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

wasm: pass command line arguments and environment variables via go.importObject #68841

Open
Zxilly opened this issue Aug 12, 2024 · 3 comments
Open
Labels
arch-wasm WebAssembly issues NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Zxilly
Copy link
Member

Zxilly commented Aug 12, 2024

Proposal Details

This proposal suggests a modification to the Go compiler's WebAssembly (Wasm) target to change the mechanism used for passing command-line arguments and environment variables.

In the current implementation of the Go compiler targeting Wasm, command-line arguments and environment variables are written directly into the linear memory of the WebAssembly module, with the combined size of these parameters being limited to 8192 bytes.

The size limitation of 8192 bytes for the combined environment variables and command-line arguments is restrictive, particularly when considering the capabilities of mainstream operating systems:

  • Linux: MAX_ARG_STRLEN * 32, typically 128KB
  • Windows: Has a maximum environment block size of 32,767 characters.
  • macOS: I don't have a macOS device, but in GitHub Actions, the macOS runner can apparently also store environment variables that are longer than 8192

This restriction has caused some real trouble. When running unit tests on GitHub Actions, for example, the length of environment variables included by default in the runner has exceeded this limit.

https://github.com/evanw/esbuild/blob/9c13ae1f06dfa909eb4a53882e3b7e4216a503fe/Makefile#L55-L62

https://github.com/Zxilly/go-size-analyzer/blob/c4e4db97cc0383797c8b4960c55db529df451601/scripts/tests.py#L47-L74

agnivade/wasmbrowsertest#30

#49011

I propose to instead use go.importObject for passing these parameters. Glue js should perform dynamic allocation of environment variables and command line arguments as the wasm application tries to read them, and then provide the values to the wasm application using logic similar to syscall/js.copyBytesToGo.

@gopherbot gopherbot added this to the Proposal milestone Aug 12, 2024
@gabyhelp
Copy link

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@ianlancetaylor
Copy link
Member

This seems like something that can be fixed internally without changing anything user-visible, so taking it out of the proposal process.

@ianlancetaylor ianlancetaylor changed the title proposal: wasm: passing command line arguments and environment variables via go.importObject wasm: pass command line arguments and environment variables via go.importObject Aug 14, 2024
@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed Proposal labels Aug 14, 2024
@ianlancetaylor ianlancetaylor modified the milestones: Proposal, Backlog Aug 14, 2024
@ianlancetaylor ianlancetaylor added the arch-wasm WebAssembly issues label Aug 14, 2024
@ianlancetaylor
Copy link
Member

CC @golang/wasm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly issues NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants