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: ...@@ -168,8 +168,7 @@ jobs:
abi: msvc abi: msvc
arch: arch:
x86_64: {} x86_64: {}
aarch64: aarch64: {}
build_task: build-native-no-plugin-release
linux: linux:
host: "['self-hosted', 'linux', 'x64', 'metal']" host: "['self-hosted', 'linux', 'x64', 'metal']"
docker: next-swc-builder:latest docker: next-swc-builder:latest
......
...@@ -88,7 +88,7 @@ jobs: ...@@ -88,7 +88,7 @@ jobs:
- name: Build next-swc - name: Build next-swc
run: | 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" echo "Successfully built next-swc with published turbopack"
- name: Build next.js - name: Build next.js
......
...@@ -4989,7 +4989,6 @@ dependencies = [ ...@@ -4989,7 +4989,6 @@ dependencies = [
"turbo-unix-path", "turbo-unix-path",
"turbopack-core", "turbopack-core",
"turbopack-ecmascript-hmr-protocol", "turbopack-ecmascript-hmr-protocol",
"turbopack-ecmascript-plugins",
"turbopack-node", "turbopack-node",
"turbopack-trace-server", "turbopack-trace-server",
"turbopack-trace-utils", "turbopack-trace-utils",
......
...@@ -87,7 +87,7 @@ inherits = "release" ...@@ -87,7 +87,7 @@ inherits = "release"
debug = true debug = true
# Size-optimized crates: determined via `cargo bloat --release --crates -p next-napi-bindings`. # 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] [profile.release.package.browserslist-rs]
opt-level = "s" opt-level = "s"
......
...@@ -92,11 +92,6 @@ default = ["process_pool"] ...@@ -92,11 +92,6 @@ default = ["process_pool"]
process_pool = ["turbopack-node/process_pool"] process_pool = ["turbopack-node/process_pool"]
worker_pool = ["turbopack-node/worker_pool"] worker_pool = ["turbopack-node/worker_pool"]
next-font-local = [] 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-webp = ["turbopack-image/webp"]
image-avif = ["turbopack-image/avif"] image-avif = ["turbopack-image/avif"]
......
use anyhow::Result; use anyhow::Result;
#[allow(unused_imports)]
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::Vc; use turbo_tasks::Vc;
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack::module_options::ModuleRule; use turbopack::module_options::ModuleRule;
#[allow(unused_imports)]
use turbopack_core::{context::AssetContext, resolve::origin::ResolveOrigin}; use turbopack_core::{context::AssetContext, resolve::origin::ResolveOrigin};
use crate::next_config::NextConfig; use crate::next_config::NextConfig;
...@@ -15,30 +13,19 @@ pub async fn get_swc_ecma_transform_plugin_rule( ...@@ -15,30 +13,19 @@ pub async fn get_swc_ecma_transform_plugin_rule(
) -> Result<Option<ModuleRule>> { ) -> Result<Option<ModuleRule>> {
let plugin_configs = next_config.experimental_swc_plugins().await?; let plugin_configs = next_config.experimental_swc_plugins().await?;
if !plugin_configs.is_empty() { 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
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)
}
} else { } else {
Ok(None) Ok(None)
} }
} }
/// A resolve origin without any asset_context, intended for handle_resolve_error /// A resolve origin without any asset_context, intended for handle_resolve_error
#[cfg(feature = "plugin")]
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct DummyResolveOrigin { pub struct DummyResolveOrigin {
origin_path: FileSystemPath, origin_path: FileSystemPath,
} }
#[cfg(feature = "plugin")]
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl DummyResolveOrigin { impl DummyResolveOrigin {
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -47,7 +34,6 @@ impl DummyResolveOrigin { ...@@ -47,7 +34,6 @@ impl DummyResolveOrigin {
} }
} }
#[cfg(feature = "plugin")]
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ResolveOrigin for DummyResolveOrigin { impl ResolveOrigin for DummyResolveOrigin {
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -61,7 +47,6 @@ impl ResolveOrigin for DummyResolveOrigin { ...@@ -61,7 +47,6 @@ impl ResolveOrigin for DummyResolveOrigin {
} }
} }
#[cfg(feature = "plugin")]
pub async fn get_swc_ecma_transform_rule_impl( pub async fn get_swc_ecma_transform_rule_impl(
project_path: FileSystemPath, project_path: FileSystemPath,
plugin_configs: &[(RcStr, serde_json::Value)], plugin_configs: &[(RcStr, serde_json::Value)],
......
...@@ -4,20 +4,6 @@ name = "next-custom-transforms" ...@@ -4,20 +4,6 @@ name = "next-custom-transforms"
version = "0.0.0" version = "0.0.0"
publish = false 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] [lints]
workspace = true workspace = true
...@@ -64,7 +50,6 @@ styled_components = { workspace = true } ...@@ -64,7 +50,6 @@ styled_components = { workspace = true }
styled_jsx = { workspace = true } styled_jsx = { workspace = true }
swc_emotion = { workspace = true } swc_emotion = { workspace = true }
swc_relay = { workspace = true } swc_relay = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, optional = true }
turbo-rcstr = { workspace = true } turbo-rcstr = { workspace = true }
urlencoding = { workspace = true } urlencoding = { workspace = true }
next-taskless = { workspace = true } next-taskless = { workspace = true }
...@@ -75,7 +60,6 @@ preset_env_base = { workspace = true } ...@@ -75,7 +60,6 @@ preset_env_base = { workspace = true }
[dev-dependencies] [dev-dependencies]
testing = { workspace = true } 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_core = { workspace = true, features = ["testing_transform", "__plugin_transform_host", "__plugin_transform_host_schema_v1"] }
swc_plugin_backend_wasmtime = { workspace = true } 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 ...@@ -8,23 +8,6 @@ publish = false
crate-type = ["cdylib"] crate-type = ["cdylib"]
[features] [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-webp = ["next-core/image-webp"]
image-avif = ["next-core/image-avif"] image-avif = ["next-core/image-avif"]
# Enable all the available image codec support. # Enable all the available image codec support.
...@@ -50,11 +33,6 @@ ignored = [ ...@@ -50,11 +33,6 @@ ignored = [
# we need to set features on these packages when building for WASM, but we don't directly use them # we need to set features on these packages when building for WASM, but we don't directly use them
"getrandom", "getrandom",
"iana-time-zone", "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] [dependencies]
...@@ -105,13 +83,16 @@ swc_core = { workspace = true, features = [ ...@@ -105,13 +83,16 @@ swc_core = { workspace = true, features = [
"ecma_transforms_typescript", "ecma_transforms_typescript",
"ecma_utils", "ecma_utils",
"ecma_visit", "ecma_visit",
"__plugin_transform_host",
"__plugin_transform_host_schema_v1",
"plugin_transform_host_native_filesystem_cache",
] } ] }
# Dependencies for the native, non-wasm32 build. # Dependencies for the native, non-wasm32 build.
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
lightningcss-napi = { workspace = true } lightningcss-napi = { workspace = true }
swc_plugin_backend_wasmtime = { workspace = true, optional = true }
lightningcss = { workspace = true } lightningcss = { workspace = true }
swc_plugin_backend_wasmtime = { workspace = true }
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
turbo-rcstr = { workspace = true, features = ["napi"] } turbo-rcstr = { workspace = true, features = ["napi"] }
turbo-tasks = { workspace = true } turbo-tasks = { workspace = true }
...@@ -132,7 +113,6 @@ turbopack-core = { workspace = true } ...@@ -132,7 +113,6 @@ turbopack-core = { workspace = true }
turbopack-ecmascript-hmr-protocol = { workspace = true } turbopack-ecmascript-hmr-protocol = { workspace = true }
turbopack-trace-utils = { workspace = true } turbopack-trace-utils = { workspace = true }
turbopack-trace-server = { workspace = true } turbopack-trace-server = { workspace = true }
turbopack-ecmascript-plugins = { workspace = true, optional = true }
turbopack-node = { workspace = true, default-features = false, features = ["worker_pool"] } turbopack-node = { workspace = true, default-features = false, features = ["worker_pool"] }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
......
...@@ -31,6 +31,7 @@ use std::{ ...@@ -31,6 +31,7 @@ use std::{
fs::read_to_string, fs::read_to_string,
panic::{AssertUnwindSafe, catch_unwind}, panic::{AssertUnwindSafe, catch_unwind},
rc::Rc, rc::Rc,
sync::Arc,
}; };
use anyhow::{Context as _, anyhow, bail}; use anyhow::{Context as _, anyhow, bail};
...@@ -41,10 +42,11 @@ use once_cell::sync::Lazy; ...@@ -41,10 +42,11 @@ use once_cell::sync::Lazy;
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use swc_core::{ use swc_core::{
atoms::Atom, atoms::Atom,
base::{Compiler, TransformOutput, try_with_handler}, base::{Compiler, TransformOutput, config::RuntimeOptions, try_with_handler},
common::{FileName, GLOBALS, Mark, comments::SingleThreadedComments, errors::ColorConfig}, common::{FileName, GLOBALS, Mark, comments::SingleThreadedComments, errors::ColorConfig},
ecma::ast::noop_pass, ecma::ast::noop_pass,
}; };
use swc_plugin_backend_wasmtime::WasmtimeRuntime;
use crate::{complete_output, get_compiler, util::MapErr}; use crate::{complete_output, get_compiler, util::MapErr};
...@@ -128,15 +130,8 @@ impl Task for TransformTask { ...@@ -128,15 +130,8 @@ impl Task for TransformTask {
let unresolved_mark = Mark::new(); let unresolved_mark = Mark::new();
let mut options = options.patch(&fm); let mut options = options.patch(&fm);
options.swc.unresolved_mark = Some(unresolved_mark); options.swc.unresolved_mark = Some(unresolved_mark);
options.swc.runtime_options =
#[cfg(feature = "plugin")] RuntimeOptions::default().plugin_runtime(Arc::new(WasmtimeRuntime));
{
options.swc.runtime_options =
swc_core::base::config::RuntimeOptions::default()
.plugin_runtime(std::sync::Arc::new(
swc_plugin_backend_wasmtime::WasmtimeRuntime,
));
}
let cm = self.c.cm.clone(); let cm = self.c.cm.clone();
let file = fm.clone(); let file = fm.clone();
......
...@@ -8,11 +8,9 @@ ...@@ -8,11 +8,9 @@
"scripts": { "scripts": {
"build-native-auto": "node maybe-build-native.mjs", "build-native-auto": "node maybe-build-native.mjs",
"clean": "node ../../scripts/rm.mjs native", "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": "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 plugin,image-extended,tracing/release_max_level_trace --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 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 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-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-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-sccache": "node ../../scripts/build-sccache.js",
"build-wasm": "wasm-pack build ../../crates/wasm --scope=next", "build-wasm": "wasm-pack build ../../crates/wasm --scope=next",
......
...@@ -46,16 +46,6 @@ ...@@ -46,16 +46,6 @@
"inputs": ["../../target/.rust-fingerprint"], "inputs": ["../../target/.rust-fingerprint"],
"outputs": ["native/*.node", "native/index.d.ts"], "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": { "build-wasm": {
"dependsOn": ["rust-fingerprint"], "dependsOn": ["rust-fingerprint"],
"inputs": ["../../target/.rust-fingerprint"], "inputs": ["../../target/.rust-fingerprint"],
......
...@@ -10,18 +10,7 @@ autobenches = false ...@@ -10,18 +10,7 @@ autobenches = false
bench = false bench = false
[features] [features]
default = ["swc_ecma_transform_plugin"]
transform_emotion = [] 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] [lints]
workspace = true workspace = true
...@@ -45,8 +34,14 @@ turbopack-ecmascript = { workspace = true } ...@@ -45,8 +34,14 @@ turbopack-ecmascript = { workspace = true }
styled_components = { workspace = true } styled_components = { workspace = true }
styled_jsx = { workspace = true } styled_jsx = { workspace = true }
swc_core = { workspace = true, features = ["ecma_ast", "ecma_visit", "common"] } swc_core = { workspace = true, features = [
swc_plugin_backend_wasmtime = { workspace = true, optional = true } "ecma_ast",
"ecma_visit",
"common",
"__plugin_transform_host",
"__plugin_transform_host_schema_v1",
] }
swc_plugin_backend_wasmtime = { workspace = true }
swc_emotion = { workspace = true } swc_emotion = { workspace = true }
swc_relay = { 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