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

proposal: cmd/go: add GOINVOKE option #62736

Closed
Jorropo opened this issue Sep 19, 2023 · 2 comments
Closed

proposal: cmd/go: add GOINVOKE option #62736

Jorropo opened this issue Sep 19, 2023 · 2 comments
Milestone

Comments

@Jorropo
Copy link
Member

Jorropo commented Sep 19, 2023

Usecase

I want to add wasip1 tests to my codebase however doing so is non trivial because the dumb GOOS=wasip1 GOARCH=wasm yields:

fork/exec /tmp/go-build85289293/b854/internal.test: exec format error

Instead I need to manually run go test -c -o tests and do wasmtime tests (or some other wasip1 runtime) on packages that go list tell me I should test which is a non trivial line of bash to write.

Proposal

Add a new GOINVOKE option to go env, this will specify a binary that will be used to invoke targets, the target will be the first argument passed to this binary. If empty this does nothing. Defaults to nothing.
This would affect go test, go run and go generate.

How it would work

That means I should be able to do:

GOOS=wasip1 GOARCH=wasm GOINVOKE=wastime go test ./...

And go would invoke wasmtime with /tmp/go-build85289293/b854/internal.test in argv[1].

This would also allows to do:

GOARCH=arm64 GOINVOKE=a-userland-emulator-that-supports-the-syscalls-required-by-the-runtime go test ./...

on an amd64 system and it would compile my tests for arm64 and use userland qemu (if this works one day) to emulate arm64 on the amd64 system.

@gopherbot gopherbot added this to the Proposal milestone Sep 19, 2023
@bcmills
Copy link
Member

bcmills commented Sep 19, 2023

There is already a mechanism for this: see the description of the -exec flag at https://pkg.go.dev/cmd/go#hdr-Compile_and_run_Go_program.

Simpler still is to ensure that $GOROOT/misc/wasm/go_wasip1_wasm_exec can be resolved from your $PATH, in which case it will be used automatically.

@bcmills bcmills added the GoCommand cmd/go label Sep 19, 2023
@Jorropo
Copy link
Member Author

Jorropo commented Sep 19, 2023

I overlooked go test -exec thx, there can be value in supplying a default config through ENV (no need to specify it everywhere) but I don't think this is worth spending time on.


Simpler still is to ensure that $GOROOT/misc/wasm/go_wasip1_wasm_exec can be resolved from your $PATH, in which case it will be used automatically.

The installation docs are quite incomplete on that front, I had to tell numerous peoples that they should also add $GOBIN or most likely $GOPATH/bin to their PATH already.
Now I need to know $GOROOT/misc/wasm/go_wasip1_wasm_exec too (which cool that this works, but that feels like important info to tell peoples).

Is this you will get it wrong once and learn about it when you need approach intentional or just a hole that should be patched ?

Alternatively I do not have $GOROOT/pkg/tool/linux_amd64/ in my path yet the toolchain works correctly, could it do the same thing for $GOROOT/misc/wasm/go_wasip1_wasm_exec ?

@Jorropo Jorropo closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants