cmd/wasirun: add --env-inherit flag from wazero#78
cmd/wasirun: add --env-inherit flag from wazero#78achille-roussel merged 2 commits intodispatchrun:mainfrom
Conversation
This enables GOOS=wasip1 GOARCH=wasm go test -exec 'wasirun --env-inherit --dir /' <package> The go test command sets the working directory AND $PWD to the package source directory when running. This passes the PWD variable through at runtime, and not when go test is run.
achille-roussel
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
|
It took a while to track down why go test -exec couldn't find source-relative test data. Turns out os.Getwd needs $PWD set to work on wasip1. |
|
Ah yes, the dependency on PWD is something we should probably have documented properly somewhere when Go 1.21 comes out, thanks for the feedback! |
|
Wonder if it makes sense to have I considered augmenting the |
|
That would probably be a useful addition, I would advise doing this only if the PWD environment variable does not already exists, then we set it to the current working directory. Which environment were you running in that did not set PWD? |
|
We had a Make target that set wasm-test:
$(WASM_ENV) gotip test -v -exec "wasirun --non-blocking-stdio --dir / --env PWD=$$PWD" $(TEST_PACKAGES)With wasm-test:
$(WASM_ENV) gotip test -v -exec "wasirun --non-blocking-stdio --dir / --env-inherit" $(TEST_PACKAGES)I think allowing wasm-test:
$(WASM_ENV) gotip test -v -exec "wasirun --non-blocking-stdio --dir / --env PWD" $(TEST_PACKAGES) |
This enables
GOOS=wasip1 GOARCH=wasm go test -exec 'wasirun --env-inherit --dir /' <package>The
go testcommand sets the working directory AND$PWDto the package source directory when running. This passesPWDthrough at the timewasirunis executed, rather than the value ofPWDat the timego testis executed (typically the module root).