Skip to content

Commit

Permalink
Merge pull request #2948 from vdice/ref/wasm32-wasip1-updates
Browse files Browse the repository at this point in the history
ref(*): replace wasm32-wasi with wasm32-wasip1
  • Loading branch information
vdice authored Dec 6, 2024
2 parents cda78d0 + 9ece312 commit abba523
Show file tree
Hide file tree
Showing 31 changed files with 534 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
rustup update stable && rustup default stable && rustup component add clippy rustfmt

# Installs wasm32 compiler targets
rustup target add wasm32-wasi wasm32-unknown-unknown
rustup target add wasm32-wasip1 wasm32-unknown-unknown
2 changes: 1 addition & 1 deletion .github/actions/spin-ci-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ runs:
rustup default ${{ inputs.rust-version }}
- name: "Install Wasm Rust target"
run: rustup target add wasm32-wasi wasm32-wasip1 wasm32-unknown-unknown
run: rustup target add wasm32-wasip1 wasm32-unknown-unknown
if: ${{ inputs.rust-wasm == 'true' }}
shell: bash

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ jobs:

# Install all the toolchain dependencies
- name: Install Rust wasm target
run: rustup target add wasm32-wasi wasm32-wasip1 wasm32-unknown-unknown
run: rustup target add wasm32-wasip1 wasm32-unknown-unknown
- uses: goto-bus-stop/setup-zig@v2
- uses: actions/setup-go@v4
with:
Expand Down Expand Up @@ -281,7 +281,7 @@ jobs:
run: rustup target add --toolchain ${{ env.RUST_VERSION }} ${{ matrix.config.target }}

- name: "Install Wasm Rust target"
run: rustup target add wasm32-wasi wasm32-wasip1 wasm32-unknown-unknown --toolchain ${{ env.RUST_VERSION }}
run: rustup target add wasm32-wasip1 wasm32-unknown-unknown --toolchain ${{ env.RUST_VERSION }}

- name: setup for cross-compiled linux aarch64 build
if: matrix.config.target == 'aarch64-unknown-linux-gnu'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
run: rustup target add --toolchain ${{ env.RUST_VERSION }} ${{ matrix.config.target }}

- name: "Install Wasm Rust target"
run: rustup target add wasm32-wasi wasm32-wasip1 wasm32-unknown-unknown --toolchain ${{ env.RUST_VERSION }}
run: rustup target add wasm32-wasip1 wasm32-unknown-unknown --toolchain ${{ env.RUST_VERSION }}

- name: setup for cross-compiled linux aarch64 build
if: matrix.config.target == 'aarch64-unknown-linux-gnu'
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ and then follow the
language guides, and the [guide on writing Spin applications](https://developer.fermyon.com/spin/configuration/).

## Usage
Below is an example of using the `spin` CLI to create a new Spin application. To run the example you will need to install the `wasm32-wasi` target for Rust.
Below is an example of using the `spin` CLI to create a new Spin application. To run the example you will need to install the `wasm32-wasip1` target for Rust.

```bash
$ rustup target add wasm32-wasi
$ rustup target add wasm32-wasip1
```

First, run the `spin new` command to create a Spin application from a template.
Expand All @@ -55,7 +55,7 @@ Running the `spin new` command created a `hello-rust` directory with all the nec
```bash
# Compile to Wasm by executing the `build` command.
$ spin build
Executing the build command for component hello-rust: cargo build --target wasm32-wasi --release
Executing the build command for component hello-rust: cargo build --target wasm32-wasip1 --release
Finished release [optimized] target(s) in 0.03s
Successfully ran the build command for the Spin components.

Expand Down
10 changes: 5 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ fn main() {

println!(
r#"
error: the `wasm32-wasi` target is not installed
= help: consider downloading the target with `rustup{} target add wasm32-wasi`"#,
error: the `wasm32-wasip1` target is not installed
= help: consider downloading the target with `rustup{} target add wasm32-wasip1`"#,
toolchain_override
);
process::exit(1);
Expand All @@ -75,7 +75,7 @@ error: the `wasm32-wasi` target is not installed
fn build_wasm_test_program(name: &'static str, root: &'static str) {
build_target_dep(root, Path::new("target/test-programs").join(name))
.release()
.target("wasm32-wasi")
.target("wasm32-wasip1")
.build();
println!("cargo:rerun-if-changed={root}/Cargo.toml");
println!("cargo:rerun-if-changed={root}/Cargo.lock");
Expand All @@ -85,7 +85,7 @@ fn build_wasm_test_program(name: &'static str, root: &'static str) {
fn has_wasm32_wasi_target() -> bool {
// Using rustc here for systems that don't have rustup
let output = run(
vec!["rustc", "--print=target-libdir", "--target=wasm32-wasi"],
vec!["rustc", "--print=target-libdir", "--target=wasm32-wasip1"],
None,
None,
);
Expand All @@ -110,7 +110,7 @@ fn cargo_build(dir: &str) {
"cargo",
"build",
"--target",
"wasm32-wasi",
"wasm32-wasip1",
"--release",
// Ensure that even if `CARGO_TARGET_DIR` is set
// that we're still building into the right dir.
Expand Down
2 changes: 1 addition & 1 deletion crates/componentize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ the original module exported.
This crate requires a [Rust](https://rustup.rs/) installation v1.68 or later and a couple of Wasm targets:

```shell
rustup target add wasm32-wasi
rustup target add wasm32-wasip1
rustup target add wasm32-unknown-unknown
```

Expand Down
8 changes: 4 additions & 4 deletions crates/componentize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ mod tests {
run_spin(
&fs::read(concat!(
env!("OUT_DIR"),
"/wasm32-wasi/release/rust_case_02.wasm"
"/wasm32-wasip1/release/rust_case_02.wasm"
))
.await?,
)
Expand All @@ -426,7 +426,7 @@ mod tests {
run_spin(
&fs::read(concat!(
env!("OUT_DIR"),
"/wasm32-wasi/release/rust_case_08.wasm"
"/wasm32-wasip1/release/rust_case_08.wasm"
))
.await?,
)
Expand Down Expand Up @@ -458,7 +458,7 @@ mod tests {
run_command(
&fs::read(concat!(
env!("OUT_DIR"),
"/wasm32-wasi/release/rust-command.wasm"
"/wasm32-wasip1/release/rust-command.wasm"
))
.await?,
)
Expand All @@ -471,7 +471,7 @@ mod tests {
cmd.arg("build")
.current_dir(format!("tests/{name}"))
.arg("--release")
.arg("--target=wasm32-wasi")
.arg("--target=wasm32-wasip1")
.env("CARGO_TARGET_DIR", out_dir);

let status = cmd.status().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions crates/componentize/tests/rust-case-0.2/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spin-abi-conformance.wasm: target/wasm32-wasi/release/spin-rust.wasm
spin-abi-conformance.wasm: target/wasm32-wasip1/release/spin-rust.wasm
cp $< $@

target/wasm32-wasi/release/spin-rust.wasm: src/main.rs Cargo.toml
cargo build --target wasm32-wasi --release
target/wasm32-wasip1/release/spin-rust.wasm: src/main.rs Cargo.toml
cargo build --target wasm32-wasip1 --release
2 changes: 1 addition & 1 deletion crates/core/tests/core-wasi-test/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build]
target = "wasm32-wasi"
target = "wasm32-wasip1"
26 changes: 13 additions & 13 deletions crates/doctor/src/rustlang/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ async fn diagnose_rust_wasi_target() -> Result<Vec<TargetDiagnosis>> {
// - if rustup is not present, check if cargo is present
// - if not, return RustNotInstalled
// - if so, warn but return empty list (Rust is installed but not via rustup, so we can't perform a diagnosis - bit of an edge case this one, and the user probably knows what they're doing...?)
// - if rustup is present but the list does not contain wasm32-wasi, return WasmTargetNotInstalled
// - if the list does contain wasm32-wasi, return an empty list
// - if rustup is present but the list does not contain wasm32-wasip1, return WasmTargetNotInstalled
// - if the list does contain wasm32-wasip1, return an empty list
// NOTE: this does not currently check against the Rust SDK MSRV - that could
// be a future enhancement or separate diagnosis, but at least the Rust compiler
// should give a clear error for that!
Expand All @@ -49,7 +49,7 @@ async fn diagnose_rust_wasi_target() -> Result<Vec<TargetDiagnosis>> {
RustupStatus::RustupNotInstalled => match get_cargo_status().await? {
CargoStatus::Installed => {
terminal::warn!(
"Spin Doctor can't determine if the Rust wasm32-wasi target is installed."
"Spin Doctor can't determine if the Rust wasm32-wasip1 target is installed."
);
vec![]
}
Expand Down Expand Up @@ -81,7 +81,7 @@ async fn get_rustup_target_status() -> Result<RustupStatus> {
}
Ok(output) => {
let stdout = String::from_utf8_lossy(&output.stdout);
if stdout.lines().any(|line| line == "wasm32-wasi") {
if stdout.lines().any(|line| line == "wasm32-wasip1") {
RustupStatus::AllInstalled
} else {
RustupStatus::WasiNotInstalled
Expand Down Expand Up @@ -119,7 +119,7 @@ async fn get_cargo_status() -> Result<CargoStatus> {
pub enum TargetDiagnosis {
/// Rust is not installed: neither cargo nor rustup is present
RustNotInstalled,
/// The Rust wasm32-wasi target is not installed: rustup is present but the target isn't
/// The Rust wasm32-wasip1 target is not installed: rustup is present but the target isn't
WasmTargetNotInstalled,
}

Expand All @@ -128,7 +128,7 @@ impl Diagnosis for TargetDiagnosis {
match self {
Self::RustNotInstalled => "The Rust compiler isn't installed".into(),
Self::WasmTargetNotInstalled => {
"The required Rust target 'wasm32-wasi' isn't installed".into()
"The required Rust target 'wasm32-wasip1' isn't installed".into()
}
}
}
Expand All @@ -142,16 +142,16 @@ impl Diagnosis for TargetDiagnosis {
impl Treatment for TargetDiagnosis {
fn summary(&self) -> String {
match self {
Self::RustNotInstalled => "Install the Rust compiler and the wasm32-wasi target",
Self::WasmTargetNotInstalled => "Install the Rust wasm32-wasi target",
Self::RustNotInstalled => "Install the Rust compiler and the wasm32-wasip1 target",
Self::WasmTargetNotInstalled => "Install the Rust wasm32-wasip1 target",
}
.into()
}

async fn dry_run(&self, _patient: &PatientApp) -> Result<String> {
let message = match self {
Self::RustNotInstalled => "Download and run the Rust installer from https://rustup.rs, with the `--target wasm32-wasi` option",
Self::WasmTargetNotInstalled => "Run the following command:\n `rustup target add wasm32-wasi`",
Self::RustNotInstalled => "Download and run the Rust installer from https://rustup.rs, with the `--target wasm32-wasip1` option",
Self::WasmTargetNotInstalled => "Run the following command:\n `rustup target add wasm32-wasip1`",
};
Ok(message.into())
}
Expand Down Expand Up @@ -184,7 +184,7 @@ async fn run_rust_installer() -> Result<std::process::ExitStatus> {
let script = resp.bytes().await?;

let mut cmd = std::process::Command::new("sh");
cmd.args(["-s", "--", "--target", "wasm32-wasi"]);
cmd.args(["-s", "--", "--target", "wasm32-wasip1"]);
cmd.stdin(std::process::Stdio::piped());
let mut shell = cmd.spawn()?;
let mut stdin = shell.stdin.take().unwrap();
Expand Down Expand Up @@ -213,14 +213,14 @@ async fn run_rust_installer() -> Result<std::process::ExitStatus> {
std::fs::write(&installer_path, &installer_bin)?;

let mut cmd = std::process::Command::new(installer_path);
cmd.args(["--target", "wasm32-wasi"]);
cmd.args(["--target", "wasm32-wasip1"]);
let status = cmd.status()?;
Ok(status)
}

fn install_wasi_target() -> Result<()> {
let mut cmd = std::process::Command::new("rustup");
cmd.args(["target", "add", "wasm32-wasi"]);
cmd.args(["target", "add", "wasm32-wasip1"]);
let status = cmd.status()?;
anyhow::ensure!(
status.success(),
Expand Down
4 changes: 2 additions & 2 deletions crates/templates/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,8 @@ mod tests {
assert!(cargo2.contains("name = \"hello-2\""));

let spin_toml = tokio::fs::read_to_string(&spin_toml_path).await.unwrap();
assert!(spin_toml.contains("source = \"hello/target/wasm32-wasi/release/hello.wasm\""));
assert!(spin_toml.contains("source = \"encore/target/wasm32-wasi/release/hello_2.wasm\""));
assert!(spin_toml.contains("source = \"hello/target/wasm32-wasip1/release/hello.wasm\""));
assert!(spin_toml.contains("source = \"encore/target/wasm32-wasip1/release/hello_2.wasm\""));
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion examples/http-rust/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build]
target = "wasm32-wasi"
target = "wasm32-wasip1"
4 changes: 2 additions & 2 deletions examples/http-rust/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ route = "/hello"
component = "hello"

[component.hello]
source = "target/wasm32-wasi/release/http_rust.wasm"
source = "target/wasm32-wasip1/release/http_rust.wasm"
description = "A simple component that returns hello."
[component.hello.build]
command = "cargo build --target wasm32-wasi --release"
command = "cargo build --target wasm32-wasip1 --release"
watch = ["src/**/*.rs", "Cargo.toml"]
Loading

0 comments on commit abba523

Please sign in to comment.