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
3 changes: 1 addition & 2 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/setup-nextjs-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 0 additions & 5 deletions crates/next-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
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;
Expand All @@ -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]
Expand All @@ -47,7 +34,6 @@ impl DummyResolveOrigin {
}
}

#[cfg(feature = "plugin")]
#[turbo_tasks::value_impl]
impl ResolveOrigin for DummyResolveOrigin {
#[turbo_tasks::function]
Expand All @@ -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)],
Expand Down
18 changes: 1 addition & 17 deletions crates/next-custom-transforms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }
Expand All @@ -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 }
28 changes: 4 additions & 24 deletions crates/next-napi-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
Expand Down Expand Up @@ -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 }
Expand All @@ -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]
Expand Down
15 changes: 5 additions & 10 deletions crates/next-napi-bindings/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use std::{
fs::read_to_string,
panic::{AssertUnwindSafe, catch_unwind},
rc::Rc,
sync::Arc,
};

use anyhow::{Context as _, anyhow, bail};
Expand All @@ -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};

Expand Down Expand Up @@ -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();
Expand Down
8 changes: 3 additions & 5 deletions packages/next-swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 0 additions & 10 deletions packages/next-swc/turbo.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
21 changes: 8 additions & 13 deletions turbopack/crates/turbopack-ecmascript-plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }

Loading
Loading