Unverified Commit b80c3789 authored by Maia Teegarden's avatar Maia Teegarden Committed by GitHub

Add/wasm build (#31470)

parent af6e9e2d
...@@ -26,6 +26,6 @@ packages/create-next-app/templates/** ...@@ -26,6 +26,6 @@ packages/create-next-app/templates/**
test/integration/eslint/** test/integration/eslint/**
test/development/basic/legacy-decorators/**/* test/development/basic/legacy-decorators/**/*
test-timings.json test-timings.json
packages/next/build/swc/tests/** packages/next/build/swc/crates/**
bench/nested-deps/pages/** bench/nested-deps/pages/**
bench/nested-deps/components/** bench/nested-deps/components/**
...@@ -1129,3 +1129,73 @@ jobs: ...@@ -1129,3 +1129,73 @@ jobs:
with: with:
name: next-swc-binaries name: next-swc-binaries
path: packages/next/native/next-swc.android-arm64.node path: packages/next/native/next-swc.android-arm64.node
build-wasm:
needs: build
strategy:
matrix:
target: [web, nodejs]
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
key: ${{ github.sha }}
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 14
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2021-08-12
override: true
target: wasm32-unknown-unknown
- name: Cache
uses: actions/cache@v2
with:
path: |
~/.cargo/
**/target/
key: ${{ runner.os }}-publish-integration
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build
run: (wasm-pack build packages/next/build/swc/crates/wasm --release --scope=next --target ${{ matrix.target }})
- name: Add target to folder name
run: mv packages/next/build/swc/crates/wasm/pkg packages/next/build/swc/crates/wasm/pkg-${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: wasm-binaries
path: packages/next/build/swc/crates/wasm/pkg-*
- run: ls packages/next/build/swc/crates/wasm
# - name: Publish
# run: |
# echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
# (cd crates/wasm/pkg && npm publish --access public)
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
practice:
needs: build-wasm
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v2
with:
name: wasm-binaries
path: packages/next/build/swc/crates/wasm
- run: ls packages/next/build/swc/crates/wasm
...@@ -10,7 +10,7 @@ packages/react-dev-overlay/lib/** ...@@ -10,7 +10,7 @@ packages/react-dev-overlay/lib/**
**/__tmp__/** **/__tmp__/**
lerna.json lerna.json
.github/actions/next-stats-action/.work .github/actions/next-stats-action/.work
packages/next/build/swc/tests/**/* packages/next/build/swc/crates/**/*
packages/next-codemod/transforms/__testfixtures__/**/* packages/next-codemod/transforms/__testfixtures__/**/*
packages/next-codemod/transforms/__tests__/**/* packages/next-codemod/transforms/__tests__/**/*
packages/next-codemod/**/*.js packages/next-codemod/**/*.js
......
**/.next/** **/.next/**
**/_next/** **/_next/**
**/dist/** **/dist/**
packages/next/build/swc/tests/** packages/next/build/swc/crates/**
packages/next/compiled/**/* packages/next/compiled/**/*
packages/next/bundles/webpack/packages/*.runtime.js packages/next/bundles/webpack/packages/*.runtime.js
lerna.json lerna.json
......
...@@ -177,6 +177,12 @@ version = "0.2.2" ...@@ -177,6 +177,12 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7" checksum = "b4ae4235e6dac0694637c763029ecea1a2ec9e4e06ec2729bd21ba4d9c863eb7"
[[package]]
name = "bumpalo"
version = "3.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
version = "1.4.3" version = "1.4.3"
...@@ -223,6 +229,25 @@ dependencies = [ ...@@ -223,6 +229,25 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "cloudabi"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467"
dependencies = [
"bitflags",
]
[[package]]
name = "console_error_panic_hook"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen",
]
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.1" version = "0.2.1"
...@@ -571,6 +596,15 @@ version = "0.4.8" ...@@ -571,6 +596,15 @@ version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "js-sys"
version = "0.3.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc15e39392125075f60c95ba416f5381ff6c3a948ff02ab12464715adf56c821"
dependencies = [
"wasm-bindgen",
]
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
...@@ -754,27 +788,16 @@ checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" ...@@ -754,27 +788,16 @@ checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
name = "next-swc" name = "next-swc"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"anyhow",
"backtrace",
"chrono", "chrono",
"easy-error", "easy-error",
"either", "either",
"fxhash", "fxhash",
"napi",
"napi-build",
"napi-derive",
"once_cell",
"path-clean",
"pathdiff", "pathdiff",
"regex",
"retain_mut",
"rustc-hash",
"serde", "serde",
"serde_json", "serde_json",
"styled_components", "styled_components",
"swc", "swc",
"swc_atoms", "swc_atoms",
"swc_bundler",
"swc_common", "swc_common",
"swc_css", "swc_css",
"swc_ecma_loader", "swc_ecma_loader",
...@@ -788,6 +811,29 @@ dependencies = [ ...@@ -788,6 +811,29 @@ dependencies = [
"walkdir", "walkdir",
] ]
[[package]]
name = "next-swc-napi"
version = "0.0.0"
dependencies = [
"anyhow",
"backtrace",
"fxhash",
"napi",
"napi-build",
"napi-derive",
"next-swc",
"once_cell",
"serde",
"serde_json",
"swc",
"swc_atoms",
"swc_bundler",
"swc_common",
"swc_ecma_loader",
"swc_ecmascript",
"swc_node_base",
]
[[package]] [[package]]
name = "normpath" name = "normpath"
version = "0.2.0" version = "0.2.0"
...@@ -898,13 +944,13 @@ dependencies = [ ...@@ -898,13 +944,13 @@ dependencies = [
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.11.2" version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
dependencies = [ dependencies = [
"instant", "instant",
"lock_api 0.4.5", "lock_api 0.4.5",
"parking_lot_core 0.8.5", "parking_lot_core 0.8.0",
] ]
[[package]] [[package]]
...@@ -922,14 +968,15 @@ dependencies = [ ...@@ -922,14 +968,15 @@ dependencies = [
[[package]] [[package]]
name = "parking_lot_core" name = "parking_lot_core"
version = "0.8.5" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 0.1.10",
"cloudabi 0.1.0",
"instant", "instant",
"libc", "libc",
"redox_syscall", "redox_syscall 0.1.57",
"smallvec 1.7.0", "smallvec 1.7.0",
"winapi", "winapi",
] ]
...@@ -1262,7 +1309,7 @@ version = "0.1.3" ...@@ -1262,7 +1309,7 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
dependencies = [ dependencies = [
"cloudabi", "cloudabi 0.0.3",
"fuchsia-cprng", "fuchsia-cprng",
"libc", "libc",
"rand_core 0.4.2", "rand_core 0.4.2",
...@@ -1332,6 +1379,12 @@ dependencies = [ ...@@ -1332,6 +1379,12 @@ dependencies = [
"rand_core 0.3.1", "rand_core 0.3.1",
] ]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.10" version = "0.2.10"
...@@ -1600,7 +1653,7 @@ checksum = "923f0f39b6267d37d23ce71ae7235602134b250ace715dd2c90421998ddac0c6" ...@@ -1600,7 +1653,7 @@ checksum = "923f0f39b6267d37d23ce71ae7235602134b250ace715dd2c90421998ddac0c6"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"new_debug_unreachable", "new_debug_unreachable",
"parking_lot 0.11.2", "parking_lot 0.11.1",
"phf_shared", "phf_shared",
"precomputed-hash", "precomputed-hash",
"serde", "serde",
...@@ -1715,7 +1768,7 @@ dependencies = [ ...@@ -1715,7 +1768,7 @@ dependencies = [
"indexmap", "indexmap",
"is-macro", "is-macro",
"once_cell", "once_cell",
"parking_lot 0.11.2", "parking_lot 0.11.1",
"petgraph", "petgraph",
"radix_fmt", "radix_fmt",
"rayon", "rayon",
...@@ -2393,7 +2446,7 @@ dependencies = [ ...@@ -2393,7 +2446,7 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"libc", "libc",
"rand 0.8.4", "rand 0.8.4",
"redox_syscall", "redox_syscall 0.2.10",
"remove_dir_all", "remove_dir_all",
"winapi", "winapi",
] ]
...@@ -2629,6 +2682,104 @@ version = "0.10.2+wasi-snapshot-preview1" ...@@ -2629,6 +2682,104 @@ version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm"
version = "0.0.0"
dependencies = [
"anyhow",
"console_error_panic_hook",
"next-swc",
"once_cell",
"parking_lot_core 0.8.0",
"path-clean",
"serde",
"serde_json",
"swc",
"swc_common",
"swc_ecmascript",
"tracing",
"wasm-bindgen",
"wasm-bindgen-futures",
]
[[package]]
name = "wasm-bindgen"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fe8f61dba8e5d645a4d8132dc7a0a66861ed5e1045d2c0ed940fab33bac0fbe"
dependencies = [
"cfg-if 1.0.0",
"serde",
"serde_json",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73157efb9af26fb564bb59a009afd1c7c334a44db171d280690d0c3faaec3468"
dependencies = [
"cfg-if 1.0.0",
"js-sys",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef9aa01d36cda046f797c57959ff5f3c615c9cc63997a8d545831ec7976819b"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96eb45c1b2ee33545a813a92dbb53856418bf7eb54ab34f7f7ff1448a5b3735d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7148f4696fb4960a346eaa60bbfb42a1ac4ebba21f750f75fc1375b098d5ffa"
[[package]]
name = "web-sys"
version = "0.3.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59fe19d70f5dacc03f6e46777213facae5ac3801575d56ca6cbd4c93dcd12310"
dependencies = [
"js-sys",
"wasm-bindgen",
]
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"
......
[package] [workspace]
edition = "2018"
name = "next-swc"
version = "0.0.0"
[lib] members = [
crate-type = ["cdylib", "rlib"] "crates/core",
"crates/napi",
[dependencies] "crates/wasm"
anyhow = "1.0" ]
backtrace = "0.3"
chrono = "0.4"
easy-error = "1.0.0"
either = "1"
fxhash = "0.2.1"
napi = {version = "1", features = ["serde-json"]}
napi-derive = "1"
once_cell = "1.8.0"
path-clean = "0.1"
pathdiff = "0.2.0"
regex = "1.5"
retain_mut = "0.1.3"
rustc-hash = "1.1.0"
serde = "1"
serde_json = "1"
styled_components = "0.2.0"
swc = "0.85.0"
swc_atoms = "0.2.7"
swc_bundler = { version = "0.82.0", features = ["concurrent"] }
swc_common = {version = "0.14.2", features = ["concurrent", "sourcemap"]}
swc_css = "0.31.0"
swc_ecma_loader = { version = "0.24.2", features = ["node", "lru"] }
swc_ecma_preset_env = "0.66.0"
swc_ecmascript = { version = "0.87.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1"
swc_stylis = "0.28.0"
tracing = {version = "0.1.28", features = ["release_max_level_off"]}
[build-dependencies]
napi-build = "1"
[dev-dependencies]
swc_ecma_transforms_testing = "0.45.0"
testing = "0.15.1"
walkdir = "2.3.2"
[profile.release] [profile.release]
lto = true lto = true
\ No newline at end of file
[package]
edition = "2018"
name = "next-swc"
version = "0.0.0"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
chrono = "0.4"
easy-error = "1.0.0"
either = "1"
fxhash = "0.2.1"
pathdiff = "0.2.0"
serde = "1"
serde_json = "1"
styled_components = "0.2.0"
swc = "0.85.0"
swc_atoms = "0.2.7"
swc_common = {version = "0.14.2", features = ["concurrent", "sourcemap"]}
swc_css = "0.31.0"
swc_ecma_loader = { version = "0.24.2", features = ["node", "lru"] }
swc_ecma_preset_env = "0.66.0"
swc_ecmascript = { version = "0.87.0", features = ["codegen", "minifier", "optimization", "parser", "react", "transforms", "typescript", "utils", "visit"] }
swc_node_base = "0.5.1"
swc_stylis = "0.28.0"
tracing = {version = "0.1.28", features = ["release_max_level_off"]}
[dev-dependencies]
swc_ecma_transforms_testing = "0.45.0"
testing = "0.15.1"
walkdir = "2.3.2"
...@@ -29,22 +29,15 @@ DEALINGS IN THE SOFTWARE. ...@@ -29,22 +29,15 @@ DEALINGS IN THE SOFTWARE.
#![recursion_limit = "2048"] #![recursion_limit = "2048"]
//#![deny(clippy::all)] //#![deny(clippy::all)]
#[macro_use]
extern crate napi_derive;
/// Explicit extern crate to use allocator.
extern crate swc_node_base;
use auto_cjs::contains_cjs; use auto_cjs::contains_cjs;
use backtrace::Backtrace;
use either::Either; use either::Either;
use napi::{CallContext, Env, JsObject, JsUndefined};
use serde::Deserialize; use serde::Deserialize;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use std::{env, panic::set_hook, path::PathBuf, sync::Arc}; use std::{path::PathBuf, sync::Arc};
use swc::{config::ModuleConfig, Compiler, TransformOutput}; use swc::config::ModuleConfig;
use swc_common::SourceFile; use swc_common::SourceFile;
use swc_common::{self, chain, pass::Optional, sync::Lazy, FilePathMapping, SourceMap}; use swc_common::{self, chain, pass::Optional};
use swc_ecmascript::ast::EsVersion; use swc_ecmascript::ast::EsVersion;
use swc_ecmascript::transforms::pass::noop; use swc_ecmascript::transforms::pass::noop;
use swc_ecmascript::{ use swc_ecmascript::{
...@@ -54,17 +47,13 @@ use swc_ecmascript::{ ...@@ -54,17 +47,13 @@ use swc_ecmascript::{
pub mod amp_attributes; pub mod amp_attributes;
mod auto_cjs; mod auto_cjs;
mod bundle;
pub mod hook_optimizer; pub mod hook_optimizer;
pub mod minify;
pub mod next_dynamic; pub mod next_dynamic;
pub mod next_ssg; pub mod next_ssg;
pub mod page_config; pub mod page_config;
pub mod remove_console; pub mod remove_console;
pub mod styled_jsx; pub mod styled_jsx;
mod top_level_binding_collector; mod top_level_binding_collector;
mod transform;
mod util;
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
...@@ -127,46 +116,6 @@ pub fn custom_before_pass(file: Arc<SourceFile>, opts: &TransformOptions) -> imp ...@@ -127,46 +116,6 @@ pub fn custom_before_pass(file: Arc<SourceFile>, opts: &TransformOptions) -> imp
) )
} }
static COMPILER: Lazy<Arc<Compiler>> = Lazy::new(|| {
let cm = Arc::new(SourceMap::new(FilePathMapping::empty()));
Arc::new(Compiler::new(cm.clone()))
});
#[module_exports]
fn init(mut exports: JsObject) -> napi::Result<()> {
if cfg!(debug_assertions) || env::var("SWC_DEBUG").unwrap_or_default() == "1" {
set_hook(Box::new(|panic_info| {
let backtrace = Backtrace::new();
println!("Panic: {:?}\nBacktrace: {:?}", panic_info, backtrace);
}));
}
exports.create_named_method("bundle", bundle::bundle)?;
exports.create_named_method("transform", transform::transform)?;
exports.create_named_method("transformSync", transform::transform_sync)?;
exports.create_named_method("minify", minify::minify)?;
exports.create_named_method("minifySync", minify::minify_sync)?;
Ok(())
}
fn get_compiler(_ctx: &CallContext) -> Arc<Compiler> {
COMPILER.clone()
}
#[js_function]
fn construct_compiler(ctx: CallContext) -> napi::Result<JsUndefined> {
// TODO: Assign swc::Compiler
ctx.env.get_undefined()
}
pub fn complete_output(env: &Env, output: TransformOutput) -> napi::Result<JsObject> {
env.to_js_value(&output)?.coerce_to_object()
}
impl TransformOptions { impl TransformOptions {
pub fn patch(mut self, fm: &SourceFile) -> Self { pub fn patch(mut self, fm: &SourceFile) -> Self {
self.swc.swcrc = false; self.swc.swcrc = false;
...@@ -189,5 +138,3 @@ impl TransformOptions { ...@@ -189,5 +138,3 @@ impl TransformOptions {
self self
} }
} }
pub type ArcCompiler = Arc<Compiler>;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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