Skip to content

Commit 7daf4f4

Browse files
authoredMar 30, 2025··
fix(cli): Fix plugin target as wasm32-wasip1 (#10293)
**Description:** Fixed the error where the target type behavior was inconsistent with the [documentation](https://swc.rs/docs/plugin/ecmascript/getting-started#create-a-project) when creating a plugin using CLI. Now `wasm32-wasip1` can be used normally as a target. ```shell ❯ cargo run -p swc_cli_impl -- plugin new --target-type wasm32-wasip1 my-first-plugin Running `target\debug\swc.exe plugin new --target-type wasm32-wasip1 my-first-plugin` ✅ Successfully created my-first-plugin. If you haven't, please ensure to add target via "rustup target add wasm32-wasip1" ``` **Related issue:** - Closes #10284
1 parent c276a38 commit 7daf4f4

File tree

12 files changed

+42
-35
lines changed

12 files changed

+42
-35
lines changed
 

‎.changeset/stale-plants-hammer.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
swc_core: patch
3+
swc_cli_impl: patch
4+
swc_plugin_runner: patch
5+
---
6+
7+
fix(cli/plugin): cli plugin target wasm32-wasip1

‎.github/swc-ecosystem-ci/tests/plugin-css-variable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function test(options: RunOptions) {
77
repo: "jantimon/css-variable",
88
branch: "main",
99
build: "build",
10-
beforeBuild: "rustup target add wasm32-wasi",
10+
beforeBuild: "rustup target add wasm32-wasip1",
1111
test: ["test:swc"],
1212
isWasm: true,
1313
});

‎.github/workflows/CI.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ jobs:
219219
uses: actions-rs/toolchain@v1
220220
with:
221221
profile: minimal
222-
target: wasm32-wasi
222+
target: wasm32-wasip1
223223
# MSRV is current stable for ES crates and nightly for other languages
224224
# toolchain: stable
225225
# override: true
@@ -381,7 +381,7 @@ jobs:
381381

382382
- name: Prepare
383383
run: |
384-
rustup target add wasm32-wasi
384+
rustup target add wasm32-wasip1
385385
corepack enable
386386
yarn
387387
@@ -429,7 +429,7 @@ jobs:
429429
430430
- name: Prepare
431431
run: |
432-
rustup target add wasm32-wasi
432+
rustup target add wasm32-wasip1
433433
corepack enable
434434
yarn
435435

‎CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ For running all tests, take the following steps:
104104

105105
See [official install guide of deno](https://docs.deno.com/runtime/manual/getting_started/installation/) to install it.
106106

107-
5. Add wasm32-wasi target
107+
5. Add wasm32-wasip1 target
108108

109-
`rustup target add wasm32-wasi`
109+
`rustup target add wasm32-wasip1`
110110

111111
6. Ensure you're using Node.JS >= 16
112112

‎crates/swc_cli_impl/src/commands/plugin.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use swc_core::diagnostics::get_core_engine_diagnostics;
1212
pub enum PluginTargetType {
1313
/// wasm32-unknown-unknown target.
1414
Wasm32UnknownUnknown,
15-
/// wasm32-wasi target.
16-
Wasm32Wasi,
15+
/// wasm32-wasip1 target.
16+
Wasm32Wasip1,
1717
}
1818

1919
#[derive(Parser, Debug)]
@@ -24,7 +24,7 @@ pub struct PluginScaffoldOptions {
2424

2525
/// Sets default build target type of the plugin.
2626
///
27-
/// "wasm32-wasi" enables wasi (https://github.com/WebAssembly/WASI) support for the generated
27+
/// "wasm32-wasip1" enables wasi (https://github.com/WebAssembly/WASI) support for the generated
2828
/// binary which allows to use macros like 'println!' or 'dbg!' and other
2929
/// system-related calls.
3030
///
@@ -166,7 +166,7 @@ serde = "1"
166166
swc_core = {{ version = "{}", features = ["ecma_plugin_transform"] }}
167167
168168
# .cargo/config.toml defines few alias to build plugin.
169-
# cargo build-wasi generates wasm-wasi32 binary
169+
# cargo build-wasip1 generates wasm32-wasip1 binary
170170
# cargo build-wasm32 generates wasm32-unknown-unknown binary.
171171
"#,
172172
name, swc_core_version
@@ -177,12 +177,12 @@ swc_core = {{ version = "{}", features = ["ecma_plugin_transform"] }}
177177

178178
let build_target = match self.target_type {
179179
PluginTargetType::Wasm32UnknownUnknown => "wasm32-unknown-unknown",
180-
PluginTargetType::Wasm32Wasi => "wasm32-wasi",
180+
PluginTargetType::Wasm32Wasip1 => "wasm32-wasip1",
181181
};
182182

183183
let build_alias = match self.target_type {
184184
PluginTargetType::Wasm32UnknownUnknown => "build-wasm32",
185-
PluginTargetType::Wasm32Wasi => "build-wasi",
185+
PluginTargetType::Wasm32Wasip1 => "build-wasip1",
186186
};
187187

188188
// Create `.cargo/config.toml` file for build target
@@ -193,7 +193,7 @@ swc_core = {{ version = "{}", features = ["ecma_plugin_transform"] }}
193193
r#"# These command aliases are not final, may change
194194
[alias]
195195
# Alias to build actual plugin binary for the specified target.
196-
build-wasi = "build --target wasm32-wasi"
196+
build-wasip1 = "build --target wasm32-wasip1"
197197
build-wasm32 = "build --target wasm32-unknown-unknown"
198198
"#
199199
.as_bytes(),

‎crates/swc_plugin_runner/benches/ecma_invoke.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn plugin_group(c: &mut Criterion) {
3333
cmd.current_dir(&plugin_dir);
3434
cmd.arg("build")
3535
.arg("--release")
36-
.arg("--target=wasm32-wasi");
36+
.arg("--target=wasm32-wasip1");
3737

3838
let status = cmd.status().unwrap();
3939
assert!(status.success());
@@ -45,7 +45,7 @@ fn plugin_group(c: &mut Criterion) {
4545
fn bench_transform(b: &mut Bencher, plugin_dir: &Path) {
4646
let path = &plugin_dir
4747
.join("target")
48-
.join("wasm32-wasi")
48+
.join("wasm32-wasip1")
4949
.join("release")
5050
.join("swc_noop_plugin.wasm");
5151
let raw_module_bytes = std::fs::read(path).expect("Should able to read plugin bytes");

‎crates/swc_plugin_runner/src/transform_executor.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ impl TransformExecutor {
268268
&diagnostics_env,
269269
);
270270

271-
// Plugin binary can be either wasm32-wasi or wasm32-unknown-unknown.
272-
// Wasi specific env need to be initialized if given module targets wasm32-wasi.
273-
// TODO: wasm host native runtime throws 'Memory should be set on `WasiEnv`
274-
// first'
271+
// Plugin binary can be either wasm32-wasip1 or wasm32-unknown-unknown.
272+
// Wasi specific env need to be initialized if given module targets
273+
// wasm32-wasip1. TODO: wasm host native runtime throws 'Memory should
274+
// be set on `WasiEnv` first'
275275
let (instance, wasi_env) = if is_wasi_module(&module) {
276276
let builder = WasiEnv::builder(self.module_bytes.get_module_name());
277277
let builder = if let Some(runtime) = &self.runtime {
@@ -397,19 +397,19 @@ impl TransformExecutor {
397397
used by the plugin is compatible with the host runtime. See the \
398398
documentation for compatibility information. If you are an author of the \
399399
plugin, please update `swc_core` to the compatible version.
400-
400+
401401
Note that if you want to use the os features like filesystem, you need to use \
402402
`wasi`. Wasm itself does not have concept of filesystem.
403-
403+
404404
https://swc.rs/docs/plugin/selecting-swc-core
405405
406406
See https://plugins.swc.rs/versions/from-plugin-runner/{PKG_VERSION} for the list of the compatible versions.
407-
408-
Build info:
407+
408+
Build info:
409409
Date: {BUILD_DATE}
410410
Timestamp: {BUILD_TIMESTAMP}
411-
412-
Version info:
411+
412+
Version info:
413413
swc_plugin_runner: {PKG_VERSION}
414414
Dependencies: {PKG_DEPS}
415415
"

‎crates/swc_plugin_runner/tests/css_rkyv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn build_plugin(dir: &Path) -> Result<PathBuf, Error> {
2222
cmd.env("CARGO_TARGET_DIR", &*CARGO_TARGET_DIR);
2323

2424
cmd.current_dir(dir);
25-
cmd.args(["build", "--target=wasm32-wasi", "--release"])
25+
cmd.args(["build", "--target=wasm32-wasip1", "--release"])
2626
.stderr(Stdio::inherit());
2727
cmd.output()?;
2828

@@ -35,7 +35,7 @@ fn build_plugin(dir: &Path) -> Result<PathBuf, Error> {
3535
}
3636
}
3737

38-
for entry in fs::read_dir(CARGO_TARGET_DIR.join("wasm32-wasi").join("release"))? {
38+
for entry in fs::read_dir(CARGO_TARGET_DIR.join("wasm32-wasip1").join("release"))? {
3939
let entry = entry?;
4040

4141
let s = entry.file_name().to_string_lossy().into_owned();

‎crates/swc_plugin_runner/tests/ecma_integration.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn build_plugin(dir: &Path) -> Result<PathBuf, Error> {
2626
let mut cmd = Command::new("cargo");
2727
cmd.env("CARGO_TARGET_DIR", &*CARGO_TARGET_DIR);
2828
cmd.current_dir(dir);
29-
cmd.args(["build", "--target=wasm32-wasi"])
29+
cmd.args(["build", "--target=wasm32-wasip1"])
3030
.stderr(Stdio::inherit());
3131
cmd.output()?;
3232

@@ -39,7 +39,7 @@ fn build_plugin(dir: &Path) -> Result<PathBuf, Error> {
3939
}
4040
}
4141

42-
for entry in fs::read_dir(CARGO_TARGET_DIR.join("wasm32-wasi").join("debug"))? {
42+
for entry in fs::read_dir(CARGO_TARGET_DIR.join("wasm32-wasip1").join("debug"))? {
4343
let entry = entry?;
4444

4545
let s = entry.file_name().to_string_lossy().into_owned();

‎crates/swc_plugin_runner/tests/ecma_rkyv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn build_plugin(dir: &Path) -> Result<PathBuf, Error> {
2323
let mut cmd = Command::new("cargo");
2424
cmd.env("CARGO_TARGET_DIR", &*CARGO_TARGET_DIR);
2525
cmd.current_dir(dir);
26-
cmd.args(["build", "--target=wasm32-wasi", "--release"])
26+
cmd.args(["build", "--target=wasm32-wasip1", "--release"])
2727
.stderr(Stdio::inherit());
2828
cmd.output()?;
2929

@@ -36,7 +36,7 @@ fn build_plugin(dir: &Path) -> Result<PathBuf, Error> {
3636
}
3737
}
3838

39-
for entry in fs::read_dir(CARGO_TARGET_DIR.join("wasm32-wasi").join("release"))? {
39+
for entry in fs::read_dir(CARGO_TARGET_DIR.join("wasm32-wasip1").join("release"))? {
4040
let entry = entry?;
4141

4242
let s = entry.file_name().to_string_lossy().into_owned();

‎crates/swc_plugin_runner/tests/issues.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn build_plugin(dir: &Path, crate_name: &str) -> Result<PathBuf, Error> {
2323
let mut cmd = Command::new("cargo");
2424
cmd.env("CARGO_TARGET_DIR", &*CARGO_TARGET_DIR);
2525
cmd.current_dir(dir);
26-
cmd.args(["build", "--release", "--target=wasm32-wasi"])
26+
cmd.args(["build", "--release", "--target=wasm32-wasip1"])
2727
.stderr(Stdio::inherit());
2828
cmd.output()?;
2929

@@ -36,7 +36,7 @@ fn build_plugin(dir: &Path, crate_name: &str) -> Result<PathBuf, Error> {
3636
}
3737
}
3838

39-
for entry in fs::read_dir(CARGO_TARGET_DIR.join("wasm32-wasi").join("release"))? {
39+
for entry in fs::read_dir(CARGO_TARGET_DIR.join("wasm32-wasip1").join("release"))? {
4040
let entry = entry?;
4141

4242
let s = entry.file_name().to_string_lossy().into_owned();

‎packages/core/e2e/plugins/plugins.schema.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const waitProcessAsync = async (proc) =>
1717
const getPluginAbsolutePath = (feature) =>
1818
path.join(
1919
getPkgRoot(),
20-
`node-swc/e2e/fixtures/${feature}/target/wasm32-wasi/debug/${feature}.wasm`
20+
`node-swc/e2e/fixtures/${feature}/target/wasm32-wasip1/debug/${feature}.wasm`
2121
);
2222

2323
/**
@@ -50,7 +50,7 @@ const buildPlugin = async (feature) => {
5050
"--manifest-path",
5151
`./node-swc/e2e/fixtures/${feature}/Cargo.toml`,
5252
"--target",
53-
"wasm32-wasi",
53+
"wasm32-wasip1",
5454
];
5555

5656
const options = { cwd: getPkgRoot(), stdio: "inherit" };

0 commit comments

Comments
 (0)
Please sign in to comment.