Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/stale-plants-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
swc_core: patch
swc_cli_impl: patch
swc_plugin_runner: patch
---

fix(cli/plugin): cli plugin target wasm32-wasip1
2 changes: 1 addition & 1 deletion .github/swc-ecosystem-ci/tests/plugin-css-variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export async function test(options: RunOptions) {
repo: "jantimon/css-variable",
branch: "main",
build: "build",
beforeBuild: "rustup target add wasm32-wasi",
beforeBuild: "rustup target add wasm32-wasip1",
test: ["test:swc"],
isWasm: true,
});
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
target: wasm32-wasi
target: wasm32-wasip1
# MSRV is current stable for ES crates and nightly for other languages
# toolchain: stable
# override: true
Expand Down Expand Up @@ -381,7 +381,7 @@ jobs:

- name: Prepare
run: |
rustup target add wasm32-wasi
rustup target add wasm32-wasip1
corepack enable
yarn

Expand Down Expand Up @@ -429,7 +429,7 @@ jobs:

- name: Prepare
run: |
rustup target add wasm32-wasi
rustup target add wasm32-wasip1
corepack enable
yarn

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ For running all tests, take the following steps:

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

5. Add wasm32-wasi target
5. Add wasm32-wasip1 target

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

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

Expand Down
14 changes: 7 additions & 7 deletions crates/swc_cli_impl/src/commands/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use swc_core::diagnostics::get_core_engine_diagnostics;
pub enum PluginTargetType {
/// wasm32-unknown-unknown target.
Wasm32UnknownUnknown,
/// wasm32-wasi target.
Wasm32Wasi,
/// wasm32-wasip1 target.
Wasm32Wasip1,
}

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

/// Sets default build target type of the plugin.
///
/// "wasm32-wasi" enables wasi (https://github.com/WebAssembly/WASI) support for the generated
/// "wasm32-wasip1" enables wasi (https://github.com/WebAssembly/WASI) support for the generated
/// binary which allows to use macros like 'println!' or 'dbg!' and other
/// system-related calls.
///
Expand Down Expand Up @@ -166,7 +166,7 @@ serde = "1"
swc_core = {{ version = "{}", features = ["ecma_plugin_transform"] }}

# .cargo/config.toml defines few alias to build plugin.
# cargo build-wasi generates wasm-wasi32 binary
# cargo build-wasip1 generates wasm32-wasip1 binary
# cargo build-wasm32 generates wasm32-unknown-unknown binary.
"#,
name, swc_core_version
Expand All @@ -177,12 +177,12 @@ swc_core = {{ version = "{}", features = ["ecma_plugin_transform"] }}

let build_target = match self.target_type {
PluginTargetType::Wasm32UnknownUnknown => "wasm32-unknown-unknown",
PluginTargetType::Wasm32Wasi => "wasm32-wasi",
PluginTargetType::Wasm32Wasip1 => "wasm32-wasip1",
};

let build_alias = match self.target_type {
PluginTargetType::Wasm32UnknownUnknown => "build-wasm32",
PluginTargetType::Wasm32Wasi => "build-wasi",
PluginTargetType::Wasm32Wasip1 => "build-wasip1",
};

