Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deletes experimental GOOS=js support #2027

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -298,37 +298,6 @@ jobs:
-f ../.github/wasi_testsuite_skip.json \
-r ../.github/wasi_testsuite_adapter.py

gojs_stdlib:
name: Go (js) (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # don't fail fast as sometimes failures are arch/OS specific
matrix:
os: [ubuntu-22.04, macos-12] # GOOS=js isn't supposed to work on windows. See #1222

steps:
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Checkout wazero
uses: actions/checkout@v3

- name: Install wazero
run: go install ./cmd/wazero

- name: Build gojs test binaries
env:
GOOS: js
GOARCH: wasm
run: | # Only test os package as this is being replaced by GOOS=wasip1
mkdir ~/bin && cd ~/bin
go test -c -o os.wasm os

- name: Run tests
run: | # skip tests that use functionality not also used in GOOS=wasip1
cd $(go env GOROOT)/src/os; wazero run -mount=/:/ ~/bin/os.wasm -test.v -test.skip '^Test(Chmod|Truncate|LongPath|Chown|FileChown).*$'

go_tests:
# Due to the embedding of the GOROOT of the building env(https:/golang/go/blob/3c59639b902fada0a2e5a6a35bafd10fc9183b89/src/os/os_test.go#L112),
# we have to build and cache on each OS unlike others in this file.
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ build.bench:

.PHONY: test.examples
test.examples:
@go test $(go_test_options) ./examples/... ./imports/assemblyscript/example/... ./imports/emscripten/... ./experimental/gojs/example/... ./imports/wasi_snapshot_preview1/example/...
@go test $(go_test_options) ./examples/... ./imports/assemblyscript/example/... ./imports/emscripten/... ./imports/wasi_snapshot_preview1/example/...

.PHONY: build.examples.as
build.examples.as:
Expand Down Expand Up @@ -232,7 +232,7 @@ check:
@GOARCH=amd64 GOOS=plan9 go build ./...
# Ensure we build on gojs. See #1526.
@GOARCH=wasm GOOS=js go build ./...
# Ensure we build on gojs. See #1526.
# Ensure we build on wasip1. See #1526.
@GOARCH=wasm GOOS=wasip1 go build ./...
# Ensure we build on aix. See #1723
@GOARCH=ppc64 GOOS=aix go build ./...
Expand Down
31 changes: 1 addition & 30 deletions cmd/wazero/wazero.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/experimental/gojs"
"github.com/tetratelabs/wazero/experimental/logging"
"github.com/tetratelabs/wazero/experimental/opt"
"github.com/tetratelabs/wazero/experimental/sock"
"github.com/tetratelabs/wazero/experimental/sysfs"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/tetratelabs/wazero/internal/platform"
internalsys "github.com/tetratelabs/wazero/internal/sys"
"github.com/tetratelabs/wazero/internal/version"
"github.com/tetratelabs/wazero/sys"
Expand Down Expand Up @@ -258,7 +256,7 @@ func doRun(args []string, stdOut io.Writer, stdErr logging.Writer) int {
env = append(env, fields[0], fields[1])
}

rc, rootPath, fsConfig := validateMounts(mounts, stdErr)
rc, _, fsConfig := validateMounts(mounts, stdErr)
if rc != 0 {
return rc
}
Expand Down Expand Up @@ -347,30 +345,6 @@ func doRun(args []string, stdOut io.Writer, stdErr logging.Writer) int {
// Instantiate our binary, but using the old import names.
_, err = rt.InstantiateModule(ctx, guest, conf)
}
case modeGo:
// Fail fast on multiple mounts with the deprecated GOOS=js.
// GOOS=js will be removed in favor of GOOS=wasip1 once v1.22 is out.
if count := len(mounts); count > 1 || (count == 1 && rootPath == "") {
fmt.Fprintf(stdErr, "invalid mount: only root mounts supported in GOOS=js: %v\n"+
"Consider switching to GOOS=wasip1.\n", mounts)
return 1
}

gojs.MustInstantiate(ctx, rt, guest)

config := gojs.NewConfig(conf)

// Strip the volume of the path, for example C:\
rootDir := rootPath[len(filepath.VolumeName(rootPath)):]

// If the user mounted the entire filesystem, try to inherit the CWD.
// This is better than introducing a flag just for GOOS=js, especially
// as removing flags breaks syntax compat.
if platform.ToPosixPath(rootDir) == "/" {
config = config.WithOSWorkdir()
}

err = gojs.Run(ctx, rt, guest, config)
case modeDefault:
_, err = rt.InstantiateModule(ctx, guest, conf)
}
Expand Down Expand Up @@ -468,7 +442,6 @@ const (
modeDefault importMode = iota
modeWasi
modeWasiUnstable
modeGo
)

