Skip to content

Commit

Permalink
Remove support for Wasmtime 13-and-prior CLI
Browse files Browse the repository at this point in the history
This commit removes the support in the `wasmtime` CLI for old CLI
options which were present in Wasmtime 13 and prior. This compatibility
was added in #7385 and backported to the Wasmtime 14 release #7395.
Wasmtime 14.0.0, which did not have this compatibility shim, was
released on 2023-10-20. Wasmtime 14.0.3, which restored compatibility
with this shim, was released on 2023-10-30. This means that Wasmtime
since 2023-10-30 has been warning users about differences in the old and
new CLI.

This commit will be released with Wasmtime 22 which will means that
users will have had an 8-month transition window for warnings to
migrate. The hope is that this is sufficient but it's also not too too
burdensome to carry for longer if necessary.
  • Loading branch information
alexcrichton committed May 23, 2024
1 parent f52cbbc commit 3ecec9c
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 1,357 deletions.
7 changes: 0 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,6 @@ default = [
# cost, so allow disabling this through disabling of our own `default`
# feature.
"clap/default",

# By default include compatibility with the "old" CLI from Wasmtime 13 and
# prior.
"old-cli",
]

# ========================================
Expand Down Expand Up @@ -411,9 +407,6 @@ debug-builtins = ["wasmtime/debug-builtins"]
threads = ["wasmtime-cli-flags/threads"]
gc = ["wasmtime-cli-flags/gc"]

# Enables compatibility shims with Wasmtime 13 and prior's CLI.
old-cli = []

# CLI subcommands for the `wasmtime` executable. See `wasmtime $cmd --help`
# for more information on each subcommand.
serve = ["wasi-http", "component-model", "dep:http-body-util", "dep:http"]
Expand Down
187 changes: 0 additions & 187 deletions src/bin/wasmtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ impl Wasmtime {
}

fn main() -> Result<()> {
#[cfg(feature = "old-cli")]
return old_cli::main();

#[cfg(not(feature = "old-cli"))]
return Wasmtime::parse().execute();
}

Expand All @@ -128,186 +124,3 @@ fn verify_cli() {
use clap::CommandFactory;
Wasmtime::command().debug_assert()
}