// Create `.cargo/config.toml` file for build target
Expand All @@ -193,7 +193,7 @@ swc_core = {{ version = "{}", features = ["ecma_plugin_transform"] }}
r#"# These command aliases are not final, may change
[alias]
# Alias to build actual plugin binary for the specified target.
build-wasi = "build --target wasm32-wasi"
build-wasip1 = "build --target wasm32-wasip1"
build-wasm32 = "build --target wasm32-unknown-unknown"
"#
.as_bytes(),
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_plugin_runner/benches/ecma_invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn plugin_group(c: &mut Criterion) {
cmd.current_dir(&plugin_dir);
cmd.arg("build")
.arg("--release")
.arg("--target=wasm32-wasi");
.arg("--target=wasm32-wasip1");

let status = cmd.status().unwrap();
assert!(status.success());
Expand All @@ -45,7 +45,7 @@ fn plugin_group(c: &mut Criterion) {
fn bench_transform(b: &mut Bencher, plugin_dir: &Path) {
let path = &plugin_dir
.join("target")
.join("wasm32-wasi")
.join("wasm32-wasip1")
.join("release")
.join("swc_noop_plugin.wasm");
let raw_module_bytes = std::fs::read(path).expect("Should able to read plugin bytes");
Expand Down
20 changes: 10 additions & 10 deletions crates/swc_plugin_runner/src/transform_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ impl TransformExecutor {
&diagnostics_env,
);

// Plugin binary can be either wasm32-wasi or wasm32-unknown-unknown.
// Wasi specific env need to be initialized if given module targets wasm32-wasi.
// TODO: wasm host native runtime throws 'Memory should be set on `WasiEnv`
// first'
// Plugin binary can be either wasm32-wasip1 or wasm32-unknown-unknown.
// Wasi specific env need to be initialized if given module targets
// wasm32-wasip1. TODO: wasm host native runtime throws 'Memory should
// be set on `WasiEnv` first'
let (instance, wasi_env) = if is_wasi_module(&module) {
let builder = WasiEnv::builder(self.module_bytes.get_module_name());
let builder = if let Some(runtime) = &self.runtime {
Expand Down Expand Up @@ -397,19 +397,19 @@ impl TransformExecutor {
used by the plugin is compatible with the host runtime. See the \
documentation for compatibility information. If you are an author of the \
plugin, please update `swc_core` to the compatible version.

Note that if you want to use the os features like filesystem, you need to use \
`wasi`. Wasm itself does not have concept of filesystem.

https://swc.rs/docs/plugin/selecting-swc-core

See https://plugins.swc.rs/versions/from-plugin-runner/{PKG_VERSION} for the list of the compatible versions.
Build info:

Build info:
Date: {BUILD_DATE}
Timestamp: {BUILD_TIMESTAMP}
Version info:

Version info:
swc_plugin_runner: {PKG_VERSION}
Dependencies: {PKG_DEPS}
"
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_plugin_runner/tests/css_rkyv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn build_plugin(dir: &Path) -> Result<PathBuf, Error> {
cmd.env("CARGO_TARGET_DIR", &*CARGO_TARGET_DIR);

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

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

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

let s = entry.file_name().to_string_lossy().into_owned();
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_plugin_runner/tests/ecma_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn build_plugin(dir: &Path) -> Result<PathBuf, Error> {
let mut cmd = Command::new("cargo");
cmd.env("CARGO_TARGET_DIR", &*CARGO_TARGET_DIR);
cmd.current_dir(dir);
cmd.args(["build", "--target=wasm32-wasi"])
cmd.args(["build", "--target=wasm32-wasip1"])
.stderr(Stdio::inherit());
cmd.output()?;

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

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

let s = entry.file_name().to_string_lossy().into_owned();
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_plugin_runner/tests/ecma_rkyv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn build_plugin(dir: &Path) -> Result<PathBuf, Error> {
let mut cmd = Command::new("cargo");
cmd.env("CARGO_TARGET_DIR", &*CARGO_TARGET_DIR);
cmd.current_dir(dir);
cmd.args(["build", "--target=wasm32-wasi", "--release"])
cmd.args(["build", "--target=wasm32-wasip1", "--release"])
.stderr(Stdio::inherit());
cmd.output()?;

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

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

let s = entry.file_name().to_string_lossy().into_owned();
Expand Down
4 changes: 2 additions & 2 deletions crates/swc_plugin_runner/tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn build_plugin(dir: &Path, crate_name: &str) -> Result<PathBuf, Error> {
let mut cmd = Command::new("cargo");
cmd.env("CARGO_TARGET_DIR", &*CARGO_TARGET_DIR);
cmd.current_dir(dir);
cmd.args(["build", "--release", "--target=wasm32-wasi"])
cmd.args(["build", "--release", "--target=wasm32-wasip1"])
.stderr(Stdio::inherit());
cmd.output()?;

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

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

let s = entry.file_name().to_string_lossy().into_owned();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/e2e/plugins/plugins.schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const waitProcessAsync = async (proc) =>
const getPluginAbsolutePath = (feature) =>
path.join(
getPkgRoot(),
`node-swc/e2e/fixtures/${feature}/target/wasm32-wasi/debug/${feature}.wasm`
`node-swc/e2e/fixtures/${feature}/target/wasm32-wasip1/debug/${feature}.wasm`
);

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ const buildPlugin = async (feature) => {
"--manifest-path",
`./node-swc/e2e/fixtures/${feature}/Cargo.toml`,
"--target",
"wasm32-wasi",
"wasm32-wasip1",
];

const options = { cwd: getPkgRoot(), stdio: "inherit" };
Expand Down
Loading