Skip to content

Support environment variables for most CLI arguments - #14217

Merged
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
alexcrichton:env-var-options
Aug 26, 2026
Merged

Support environment variables for most CLI arguments #14217
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
alexcrichton:env-var-options

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

This commit adds support to use environment variables in addition to CLI
flags when configuring wasmtime execution. This is applied to all
"option groups" of Wasmtime, such as -W, -S, -O, etc. Options can
be specified as a group:

WASMTIME_OPTIMIZE=opt-level=1,...

or individually:

WASMTIME_OPTIMIZE_OPT_LEVEL=1

CLI configuration overrides environment variables, and environment
variables override file-based configuration. Errors are reported as
usual if any environment variable fails to parse.

Note: I wasn't super happy with the state of cli_tests.rs so I did some initial refactoring in the first commit in this PR. That's not specifically related to this change and isn't intended to change anything, but is aspirationally a cleanup of those tests.

* Add a generic `run_cmd` helper to avoid ad-hoc spawning/printing of
  errors
* Consolidate helpers around `Command`.
* Remove most usage of `build_wasm` as it's not necessary.
This commit adds support to use environment variables in addition to CLI
flags when configuring `wasmtime` execution. This is applied to all
"option groups" of Wasmtime, such as `-W`, `-S`, `-O`, etc. Options can
be specified as a group:

    WASMTIME_OPTIMIZE=opt-level=1,...

or individually:

    WASMTIME_OPTIMIZE_OPT_LEVEL=1

CLI configuration overrides environment variables, and environment
variables override file-based configuration. Errors are reported as
usual if any environment variable fails to parse.
@alexcrichton
alexcrichton requested review from a team as code owners August 26, 2026 21:37
@alexcrichton
alexcrichton requested review from fitzgen and pchickey and removed request for a team August 26, 2026 21:37

@pchickey pchickey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for cleaning up the cli tests stuff as well

@alexcrichton
alexcrichton enabled auto-merge August 26, 2026 21:47
@alexcrichton
alexcrichton added this pull request to the merge queue Aug 26, 2026
Merged via the queue into bytecodealliance:main with commit 83d1cf7 Aug 26, 2026
54 checks passed
@alexcrichton
alexcrichton deleted the env-var-options branch August 26, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants