Skip to content

Commit

Permalink
Rename -S common to -S cli. (#8166)
Browse files Browse the repository at this point in the history
* Rename `-S common` to `-S cli`.

The "common" in `-S common` came from "wasi-common" which came from the
idea of having code in common between Wasmtime, Lucet, and others. It
doesn't have a clear meaning for end users, and has a risk of being
interpreted as "common" functionality that's generally available
everywhere.

This PR renames `-S common` to `-S cli`, and documents it as including
the WASI CLI APIs, to clarify its purpose `-S common` is still accepted,
with a warning.

* Fix formatting in RELEASES.md.

* Disable the warning about `-S common` for now.
  • Loading branch information
sunfishcode authored Mar 18, 2024
1 parent c4c5ee5 commit bcd0119
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Unreleased.

### Changed

* The `-S common` flag is renamed to `-S cli`, to better reflect that it provides
the wasi-cli APIs. `-S common` is still accepted for now, and will be deprecated
in the future.

--------------------------------------------------------------------------------

## 19.0.0
Expand Down
6 changes: 4 additions & 2 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ wasmtime_option_group! {
wasmtime_option_group! {
#[derive(PartialEq, Clone)]
pub struct WasiOptions {
/// Enable support for WASI common APIs
/// Enable support for WASI CLI APIs, including filesystems, sockets, clocks, and random.
pub cli: Option<bool>,
/// Deprecated alias for `cli`
pub common: Option<bool>,
/// Enable suport for WASI neural network API (experimental)
pub nn: Option<bool>,
Expand All @@ -265,7 +267,7 @@ wasmtime_option_group! {
pub listenfd: Option<bool>,
/// Grant access to the given TCP listen socket
pub tcplisten: Vec<String>,
/// Implement WASI with preview2 primitives (experimental).
/// Implement WASI CLI APIs with preview2 primitives (experimental).
///
/// Indicates that the implementation of WASI preview1 should be backed by
/// the preview2 implementation for components.
Expand Down
17 changes: 16 additions & 1 deletion src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,22 @@ impl RunCommand {
store: &mut Store<Host>,
module: &RunTarget,
) -> Result<()> {
if self.run.common.wasi.common != Some(false) {
let mut cli = self.run.common.wasi.cli;

// Accept -Scommon as a deprecated alias for -Scli.
if let Some(common) = self.run.common.wasi.common {
if cli.is_some() {
bail!(
"The -Scommon option should not be use with -Scli as it is a deprecated alias"
);
} else {
// In the future, we may add a warning here to tell users to use
// `-S cli` instead of `-S common`.
cli = Some(common);
}
}

if cli != Some(false) {
match linker {
CliLinker::Core(linker) => {
match (self.run.common.wasi.preview2, self.run.common.wasi.threads) {
Expand Down
26 changes: 20 additions & 6 deletions src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,30 @@ impl ServeCommand {
}

fn add_to_linker(&self, linker: &mut Linker<Host>) -> Result<()> {
// Repurpose the `-Scommon` flag of `wasmtime run` for `wasmtime serve`
let mut cli = self.run.common.wasi.cli;

// Accept -Scommon as a deprecated alias for -Scli.
if let Some(common) = self.run.common.wasi.common {
if cli.is_some() {
bail!(
"The -Scommon option should not be use with -Scli as it is a deprecated alias"
);
} else {
// In the future, we may add a warning here to tell users to use
// `-S cli` instead of `-S common`.
cli = Some(common);
}
}

// Repurpose the `-Scli` flag of `wasmtime run` for `wasmtime serve`
// to serve as a signal to enable all WASI interfaces instead of just
// those in the `proxy` world. If `-Scommon` is present then add all
// `command` APIs which includes all "common" or base WASI APIs and then
// additionally add in the required HTTP APIs.
// those in the `proxy` world. If `-Scli` is present then add all
// `command` APIs and then additionally add in the required HTTP APIs.
//
// If `-Scommon` isn't passed then use the `proxy::add_to_linker`
// If `-Scli` isn't passed then use the `proxy::add_to_linker`
// bindings which adds just those interfaces that the proxy interface
// uses.
if self.run.common.wasi.common == Some(true) {
if cli == Some(true) {
wasmtime_wasi::command::add_to_linker(linker)?;
wasmtime_wasi_http::proxy::add_only_http_to_linker(linker)?;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/old_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ impl CommonOptions {
ret.wasi.http = wasi_http;
ret.wasi.nn = wasi_nn;
ret.wasi.threads = wasi_threads;
ret.wasi.common = wasi_common;
ret.wasi.cli = wasi_common;
}
ret
}
Expand Down
2 changes: 1 addition & 1 deletion tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ mod test_programs {
&[
"-Ccache=no",
"-Wcomponent-model",
"-Scommon,http,preview2",
"-Scli,http,preview2",
HTTP_OUTBOUND_REQUEST_RESPONSE_BUILD_COMPONENT,
],
None,
Expand Down

0 comments on commit bcd0119

Please sign in to comment.