type importMode uint
Expand All @@ -481,8 +454,6 @@ func detectImports(imports []api.FunctionDefinition) importMode {
return modeWasi
case "wasi_unstable":
return modeWasiUnstable
case "go", "gojs":
return modeGo
}
}
return modeDefault
Expand Down
137 changes: 5 additions & 132 deletions cmd/wazero/wazero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os/exec"
"path"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -39,25 +38,16 @@ var wasmWasiFd []byte
//go:embed testdata/wasi_random_get.wasm
var wasmWasiRandomGet []byte

// wasmCatGo is compiled on demand with `GOOS=js GOARCH=wasm`
var wasmCatGo []byte

//go:embed testdata/cat/cat-tinygo.wasm
var wasmCatTinygo []byte

//go:embed testdata/exit_on_start_unstable.wasm
var wasmWasiUnstable []byte

func TestMain(m *testing.M) {
// For some reason, riscv64 fails to see directory listings.
if a := runtime.GOARCH; a == "riscv64" {
log.Println("main: skipping due to not yet supported GOARCH:", a)
os.Exit(0)
}

// Notably our scratch containers don't have go, so don't fail tests.
if err := compileGoJS(); err != nil {
log.Println("main: Skipping GOOS=js GOARCH=wasm tests due to:", err)
cmd := exec.Command("go", "version")
if _, err := cmd.CombinedOutput(); err != nil {
log.Println("main: cli test is only supported on a machine with Go installed")
os.Exit(0)
}
os.Exit(m.Run())
Expand Down Expand Up @@ -231,12 +221,7 @@ func TestRun(t *testing.T) {
bearPath := filepath.Join(bearDir, "bear.txt")
bearStat, err := os.Stat(bearPath)
require.NoError(t, err)
bearMtime := bearStat.ModTime().UnixMilli()
bearMtimeNano := bearStat.ModTime().UnixNano()
// The file is world read, but windows cannot see that and reports world
// write. Hence, we save off the current interpretation of mode for
// comparison.
bearMode := bearStat.Mode()

existingDir1 := filepath.Join(tmpDir, "existing1")
require.NoError(t, os.Mkdir(existingDir1, 0o700))
Expand Down Expand Up @@ -369,71 +354,6 @@ func TestRun(t *testing.T) {
<== errno=ESUCCESS
`,
},
{
name: "GOOS=js GOARCH=wasm",
wasm: wasmCatGo,
wazeroOpts: []string{fmt.Sprintf("--mount=%s:/", bearDir)},
wasmArgs: []string{"/bear.txt"},
expectedStdout: "pooh\n",
},
{
name: "GOOS=js GOARCH=wasm workdir",
wasm: wasmCatGo,
wazeroOpts: []string{
// --mount=X:\:/ on Windows, --mount=/:/ everywhere else
"--mount=" + filepath.VolumeName(bearDir) + string(os.PathSeparator) + ":/",
},
workdir: bearDir,
wasmArgs: []string{"bear.txt"},
expectedStdout: "pooh\n",
},
{
name: "GOOS=js GOARCH=wasm readonly",
wasm: wasmCatGo,
wazeroOpts: []string{fmt.Sprintf("--mount=%s:/:ro", bearDir)},
wasmArgs: []string{"/bear.txt"},
expectedStdout: "pooh\n",
},
{
name: "GOOS=js GOARCH=wasm hostlogging=proc",
wasm: wasmCatGo,
wazeroOpts: []string{"--hostlogging=proc", fmt.Sprintf("--mount=%s:/:ro", bearDir)},
wasmArgs: []string{"/not-bear.txt"},
expectedStderr: `==> go.runtime.wasmExit(code=1)
<==
`,
expectedExitCode: 1,
},
{
name: "GOOS=js GOARCH=wasm hostlogging=filesystem",
wasm: wasmCatGo,
wazeroOpts: []string{"--hostlogging=filesystem", fmt.Sprintf("--mount=%s:/", bearDir)},
wasmArgs: []string{"/bear.txt"},
expectedStdout: "pooh\n",
expectedStderr: fmt.Sprintf(`==> go.syscall/js.valueCall(fs.open(path=/bear.txt,flags=,perm=----------))
<== (err=<nil>,fd=4)
==> go.syscall/js.valueCall(fs.fstat(fd=4))
<== (err=<nil>,stat={isDir=false,mode=%[1]s,size=5,mtimeMs=%[2]d})
==> go.syscall/js.valueCall(fs.fstat(fd=4))
<== (err=<nil>,stat={isDir=false,mode=%[1]s,size=5,mtimeMs=%[2]d})
==> go.syscall/js.valueCall(fs.read(fd=4,offset=0,byteCount=512,fOffset=<nil>))
<== (err=<nil>,n=5)
==> go.syscall/js.valueCall(fs.read(fd=4,offset=0,byteCount=507,fOffset=<nil>))
<== (err=<nil>,n=0)
==> go.syscall/js.valueCall(fs.close(fd=4))
<== (err=<nil>,ok=true)
`, bearMode, bearMtime),
},
{
name: "GOOS=js GOARCH=wasm not root mount",
wasm: wasmCatGo,
wazeroOpts: []string{"--hostlogging=proc", fmt.Sprintf("--mount=%s:/animals:ro", bearDir)},
wasmArgs: []string{"/not-bear.txt"},
expectedStderr: fmt.Sprintf(`invalid mount: only root mounts supported in GOOS=js: [%s:/animals:ro]
Consider switching to GOOS=wasip1.
`, bearDir),
expectedExitCode: 1,
},
{
name: "cachedir existing absolute",
wazeroOpts: []string{"--cachedir=" + existingDir1},
Expand Down Expand Up @@ -530,22 +450,7 @@ Consider switching to GOOS=wasip1.
},
}

cryptoTest := test{
name: "GOOS=js GOARCH=wasm hostlogging=filesystem,random",
wasm: wasmCatGo,
wazeroOpts: []string{"--hostlogging=filesystem,random"},
wasmArgs: []string{"/bear.txt"},
expectedStderr: `==> go.runtime.getRandomData(r_len=32)
<==
==> go.runtime.getRandomData(r_len=8)
<==
==> go.syscall/js.valueCall(fs.open(path=/bear.txt,flags=,perm=----------))
<== (err=functionality not supported,fd=0)
`, // Test only shows logging happens in two scopes; it is ok to fail.
expectedExitCode: 1,
}

for _, tt := range append(tests, cryptoTest) {
for _, tt := range tests {
tc := tt

if tc.wasm == nil {
Expand Down Expand Up @@ -681,13 +586,6 @@ func Test_detectImports(t *testing.T) {
},
mode: modeWasiUnstable,
},
{
message: "GOOS=js GOARCH=wasm",
imports: []api.FunctionDefinition{
importer{internalapi.WazeroOnlyType{}, "go", "syscall/js.valueCall"},
},
mode: modeGo,
},
}

for _, tc := range tests {
Expand Down Expand Up @@ -814,32 +712,7 @@ func runMain(t *testing.T, workdir string, args []string) (int, string, string)
stderr := new(bytes.Buffer)
exitCode := doMain(stdout, stderr)

// Handle "go" -> "gojs" module rename in Go 1.21
stderrString := strings.ReplaceAll(stderr.String(), "==> gojs", "==> go")
return exitCode, stdout.String(), stderrString
}

// compileGoJS compiles "testdata/cat/cat.go" on demand as the binary generated
// is too big (1.6MB) to check into the source tree.
func compileGoJS() (err error) {
dir, err := os.Getwd()
if err != nil {
return err
}

srcDir := path.Join(dir, "testdata", "cat")
outPath := path.Join(srcDir, "cat-go.wasm")

// This doesn't add "-ldflags=-s -w", as the binary size only changes 28KB.
cmd := exec.Command("go", "build", "-o", outPath, ".")
cmd.Dir = srcDir
cmd.Env = append(os.Environ(), "GOARCH=wasm", "GOOS=js", "GOWASM=satconv,signext")
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("go build: %v\n%s", err, out)
}

wasmCatGo, err = os.ReadFile(outPath)
return
return exitCode, stdout.String(), stderr.String()
}

func exist(path string) error {
Expand Down
26 changes: 0 additions & 26 deletions experimental/gojs/README.md

This file was deleted.

1 change: 0 additions & 1 deletion experimental/gojs/example/.gitignore

This file was deleted.

18 changes: 0 additions & 18 deletions experimental/gojs/example/README.md

This file was deleted.

Loading
Loading