#[cfg(feature = "old-cli")]
mod old_cli {
use crate::Wasmtime;
use anyhow::{bail, Result};
use clap::error::ErrorKind;
use clap::Parser;
use wasmtime_cli::old_cli as old;

enum WhichCli {
Old,
New,
Unspecified,
}

const DEFAULT_OLD_BEHAVIOR: bool = true;

fn which_cli() -> Result<WhichCli> {
Ok(match std::env::var("WASMTIME_NEW_CLI") {
Ok(s) if s == "0" => WhichCli::Old,
Ok(s) if s == "1" => WhichCli::New,
Ok(_) => bail!("the `WASMTIME_NEW_CLI` should either be `0` or `1`"),
Err(_) => WhichCli::Unspecified,
})
}

pub fn main() -> Result<()> {
match which_cli()? {
// If the old or the new CLI is explicitly selected, then run that
// variant no questions asked.
WhichCli::New => return Wasmtime::parse().execute(),
WhichCli::Old => return try_parse_old().unwrap_or_else(|e| e.exit()).execute(),

// fall through below to run an unspecified version of the CLI
WhichCli::Unspecified => {}
}

// Here it's not specified which version of the CLI should be used, so
// both the old and the new CLI parsers are used and depending on the
// results an execution happens.
let new = Wasmtime::try_parse();
let old = try_parse_old();
match (new, old) {
// Both parsers succeeded. This means that it's likely that no
// options to configure execution, e.g. `--disable-logging`, were
// used in the old parser or the new.
//
// The result of parsing can still differ though. For example:
//
// wasmtime foo.wasm --invoke foo
//
// would previously be parsed as passing `--invoke` to Wasmtime but
// the new parser instead parses that as passing the flag to
// `foo.wasm`.
//
// In this situation use the `DEFAULT_OLD_BEHAVIOR` constant to
// dictate which wins and additionally print a warning message.
(Ok(new), Ok(old)) => {
if new == old {
return new.execute();
}
if DEFAULT_OLD_BEHAVIOR {
eprintln!(
"\
warning: this CLI invocation of Wasmtime will be parsed differently in future
Wasmtime versions -- see this online issue for more information:
https://github.com/bytecodealliance/wasmtime/issues/7384
Wasmtime will now execute with the old (<= Wasmtime 13) CLI parsing,
however this behavior can also be temporarily configured with an
environment variable:
- WASMTIME_NEW_CLI=0 to indicate old semantics are desired and silence this warning, or
- WASMTIME_NEW_CLI=1 to indicate new semantics are desired and use the latest behavior\
"
);
old.execute()
} else {
// this error message is not statically reachable due to
// `DEFAULT_OLD_BEHAVIOR=true` at this time, but when that
// changes this should be updated to have a more accurate
// set of text.
assert!(false);
eprintln!(
"\
warning: this CLI invocation of Wasmtime is parsed differently than it was
previously -- see this online issue for more information:
https://github.com/bytecodealliance/wasmtime/issues/7384
Wasmtime will now execute with the new (>= Wasmtime XXX) CLI parsing,
however this behavior can also be temporarily configured with an
environment variable:
- WASMTIME_NEW_CLI=0 to indicate old semantics are desired instead of the new, or
- WASMTIME_NEW_CLI=1 to indicate new semantics are desired and silences this warning\
"
);
new.execute()
}
}

// Here the new parser succeeded where the old one failed. This
// could indicate for example that new options are being passed on
// the CLI.
//
// In this situation assume that the new parser is what's intended
// so execute those semantics.
(Ok(new), Err(_old)) => new.execute(),

// Here the new parser failed and the old parser succeeded. This
// could indicate for example passing old CLI flags.
//
// Here assume that the old semantics are desired but emit a warning
// indicating that this will change in the future.
(Err(_new), Ok(old)) => {
eprintln!(
"\
warning: this CLI invocation of Wasmtime is going to break in the future -- for
more information see this issue online:
https://github.com/bytecodealliance/wasmtime/issues/7384
Wasmtime will now execute with the old (<= Wasmtime 13) CLI parsing,
however this behavior can also be temporarily configured with an
environment variable:
- WASMTIME_NEW_CLI=0 to indicate old semantics are desired and silence this warning, or
- WASMTIME_NEW_CLI=1 to indicate new semantics are desired and see the error\
"
);
old.execute()
}

// Both parsers failed to parse the CLI invocation.
//
// This could mean that someone manually passed an old flag
// incorrectly. This could also mean that a new flag was passed
// incorrectly. Clap also models `--help` requests as errors here so
// this could also mean that a `--help` flag was passed.
//
// The current assumption in any case is that there's a human
// interacting with the CLI at this point. They may or may not be
// aware of the old CLI vs new CLI but if we're going to print an
// error message then now's probably as good a time as any to nudge
// them towards the new CLI. Any preexisting scripts which parsed
// the old CLI should not hit this case which means that all old
// successful parses will not go through here.
//
// In any case, display the error for the new CLI, including new
// help text.
(Err(new), Err(_old)) => new.exit(),
}
}

fn try_parse_old() -> clap::error::Result<Wasmtime> {
match old::Wasmtime::try_parse() {
Ok(old) => Ok(convert(old)),
Err(e) => {
if let ErrorKind::InvalidSubcommand | ErrorKind::UnknownArgument = e.kind() {
if let Ok(run) = old::RunCommand::try_parse() {
return Ok(Wasmtime {
subcommand: None,
run: run.convert(),
});
}
}
Err(e)
}
}
}

fn convert(old: old::Wasmtime) -> Wasmtime {
let subcommand = match old {
old::Wasmtime::Compile(c) => crate::Subcommand::Compile(c.convert()),
old::Wasmtime::Run(c) => crate::Subcommand::Run(c.convert()),
};
let mut run = wasmtime_cli::commands::RunCommand::parse_from::<_, &str>(["x", "y"]);
run.module_and_args = Vec::new();
Wasmtime {
subcommand: Some(subcommand),
run,
}
}
}
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ pub mod commands;

#[cfg(feature = "run")]
pub(crate) mod common;

#[cfg(feature = "old-cli")]
pub mod old_cli;

0 comments on commit 3ecec9c

Please sign in to comment.