Skip to content

Commit

Permalink
new: WATM v1 (#6)
Browse files Browse the repository at this point in the history
* new: WATM v1

v1: based on v0, we renamed and redesigned tons of interfaces, introduced new working modes, and fixed potential bugs.

Signed-off-by: Gaukas Wang <i@gaukas.wang>

* build: move and update replaced package

Move tinygo/v?/examples/replace/x/sys` to `tinygo/replaced/golang.org/x/sys@v0.19.0`

Signed-off-by: Gaukas Wang <i@gaukas.wang>

---------

Signed-off-by: Gaukas Wang <i@gaukas.wang>
  • Loading branch information
gaukas committed Apr 8, 2024
1 parent a4098d9 commit 5c9b8ee
Show file tree
Hide file tree
Showing 568 changed files with 7,027 additions and 175 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ jobs:
path: ${{ matrix.watm.name }}.v0.tinygo.wasm
retention-days: 1

watm_tinygo_v1_artifacts:
name: "watm: build ${{ matrix.watm.name }}.v1.tinygo.wasm with TinyGo"
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
watm: [
{ name: "plain", scheduler: "none", gc: "conservative", tags: "purego" },
{ name: "reverse", scheduler: "none", gc: "conservative", tags: "purego" },
{ name: "utls", scheduler: "asyncify", gc: "conservative", tags: "purego" }
]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22.x"
- uses: acifani/setup-tinygo@v2
with:
tinygo-version: '0.31.1'
- name: Build WATM Artifacts
run: tinygo build -o ../../../${{ matrix.watm.name }}.v1.tinygo.wasm
-target=wasi -no-debug -scheduler=${{ matrix.watm.scheduler }}
-gc=${{ matrix.watm.gc }} -tags=${{ matrix.watm.tags }}
./${{ matrix.watm.name }}/
working-directory: ./tinygo/v1/examples/
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.watm.name }}.v1.tinygo
path: ${{ matrix.watm.name }}.v1.tinygo.wasm
retention-days: 1

release:
needs:
- watm_tinygo_v0_artifacts
Expand Down
39 changes: 31 additions & 8 deletions .github/workflows/watm.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: "watm"

on:
push:
branches: [ "master" ]
paths:
- '**'
- '!tinygo/snippets/**' # ignore changes to snippets since they are not impacting the module
- '!**.md' # ignore changes to markdown files since they are not part of the code
- '!**/LICENSE*'
# push:
# branches: [ "master" ]
# paths:
# - '**'
# - '!tinygo/snippets/**' # ignore changes to snippets since they are not impacting the module
# - '!**.md' # ignore changes to markdown files since they are not part of the code
# - '!**/LICENSE*'
pull_request:
branches: [ "master" ]
paths:
Expand Down Expand Up @@ -58,4 +58,27 @@ jobs:
run: |
mkdir -p tmp
tinygo build -o tmp/${{ matrix.examples }}.wasm -target=wasi -tags=purego ./${{ matrix.examples }}/
working-directory: ./tinygo/v0/examples/
working-directory: ./tinygo/v0/examples/

watm_build_tinygo_v1_examples:
name: "build ${{ matrix.examples }}.v1.tinygo.wasm w/ tinygo ${{ matrix.tinygo }} (go${{ matrix.go }})"
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
tinygo: [ "0.31.1" ] # latest tinygo version ONLY (1)
go: [ "1.21.x", "1.22.x" ] # latest 2 stable versions of Go. TODO: bump to 1.22.x once tinygo support added.
examples: [ "plain", "reverse", "utls" ] # Add examples here per ones under tinygo/v0/examples
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- uses: acifani/setup-tinygo@v2
with:
tinygo-version: ${{ matrix.tinygo }}
- name: Build
run: |
mkdir -p tmp
tinygo build -o tmp/${{ matrix.examples }}.wasm -target=wasi -tags=purego ./${{ matrix.examples }}/
working-directory: ./tinygo/v1/examples/
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/refraction-networking/watm

go 1.20
go 1.21
10 changes: 10 additions & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Treat all files in this repo as binary, with no git magic updating
# line endings. Windows users contributing to Go will need to use a
# modern version of git and editors capable of LF line endings.
#
# We'll prevent accidental CRLF line endings from entering the repo
# via the git-review gofmt checks.
#
# See golang.org/issue/9281

* -text
2 changes: 2 additions & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Add no patterns to .gitignore except for files generated by the build.
last-change
26 changes: 26 additions & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributing to Go

Go is an open source project.

It is the work of hundreds of contributors. We appreciate your help!

## Filing issues

When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions:

1. What version of Go are you using (`go version`)?
2. What operating system and processor architecture are you using?
3. What did you do?
4. What did you expect to see?
5. What did you see instead?

General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
The gophers there will answer or ask you to file an issue if you've tripped over a bug.

## Contributing code

Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
before sending patches.

Unless otherwise noted, the Go source files are distributed under
the BSD-style license found in the LICENSE file.
27 changes: 27 additions & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 changes: 22 additions & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/PATENTS
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Additional IP Rights Grant (Patents)

"This implementation" means the copyrightable works distributed by
Google as part of the Go project.

Google hereby grants to You a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as stated in this section)
patent license to make, have made, use, offer to sell, sell, import,
transfer and otherwise run, modify and propagate the contents of this
implementation of Go, where such license applies only to those patent
claims, both currently owned or controlled by Google and acquired in
the future, licensable by Google that are necessarily infringed by this
implementation of Go. This grant does not include claims that would be
infringed only as a consequence of further modification of this
implementation. If you or your agent or exclusive licensee institute or
order or agree to the institution of patent litigation against any
entity (including a cross-claim or counterclaim in a lawsuit) alleging
that this implementation of Go or any code incorporated within this
implementation of Go constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any patent
rights granted to you under this License for this implementation of Go
shall terminate as of the date such litigation is filed.
20 changes: 20 additions & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# sys

[![Go Reference](https://pkg.go.dev/badge/golang.org/x/sys.svg)](https://pkg.go.dev/golang.org/x/sys)

This repository holds supplemental Go packages for low-level interactions with
the operating system.

## Download/Install

The easiest way to install is to run `go get -u golang.org/x/sys`. You can
also manually git clone the repository to `$GOPATH/src/golang.org/x/sys`.

## Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to
this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the sys repository is located at
https://github.com/golang/go/issues. Prefix your issue with "x/sys:" in the
subject line, so it is easy to find.
1 change: 1 addition & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/codereview.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
issuerepo: golang/go
File renamed without changes.
20 changes: 20 additions & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/cpu/runtime_auxv_go121.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package cpu

import (
_ "unsafe" // for linkname
)

// manually disabling the following until TinyGo implements runtime.getAuxv

// //go:linkname runtime_getAuxv runtime.getAuxv
// func runtime_getAuxv() []uintptr

// func init() {
// getAuxvFn = runtime_getAuxv
// }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21 && !(wasi || wasm || wasip1 || wasip2)
//go:build go1.21

package cpu

Expand Down
102 changes: 102 additions & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/execabs/execabs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package execabs is a drop-in replacement for os/exec
// that requires PATH lookups to find absolute paths.
// That is, execabs.Command("cmd") runs the same PATH lookup
// as exec.Command("cmd"), but if the result is a path
// which is relative, the Run and Start methods will report
// an error instead of running the executable.
//
// See https://blog.golang.org/path-security for more information
// about when it may be necessary or appropriate to use this package.
package execabs

import (
"context"
"fmt"
"os/exec"
"path/filepath"
"reflect"
"unsafe"
)

// ErrNotFound is the error resulting if a path search failed to find an executable file.
// It is an alias for exec.ErrNotFound.
var ErrNotFound = exec.ErrNotFound

// Cmd represents an external command being prepared or run.
// It is an alias for exec.Cmd.
type Cmd = exec.Cmd

// Error is returned by LookPath when it fails to classify a file as an executable.
// It is an alias for exec.Error.
type Error = exec.Error

// An ExitError reports an unsuccessful exit by a command.
// It is an alias for exec.ExitError.
type ExitError = exec.ExitError

func relError(file, path string) error {
return fmt.Errorf("%s resolves to executable in current directory (.%c%s)", file, filepath.Separator, path)
}

// LookPath searches for an executable named file in the directories
// named by the PATH environment variable. If file contains a slash,
// it is tried directly and the PATH is not consulted. The result will be
// an absolute path.
//
// LookPath differs from exec.LookPath in its handling of PATH lookups,
// which are used for file names without slashes. If exec.LookPath's
// PATH lookup would have returned an executable from the current directory,
// LookPath instead returns an error.
func LookPath(file string) (string, error) {
path, err := exec.LookPath(file)
if err != nil && !isGo119ErrDot(err) {
return "", err
}
if filepath.Base(file) == file && !filepath.IsAbs(path) {
return "", relError(file, path)
}
return path, nil
}

func fixCmd(name string, cmd *exec.Cmd) {
if filepath.Base(name) == name && !filepath.IsAbs(cmd.Path) && !isGo119ErrFieldSet(cmd) {
// exec.Command was called with a bare binary name and
// exec.LookPath returned a path which is not absolute.
// Set cmd.lookPathErr and clear cmd.Path so that it
// cannot be run.
lookPathErr := (*error)(unsafe.Pointer(reflect.ValueOf(cmd).Elem().FieldByName("lookPathErr").Addr().Pointer()))
if *lookPathErr == nil {
*lookPathErr = relError(name, cmd.Path)
}
cmd.Path = ""
}
}

// CommandContext is like Command but includes a context.
//
// The provided context is used to kill the process (by calling os.Process.Kill)
// if the context becomes done before the command completes on its own.
func CommandContext(ctx context.Context, name string, arg ...string) *exec.Cmd {
cmd := exec.CommandContext(ctx, name, arg...)
fixCmd(name, cmd)
return cmd

}

// Command returns the Cmd struct to execute the named program with the given arguments.
// See exec.Command for most details.
//
// Command differs from exec.Command in its handling of PATH lookups,
// which are used when the program name contains no slashes.
// If exec.Command would have returned an exec.Cmd configured to run an
// executable from the current directory, Command instead
// returns an exec.Cmd that will return an error from Start or Run.
func Command(name string, arg ...string) *exec.Cmd {
cmd := exec.Command(name, arg...)
fixCmd(name, cmd)
return cmd
}
17 changes: 17 additions & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/execabs/execabs_go118.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !go1.19

package execabs

import "os/exec"

func isGo119ErrDot(err error) bool {
return false
}

func isGo119ErrFieldSet(cmd *exec.Cmd) bool {
return false
}
20 changes: 20 additions & 0 deletions tinygo/replaced/golang.org/x/sys@v0.19.0/execabs/execabs_go119.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.19

package execabs

import (
"errors"
"os/exec"
)

func isGo119ErrDot(err error) bool {
return errors.Is(err, exec.ErrDot)
}

func isGo119ErrFieldSet(cmd *exec.Cmd) bool {
return cmd.Err != nil
}

0 comments on commit 5c9b8ee

Please sign in to comment.