Unverified Commit 3bbbb32f authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

Enable wasm plugins on windows arm (#92544)

Not because we should, but because we can.

Previously we disabled this due to an incompatibility between windows arm and wasmer, however we recently switched to wasmtime which appears to work.

So simplify the CI configuration and the rust feature flags

https://github.com/vercel/next.js/actions/runs/24271405735 is a build-and-deploy.yml run and this is the [windows arm build](https://github.com/vercel/next.js/actions/runs/24271405735/job/70877042113)
parent dde29803
......@@ -168,8 +168,7 @@ jobs:
abi: msvc
arch:
x86_64: {}
aarch64:
build_task: build-native-no-plugin-release
aarch64: {}
linux:
host: "['self-hosted', 'linux', 'x64', 'metal']"
docker: next-swc-builder:latest
......
......@@ -88,7 +88,7 @@ jobs:
- name: Build next-swc
run: |
hyperfine --min-runs 1 --show-output 'pnpm run --filter=@next/swc build-native --features plugin --release'
hyperfine --min-runs 1 --show-output 'pnpm run --filter=@next/swc build-native --release'
echo "Successfully built next-swc with published turbopack"
- name: Build next.js
......
......@@ -4989,7 +4989,6 @@ dependencies = [
"turbo-unix-path",
"turbopack-core",
"turbopack-ecmascript-hmr-protocol",
"turbopack-ecmascript-plugins",
"turbopack-node",
"turbopack-trace-server",
"turbopack-trace-utils",
......
......@@ -87,7 +87,7 @@ inherits = "release"
debug = true
# Size-optimized crates: determined via `cargo bloat --release --crates -p next-napi-bindings`.
# Wasmtime/cranelift crates are used by the plugin feature (wasm builds).
# Wasmtime/cranelift crates are used by the SWC plugin transform system.
[profile.release.package.browserslist-rs]
opt-level = "s"
......
......@@ -92,11 +92,6 @@ default = ["process_pool"]
process_pool = ["turbopack-node/process_pool"]
worker_pool = ["turbopack-node/worker_pool"]
next-font-local = []
plugin = [
"swc_core/__plugin_transform_host",
"swc_core/__plugin_transform_host_schema_v1",
"turbopack-ecmascript-plugins/swc_ecma_transform_plugin",
]
image-webp = ["turbopack-image/webp"]
image-avif = ["turbopack-image/avif"]
......
use anyhow::Result;
#[allow(unused_imports)]
use turbo_rcstr::RcStr;
use turbo_tasks::Vc;
use turbo_tasks_fs::FileSystemPath;
use turbopack::module_options::ModuleRule;
#[allow(unused_imports)]
use turbopack_core::{context::AssetContext, resolve::origin::ResolveOrigin};
use crate::next_config::NextConfig;
......@@ -15,30 +13,19 @@ pub async fn get_swc_ecma_transform_plugin_rule(
) -> Result<Option<ModuleRule>> {
let plugin_configs = next_config.experimental_swc_plugins().await?;
if !plugin_configs.is_empty() {
#[cfg(feature = "plugin")]
{
let enable_mdx_rs = next_config.mdx_rs().await?.is_some();
get_swc_ecma_transform_rule_impl(project_path, &plugin_configs, enable_mdx_rs).await
}
#[cfg(not(feature = "plugin"))]
{
let _ = project_path; // To satisfy lint
Ok(None)
}
let enable_mdx_rs = next_config.mdx_rs().await?.is_some();
get_swc_ecma_transform_rule_impl(project_path, &plugin_configs, enable_mdx_rs).await
} else {
Ok(None)
}
}
/// A resolve origin without any asset_context, intended for handle_resolve_error
#[cfg(feature = "plugin")]
#[turbo_tasks::value]
pub struct DummyResolveOrigin {
origin_path: FileSystemPath,
}
#[cfg(feature = "plugin")]
#[turbo_tasks::value_impl]
impl DummyResolveOrigin {
#[turbo_tasks::function]
......@@ -47,7 +34,6 @@ impl DummyResolveOrigin {
}
}
#[cfg(feature = "plugin")]
#[turbo_tasks::value_impl]
impl ResolveOrigin for DummyResolveOrigin {
#[turbo_tasks::function]
......@@ -61,7 +47,6 @@ impl ResolveOrigin for DummyResolveOrigin {
}
}
#[cfg(feature = "plugin")]
pub async fn get_swc_ecma_transform_rule_impl(
project_path: FileSystemPath,
plugin_configs: &[(RcStr, serde_json::Value)],
......
......@@ -4,20 +4,6 @@ name = "next-custom-transforms"
version = "0.0.0"
publish = false
[features]
plugin = [
"swc_core/__plugin_transform_host",
"swc_core/__plugin_transform_host_schema_v1",
"turbopack-ecmascript-plugins/swc_ecma_transform_plugin",
]
[package.metadata.cargo-shear]
ignored = [
# when using the `plugin` feature, we need to set a feature flag on `turbopack-ecmascript-plugins`
# so we must list it as a dependency even though we don't directly use it
"turbopack-ecmascript-plugins",
]
[lints]
workspace = true
......@@ -64,7 +50,6 @@ styled_components = { workspace = true }
styled_jsx = { workspace = true }
swc_emotion = { workspace = true }
swc_relay = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, optional = true }
turbo-rcstr = { workspace = true }
urlencoding = { workspace = true }
next-taskless = { workspace = true }
......@@ -75,7 +60,6 @@ preset_env_base = { workspace = true }
[dev-dependencies]
testing = { workspace = true }
# effectively enable the "plugin" feature for tests
swc_core = { workspace = true, features = ["testing_transform", "__plugin_transform_host", "__plugin_transform_host_schema_v1"] }
swc_plugin_backend_wasmtime = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, features = ["swc_ecma_transform_plugin"] }
turbopack-ecmascript-plugins = { workspace = true }
......@@ -8,23 +8,6 @@ publish = false
crate-type = ["cdylib"]
[features]
# Instead of enabling all the plugin-related functionality by default, make it
# overridable when built (i.e napi --build --features plugin). This is due to
# some of transitive dependencies have features cannot be enabled at the same
# time (i.e wasmer/default vs wasmer/js-default) while cargo merges all the
# features at once.
plugin = [
# Use granular plugin features to avoid pulling in wasmer via __plugin_transform_env_native.
"swc_core/__plugin_transform_host",
"swc_core/__plugin_transform_host_schema_v1",
"swc_core/plugin_transform_host_native_filesystem_cache",
"dep:swc_plugin_backend_wasmtime",
"next-custom-transforms/plugin",
"next-core/plugin",
"turbopack-ecmascript-plugins",
"turbopack-ecmascript-plugins/swc_ecma_transform_plugin",
]
image-webp = ["next-core/image-webp"]
image-avif = ["next-core/image-avif"]
# Enable all the available image codec support.
......@@ -50,11 +33,6 @@ ignored = [
# we need to set features on these packages when building for WASM, but we don't directly use them
"getrandom",
"iana-time-zone",
# the plugins feature needs to set a feature on this transitively depended-on package, we never
# directly import it
"turbopack-ecmascript-plugins",
# used conditionally behind the `plugin` feature flag
"swc_plugin_backend_wasmtime",
]
[dependencies]
......@@ -105,13 +83,16 @@ swc_core = { workspace = true, features = [
"ecma_transforms_typescript",
"ecma_utils",
"ecma_visit",
"__plugin_transform_host",
"__plugin_transform_host_schema_v1",
"plugin_transform_host_native_filesystem_cache",
] }
# Dependencies for the native, non-wasm32 build.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
lightningcss-napi = { workspace = true }
swc_plugin_backend_wasmtime = { workspace = true, optional = true }
lightningcss = { workspace = true }
swc_plugin_backend_wasmtime = { workspace = true }
tokio = { workspace = true, features = ["full"] }
turbo-rcstr = { workspace = true, features = ["napi"] }
turbo-tasks = { workspace = true }
......@@ -132,7 +113,6 @@ turbopack-core = { workspace = true }
turbopack-ecmascript-hmr-protocol = { workspace = true }
turbopack-trace-utils = { workspace = true }
turbopack-trace-server = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, optional = true }
turbopack-node = { workspace = true, default-features = false, features = ["worker_pool"] }
[target.'cfg(windows)'.dependencies]
......
......@@ -31,6 +31,7 @@ use std::{
fs::read_to_string,
panic::{AssertUnwindSafe, catch_unwind},
rc::Rc,
sync::Arc,
};
use anyhow::{Context as _, anyhow, bail};
......@@ -41,10 +42,11 @@ use once_cell::sync::Lazy;
use rustc_hash::{FxHashMap, FxHashSet};
use swc_core::{
atoms::Atom,
base::{Compiler, TransformOutput, try_with_handler},
base::{Compiler, TransformOutput, config::RuntimeOptions, try_with_handler},
common::{FileName, GLOBALS, Mark, comments::SingleThreadedComments, errors::ColorConfig},
ecma::ast::noop_pass,
};
use swc_plugin_backend_wasmtime::WasmtimeRuntime;
use crate::{complete_output, get_compiler, util::MapErr};
......@@ -128,15 +130,8 @@ impl Task for TransformTask {
let unresolved_mark = Mark::new();
let mut options = options.patch(&fm);
options.swc.unresolved_mark = Some(unresolved_mark);
#[cfg(feature = "plugin")]
{
options.swc.runtime_options =
swc_core::base::config::RuntimeOptions::default()
.plugin_runtime(std::sync::Arc::new(
swc_plugin_backend_wasmtime::WasmtimeRuntime,
));
}
options.swc.runtime_options =
RuntimeOptions::default().plugin_runtime(Arc::new(WasmtimeRuntime));
let cm = self.c.cm.clone();
let file = fm.clone();
......
......@@ -8,11 +8,9 @@
"scripts": {
"build-native-auto": "node maybe-build-native.mjs",
"clean": "node ../../scripts/rm.mjs native",
"build-native": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --features plugin,image-extended --js false native",
"build-native-release": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --release --features plugin,image-extended,tracing/release_max_level_trace --js false native",
"build-native-release-with-assertions": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --profile release-with-assertions --features plugin,image-extended,tracing/release_max_level_trace --js false native",
"build-native-no-plugin": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --features image-webp --js false native",
"build-native-no-plugin-release": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --release --features image-webp,tracing/release_max_level_trace --js false native",
"build-native": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --features image-extended --js false native",
"build-native-release": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --release --features image-extended,tracing/release_max_level_trace --js false native",
"build-native-release-with-assertions": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --profile release-with-assertions --features image-extended,tracing/release_max_level_trace --js false native",
"build-native-wasi": "npx --package=@napi-rs/cli@3.0.0-alpha.45 napi build --platform --target wasm32-wasip1-threads -p next-napi-bindings --cwd ../../ --output-dir packages/next-swc/native --no-default-features",
"build-sccache": "node ../../scripts/build-sccache.js",
"build-wasm": "wasm-pack build ../../crates/wasm --scope=next",
......
......@@ -46,16 +46,6 @@
"inputs": ["../../target/.rust-fingerprint"],
"outputs": ["native/*.node", "native/index.d.ts"],
},
"build-native-no-plugin": {
"dependsOn": ["rust-fingerprint"],
"inputs": ["../../target/.rust-fingerprint"],
"outputs": ["native/*.node", "native/index.d.ts"],
},
"build-native-no-plugin-release": {
"dependsOn": ["rust-fingerprint"],
"inputs": ["../../target/.rust-fingerprint"],
"outputs": ["native/*.node", "native/index.d.ts"],
},
"build-wasm": {
"dependsOn": ["rust-fingerprint"],
"inputs": ["../../target/.rust-fingerprint"],
......
......@@ -10,18 +10,7 @@ autobenches = false
bench = false
[features]
default = ["swc_ecma_transform_plugin"]
transform_emotion = []
# [NOTE]: Be careful to explicitly enable this only for the supported platform / targets.
swc_ecma_transform_plugin = [
# Use granular plugin features to avoid pulling in wasmer via __plugin_transform_env_native.
# __plugin_transform_host provides the plugin runner types and proxy re-exports.
# __plugin_transform_host_schema_v1 provides the schema version support.
# We provide WasmtimeRuntime explicitly, so we don't need swc's env-native backend wiring.
"swc_core/__plugin_transform_host",
"swc_core/__plugin_transform_host_schema_v1",
"swc_plugin_backend_wasmtime"
]
[lints]
workspace = true
......@@ -45,8 +34,14 @@ turbopack-ecmascript = { workspace = true }
styled_components = { workspace = true }
styled_jsx = { workspace = true }
swc_core = { workspace = true, features = ["ecma_ast", "ecma_visit", "common"] }
swc_plugin_backend_wasmtime = { workspace = true, optional = true }
swc_core = { workspace = true, features = [
"ecma_ast",
"ecma_visit",
"common",
"__plugin_transform_host",
"__plugin_transform_host_schema_v1",
] }
swc_plugin_backend_wasmtime = { workspace = true }
swc_emotion = { workspace = true }
swc_relay = { workspace = true }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment