Skip to content

Commit 3e8dd66

Browse files
committed
Add compatibility shims for Wasmtime 13 CLI (bytecodealliance#7385)
* Add compatibility shims for Wasmtime 13 CLI This commit introduces a compatibility shim for the Wasmtime 13 CLI and prior. The goal of this commit is to address concerns raised in bytecodealliance#7336 and other locations as well. While the new CLI cannot be un-shipped at this point this PR attempts to ameliorate the situation somewhat through a few avenues: * A complete copy of the old CLI parser is now included in `wasmtime` by default. * The `WASMTIME_NEW_CLI=0` environment variable can force usage of the old CLI parser for the `run` and `compile` commands. * The `WASMTIME_NEW_CLI=1` environment variable can force usage of the new CLI parser. * Otherwise both the old and the new CLI parser are executed. Depending on the result one is selected to be executed, possibly with a warning printed. * If both CLI parsers succeed but produce the same result, then no warning is emitted and execution continues as usual. * If both CLI parsers succeed but produce different results then a warning is emitted indicating this. The warning points to bytecodealliance#7384 which has further examples of how to squash the warning. The warning also mentions the above env var to turn the warning off. In this situation the old semantics are used at this time instead of the new semantics. It's intended that eventually this will change in the future. * If the new CLI succeeds and the old CLI fails then the new semantics are executed without warning. * If the old CLI succeeds and the new CLI fails then a warning is issued and the old semantics are used. * If both the old and the new CLI fail to parse then the error message for the new CLI is emitted. Note that this doesn't add up to a perfect transition. The hope is that most of the major cases of change at the very least have something printed. My plan is to land this on `main` and then backport it to the 14.0.0 branch as a 14.0.3 release. * Wordsmith messages * Update messages * More wording updates * Fix grammar * More updates
1 parent 449a7dc commit 3e8dd66

18 files changed

Lines changed: 1428 additions & 42 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ serde_derive = { workspace = true }
4747
serde_json = { workspace = true }
4848
wasmparser = { workspace = true }
4949
wasm-encoder = { workspace = true }
50+
humantime = { workspace = true }
5051

5152
async-trait = { workspace = true }
5253
tokio = { workspace = true, optional = true, features = [ "signal", "macros" ] }
@@ -271,6 +272,7 @@ syn = "2.0.25"
271272
test-log = { version = "0.2", default-features = false, features = ["trace"] }
272273
tracing-subscriber = { version = "0.3.1", default-features = false, features = ['fmt', 'env-filter'] }
273274
url = "2.3.1"
275+
humantime = "2.0.0"
274276

275277
[features]
276278
default = [
@@ -283,6 +285,10 @@ default = [
283285
"wasi-http",
284286
"pooling-allocator",
285287
"serve",
288+
289+
# By default include compatibility with the "old" CLI from Wasmtime 13 and
290+
# prior.
291+
"old-cli",
286292
]
287293
jitdump = ["wasmtime/jitdump"]
288294
vtune = ["wasmtime/vtune"]
@@ -302,6 +308,9 @@ wmemcheck = ["wasmtime/wmemcheck"]
302308
# Enable the `wasmtime serve` command
303309
serve = ["wasi-http", "component-model"]
304310

311+
# Enables compatibility shims with Wasmtime 13 and prior's CLI.
312+
old-cli = []
313+
305314
[[test]]
306315
name = "host_segfault"
307316
harness = false

crates/cli-flags/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ file-per-thread-logger = { workspace = true }
1515
pretty_env_logger = { workspace = true }
1616
rayon = "1.5.0"
1717
wasmtime = { workspace = true }
18-
humantime = "2.0.0"
18+
humantime = { workspace = true }
1919

2020
[features]
2121
default = [

crates/cli-flags/src/lib.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn init_file_per_thread_logger(prefix: &'static str) {
3737
}
3838

3939
wasmtime_option_group! {
40+
#[derive(PartialEq, Clone)]
4041
pub struct OptimizeOptions {
4142
/// Optimization level of generated code (0-2, s; default: 0)
4243
pub opt_level: Option<wasmtime::OptLevel>,
@@ -72,6 +73,7 @@ wasmtime_option_group! {
7273
}
7374

7475
wasmtime_option_group! {
76+
#[derive(PartialEq, Clone)]
7577
pub struct CodegenOptions {
7678
/// Either `cranelift` or `winch`.
7779
///
@@ -99,6 +101,7 @@ wasmtime_option_group! {
99101
}
100102

101103
wasmtime_option_group! {
104+
#[derive(PartialEq, Clone)]
102105
pub struct DebugOptions {
103106
/// Enable generation of DWARF debug information in compiled code.
104107
pub debug_info: Option<bool>,
@@ -118,6 +121,7 @@ wasmtime_option_group! {
118121
}
119122

120123
wasmtime_option_group! {
124+
#[derive(PartialEq, Clone)]
121125
pub struct WasmOptions {
122126
/// Enable canonicalization of all NaN values.
123127
pub nan_canonicalization: Option<bool>,
@@ -208,6 +212,7 @@ wasmtime_option_group! {
208212
}
209213

210214
wasmtime_option_group! {
215+
#[derive(PartialEq, Clone)]
211216
pub struct WasiOptions {
212217
/// Enable support for WASI common APIs
213218
pub common: Option<bool>,
@@ -252,14 +257,14 @@ wasmtime_option_group! {
252257
}
253258
}
254259

255-
#[derive(Debug, Clone)]
260+
#[derive(Debug, Clone, PartialEq)]
256261
pub struct WasiNnGraph {
257262
pub format: String,
258263
pub dir: String,
259264
}
260265

261266
/// Common options for commands that translate WebAssembly modules
262-
#[derive(Parser)]
267+
#[derive(Parser, Clone)]
263268
pub struct CommonOptions {
264269
// These options groups are used to parse `-O` and such options but aren't
265270
// the raw form consumed by the CLI. Instead they're pushed into the `pub`
@@ -492,3 +497,31 @@ impl CommonOptions {
492497
Ok(())
493498
}
494499
}
500+
501+
impl PartialEq for CommonOptions {
502+
fn eq(&self, other: &CommonOptions) -> bool {
503+
let mut me = self.clone();
504+
me.configure();
505+
let mut other = other.clone();
506+
other.configure();
507+
let CommonOptions {
508+
opts_raw: _,
509+
codegen_raw: _,
510+
debug_raw: _,
511+
wasm_raw: _,
512+
wasi_raw: _,
513+
configured: _,
514+
515+
opts,
516+
codegen,
517+
debug,
518+
wasm,
519+
wasi,
520+
} = me;
521+
opts == other.opts
522+
&& codegen == other.codegen
523+
&& debug == other.debug
524+
&& wasm == other.wasm
525+
&& wasi == other.wasi
526+
}
527+
}

crates/cli-flags/src/opt.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::time::Duration;
1515
#[macro_export]
1616
macro_rules! wasmtime_option_group {
1717
(
18+
$(#[$attr:meta])*
1819
pub struct $opts:ident {
1920
$(
2021
$(#[doc = $doc:tt])*
@@ -32,6 +33,7 @@ macro_rules! wasmtime_option_group {
3233
}
3334
) => {
3435
#[derive(Default, Debug)]
36+
$(#[$attr])*
3537
pub struct $opts {
3638
$(
3739
pub $opt: $container<$payload>,
@@ -41,7 +43,7 @@ macro_rules! wasmtime_option_group {
4143
)?
4244
}
4345

44-
#[derive(Clone, Debug)]
46+
#[derive(Clone, Debug,PartialEq)]
4547
#[allow(non_camel_case_types)]
4648
enum $option {
4749
$(
@@ -106,7 +108,7 @@ macro_rules! wasmtime_option_group {
106108
}
107109

108110
/// Parser registered with clap which handles parsing the `...` in `-O ...`.
109-
#[derive(Clone, Debug)]
111+
#[derive(Clone, Debug, PartialEq)]
110112
pub struct CommaSeparated<T>(pub Vec<T>);
111113

112114
impl<T> ValueParserFactory for CommaSeparated<T>
@@ -366,10 +368,7 @@ impl WasmtimeOptionValue for wasmtime::Strategy {
366368
match String::parse(val)?.as_str() {
367369
"cranelift" => Ok(wasmtime::Strategy::Cranelift),
368370
"winch" => Ok(wasmtime::Strategy::Winch),
369-
other => bail!(
370-
"unknown optimization level `{}`, only 0,1,2,s accepted",
371-
other
372-
),
371+
other => bail!("unknown compiler `{other}` only `cranelift` and `winch` accepted",),
373372
}
374373
}
375374
}

crates/wasmtime/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ impl fmt::Debug for Config {
18261826
///
18271827
/// This is used as an argument to the [`Config::strategy`] method.
18281828
#[non_exhaustive]
1829-
#[derive(Clone, Debug, Copy)]
1829+
#[derive(PartialEq, Eq, Clone, Debug, Copy)]
18301830
pub enum Strategy {
18311831
/// An indicator that the compilation strategy should be automatically
18321832
/// selected.

0 commit comments

Comments
 (0)