Skip to content

Commit 23fc0c1

Browse files
authored
Make TOML config keys kebab-case, and add docs (bytecodealliance#10132)
* Update cli book docs for toml option * Make TOML keys use kebab-case in order to match cli names
1 parent ebd9824 commit 23fc0c1

File tree

3 files changed

+67
-14
lines changed

3 files changed

+67
-14
lines changed

crates/cli-flags/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn init_file_per_thread_logger(prefix: &'static str) {
4343

4444
wasmtime_option_group! {
4545
#[derive(PartialEq, Clone, Deserialize)]
46-
#[serde(deny_unknown_fields)]
46+
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
4747
pub struct OptimizeOptions {
4848
/// Optimization level of generated code (0-2, s; default: 2)
4949
#[serde(default)]
@@ -202,7 +202,7 @@ wasmtime_option_group! {
202202

203203
wasmtime_option_group! {
204204
#[derive(PartialEq, Clone, Deserialize)]
205-
#[serde(deny_unknown_fields)]
205+
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
206206
pub struct CodegenOptions {
207207
/// Either `cranelift` or `winch`.
208208
///
@@ -251,7 +251,7 @@ wasmtime_option_group! {
251251

252252
wasmtime_option_group! {
253253
#[derive(PartialEq, Clone, Deserialize)]
254-
#[serde(deny_unknown_fields)]
254+
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
255255
pub struct DebugOptions {
256256
/// Enable generation of DWARF debug information in compiled code.
257257
pub debug_info: Option<bool>,
@@ -272,7 +272,7 @@ wasmtime_option_group! {
272272

273273
wasmtime_option_group! {
274274
#[derive(PartialEq, Clone, Deserialize)]
275-
#[serde(deny_unknown_fields)]
275+
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
276276
pub struct WasmOptions {
277277
/// Enable canonicalization of all NaN values.
278278
pub nan_canonicalization: Option<bool>,
@@ -387,7 +387,7 @@ wasmtime_option_group! {
387387

388388
wasmtime_option_group! {
389389
#[derive(PartialEq, Clone, Deserialize)]
390-
#[serde(deny_unknown_fields)]
390+
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
391391
pub struct WasiOptions {
392392
/// Enable support for WASI CLI APIs, including filesystems, sockets, clocks, and random.
393393
pub cli: Option<bool>,
@@ -1047,7 +1047,7 @@ mod tests {
10471047
let toml = format!(
10481048
r#"
10491049
[optimize]
1050-
opt_level = {opt_value}
1050+
opt-level = {opt_value}
10511051
"#,
10521052
);
10531053
let parsed_opt_level = toml::from_str::<CommonOptions>(&toml)
@@ -1071,7 +1071,7 @@ mod tests {
10711071
let toml = format!(
10721072
r#"
10731073
[optimize]
1074-
regalloc_algorithm = {regalloc_value}
1074+
regalloc-algorithm = {regalloc_value}
10751075
"#,
10761076
);
10771077
let parsed_regalloc_algorithm = toml::from_str::<CommonOptions>(&toml)

docs/cli-options.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,56 @@ display what Cranelift settings are inferred for the host:
126126
```sh
127127
$ wasmtime settings
128128
```
129+
130+
# Additional options
131+
Many of the above subcommands also take additional options. For example,
132+
- run
133+
- serve
134+
- compile
135+
- explore
136+
- wast
137+
138+
are all subcommands which can take additional CLI options of the format
139+
140+
```sh
141+
Options:
142+
-O, --optimize <KEY[=VAL[,..]]>
143+
Optimization and tuning related options for wasm performance, `-O help` to see all
144+
145+
-C, --codegen <KEY[=VAL[,..]]>
146+
Codegen-related configuration options, `-C help` to see all
147+
148+
-D, --debug <KEY[=VAL[,..]]>
149+
Debug-related configuration options, `-D help` to see all
150+
151+
-W, --wasm <KEY[=VAL[,..]]>
152+
Options for configuring semantic execution of WebAssembly, `-W help` to see all
153+
154+
-S, --wasi <KEY[=VAL[,..]]>
155+
Options for configuring WASI and its proposals, `-S help` to see all
156+
```
157+
158+
For example, adding `--optimize opt-level=0` to a `wasmtime compile` subcommand
159+
will turn off most optimizations for the generated code.
160+
161+
## CLI options using TOML file
162+
Most key-value options that can be provided using the `--optimize`, `--codegen`,
163+
`--debug`, `--wasm`, and `--wasi` flags can also be provided using a TOML
164+
file using the `--config <FILE>` cli flag, by putting the key-value inside a TOML
165+
table with the same name.
166+
167+
For example, with a TOML file like this
168+
```toml
169+
[optimize]
170+
opt-level = 0
171+
```
172+
the command
173+
```sh
174+
$ wasmtime compile --config config.toml
175+
```
176+
would be the same as
177+
```sh
178+
$ wasmtime compile --optimize opt-level=0
179+
```
180+
assuming the TOML file is called `config.toml`. Of course you can put as many
181+
key-value pairs as you want in the TOML file.

tests/all/cli_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,18 +2161,18 @@ fn config_cli_flag() -> Result<()> {
21612161
cfg.write_all(
21622162
br#"
21632163
[optimize]
2164-
opt_level = 2
2165-
regalloc_algorithm = "single-pass"
2166-
signals_based_traps = false
2164+
opt-level = 2
2165+
regalloc-algorithm = "single-pass"
2166+
signals-based-traps = false
21672167
21682168
[codegen]
21692169
collector = "null"
21702170
21712171
[debug]
2172-
debug_info = true
2172+
debug-info = true
21732173
21742174
[wasm]
2175-
max_wasm_stack = 65536
2175+
max-wasm-stack = 65536
21762176
21772177
[wasi]
21782178
cli = true
@@ -2213,7 +2213,7 @@ fn config_cli_flag() -> Result<()> {
22132213
cfg.write_all(
22142214
br#"
22152215
[optimize]
2216-
this_key_does_not_exist = true
2216+
this-key-does-not-exist = true
22172217
"#,
22182218
)?;
22192219
let output = run_wasmtime(&[
@@ -2227,7 +2227,7 @@ fn config_cli_flag() -> Result<()> {
22272227
.as_ref()
22282228
.unwrap_err()
22292229
.to_string()
2230-
.contains("unknown field `this_key_does_not_exist`"),
2230+
.contains("unknown field `this-key-does-not-exist`"),
22312231
"'{output:?}' did not contain expected error message"
22322232
);
22332233

0 commit comments

Comments
 (0)