Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

wasi: Disable preview0 by default in cli (#14479)

Alex Crichton285395dbd7a7
diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs
index 4542f65703..67d3b5be7e 100644
--- a/crates/cli-flags/src/lib.rs
+++ b/crates/cli-flags/src/lib.rs
@@ -600,7 +600,7 @@ wasmtime_option_group! {
pub udp: Option<bool>,
/// Enable WASI APIs marked as: @unstable(feature = network-error-code)
pub network_error_code: Option<bool>,
- /// Allows imports from the `wasi_unstable` core wasm module.
+ /// Allows imports from the `wasi_unstable` core wasm module. Disabled by default.
pub preview0: Option<bool>,
/// Inherit all environment variables from the parent process.
///
diff --git a/src/commands/run.rs b/src/commands/run.rs
index aa0d41e8b1..501374b52c 100644
--- a/src/commands/run.rs
+++ b/src/commands/run.rs
@@ -1148,12 +1148,8 @@ impl RunCommand {
}
// If preview2 was explicitly requested, always use it.
// Otherwise use it so long as threads are disabled.
- //
- // Note that for now `p0` is currently
- // default-enabled but this may turn into
- // default-disabled in the future.
(Some(true), _) | (None, Some(false) | None) => {
- if self.run.common.wasi.preview0 != Some(false) {
+ if self.run.common.wasi.preview0 == Some(true) {
wasmtime_wasi::p0::add_to_linker_async(linker, |t| t.wasip1_ctx())?;
}
wasmtime_wasi::p1::add_to_linker_async(linker, |t| t.wasip1_ctx())?;
diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs
index bb7d4c23e2..4a0add760a 100644
--- a/tests/all/cli_tests.rs
+++ b/tests/all/cli_tests.rs
@@ -162,7 +162,14 @@ fn assert_trap_code(status: &ExitStatus) {
// Run a simple WASI hello world, snapshot0 edition.
#[test]
fn hello_wasi_snapshot0() -> Result<()> {
- let stdout = run_wasmtime(&["tests/all/cli_tests/hello_wasi_snapshot0.wat"])?;
+ let output = wasmtime(&["tests/all/cli_tests/hello_wasi_snapshot0.wat"])?.output()?;
+ assert!(!output.status.success());
+ assert!(
+ String::from_utf8_lossy(&output.stderr)
+ .contains("unknown import: `wasi_unstable::proc_exit`")
+ );
+
+ let stdout = run_wasmtime(&["-Spreview0", "tests/all/cli_tests/hello_wasi_snapshot0.wat"])?;
assert_eq!(stdout, "Hello, world!\n");
Ok(())
}
@@ -213,7 +220,8 @@ fn timeout_in_invoke() -> Result<()> {
// Exit with a valid non-zero exit code, snapshot0 edition.
#[test]
fn exit2_wasi_snapshot0() -> Result<()> {
- let output = wasmtime(&["tests/all/cli_tests/exit2_wasi_snapshot0.wat"])?.output()?;
+ let output =
+ wasmtime(&["-Spreview0", "tests/all/cli_tests/exit2_wasi_snapshot0.wat"])?.output()?;
assert_eq!(output.status.code().unwrap(), 2);
Ok(())
}
@@ -229,7 +237,11 @@ fn exit2_wasi_snapshot1() -> Result<()> {
// Exit with a valid non-zero exit code, snapshot0 edition.
#[test]
fn exit125_wasi_snapshot0() -> Result<()> {
- let output = wasmtime(&["tests/all/cli_tests/exit125_wasi_snapshot0.wat"])?.output()?;
+ let output = wasmtime(&[
+ "-Spreview0",
+ "tests/all/cli_tests/exit125_wasi_snapshot0.wat",
+ ])?
+ .output()?;
dbg!(&output);
assert_eq!(output.status.code().unwrap(), 125);
Ok(())
@@ -246,7 +258,11 @@ fn exit125_wasi_snapshot1() -> Result<()> {
// Exit with an invalid non-zero exit code, snapshot0 edition.
#[test]
fn exit126_wasi_snapshot0() -> Result<()> {
- let output = wasmtime(&["tests/all/cli_tests/exit126_wasi_snapshot0.wat"])?.output()?;
+ let output = wasmtime(&[
+ "-Spreview0",
+ "tests/all/cli_tests/exit126_wasi_snapshot0.wat",
+ ])?
+ .output()?;
assert_eq!(output.status.code().unwrap(), 1);
assert!(output.stdout.is_empty());
assert!(String::from_utf8_lossy(&output.stderr).contains("invalid exit status"));
@@ -374,7 +390,8 @@ fn run_cwasm() -> Result<()> {
#[test]
fn hello_wasi_snapshot0_from_stdin() -> Result<()> {
let stdout = run_cmd(
- wasmtime(&["-"])?.stdin(File::open("tests/all/cli_tests/hello_wasi_snapshot0.wat")?),
+ wasmtime(&["-Spreview0", "-"])?
+ .stdin(File::open("tests/all/cli_tests/hello_wasi_snapshot0.wat")?),
)?;
assert_eq!(stdout, "Hello, world!\n");
Ok(())