refactor(bindings): Use separate workspace for bindings (#5506)

This commit is contained in:
OJ Kwon 2022-08-15 23:01:49 -07:00 committed by GitHub
parent a1cb679675
commit 496346ac04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 10897 additions and 1531 deletions

View File

@ -74,7 +74,7 @@ jobs:
yarn
- name: Run benchmark
run: cargo bench --workspace --exclude swc_plugin --exclude binding_core_wasm --exclude swc_cli --exclude binding_core_node --features plugin_transform_schema_vtest -- --output-format bencher | tee output.txt
run: cargo bench --workspace --exclude swc_plugin --features plugin_transform_schema_vtest -- --output-format bencher | tee output.txt
- name: Download previous benchmark results
run: mkdir raw-data && curl -o raw-data/benchmark-data.json https://raw.githubusercontent.com/swc-project/raw-data/gh-pages/benchmark-data.json

View File

@ -96,9 +96,7 @@ jobs:
os: ubuntu-latest
- crate: better_scoped_tls
os: ubuntu-latest
- crate: binding_core_node
os: ubuntu-latest
- crate: binding_core_wasm
- crate: binding_macros
os: ubuntu-latest
- crate: dbg-swc
os: ubuntu-latest
@ -108,8 +106,6 @@ jobs:
os: ubuntu-latest
- crate: jsdoc
os: ubuntu-latest
- crate: node_macro_deps
os: ubuntu-latest
- crate: preset_env_base
os: ubuntu-latest
- crate: string_enum
@ -128,13 +124,6 @@ jobs:
cargo hack check --feature-powerset --no-dev-deps
- crate: swc_cached
os: ubuntu-latest
- crate: swc_cli
os: ubuntu-latest
check: |
cargo check
cargo check --features plugin
- crate: swc_cli
os: windows-latest
- crate: swc_common
os: ubuntu-latest
check: |
@ -145,6 +134,8 @@ jobs:
os: ubuntu-latest
- crate: swc_config_macro
os: ubuntu-latest
- crate: swc_core
os: ubuntu-latest
- crate: swc_css
os: ubuntu-latest
- crate: swc_css_ast
@ -283,22 +274,6 @@ jobs:
os: ubuntu-latest
- crate: swc_html_visit
os: ubuntu-latest
- crate: swc_xml
os: ubuntu-latest
- crate: swc_xml_ast
os: ubuntu-latest
- crate: swc_xml_codegen
os: ubuntu-latest
- crate: swc_xml_codegen
os: windows-latest
- crate: swc_xml_codegen_macros
os: ubuntu-latest
- crate: swc_xml_parser
os: ubuntu-latest
- crate: swc_xml_parser
os: windows-latest
- crate: swc_xml_visit
os: ubuntu-latest
- crate: swc_macros_common
os: ubuntu-latest
- crate: swc_node_base
@ -340,6 +315,18 @@ jobs:
os: ubuntu-latest
- crate: swc_visit_macros
os: ubuntu-latest
- crate: swc_xml
os: ubuntu-latest
- crate: swc_xml_ast
os: ubuntu-latest
- crate: swc_xml_codegen
os: ubuntu-latest
- crate: swc_xml_codegen_macros
os: ubuntu-latest
- crate: swc_xml_parser
os: ubuntu-latest
- crate: swc_xml_visit
os: ubuntu-latest
- crate: testing
os: ubuntu-latest
- crate: testing_macros
@ -416,7 +403,7 @@ jobs:
swc-exec-cache-${{ matrix.settings.crate }}-${{ runner.os }}
- name: Run cargo test
if: matrix.settings.crate != 'swc_plugin_runner' && matrix.settings.crate != 'swc_ecma_minifier' && matrix.settings.crate != 'swc_core' && matrix.settings.crate != 'swc_ecma_quote'
if: matrix.settings.crate != 'swc_plugin_runner' && matrix.settings.crate != 'swc_ecma_minifier' && matrix.settings.crate != 'swc_core' && matrix.settings.crate != 'swc_ecma_quote' && matrix.settings.crate != 'swc_cli' && matrix.settings.crate != 'binding_core_wasm'
run: |
cargo test --color always -p ${{ matrix.settings.crate }}
@ -425,6 +412,16 @@ jobs:
run: |
cargo test --color always -p swc_core --features quote --features common --features utils
- name: Run cargo test (binding_core_wasm)
if: matrix.settings.crate == 'binding_core_wasm'
run: |
cargo test --color always --manifest-path ./bindings/binding_core_wasm/Cargo.toml
- name: Run cargo test (cli)
if: matrix.settings.crate == 'swc_cli'
run: |
cargo test --color always --manifest-path ./bindings/swc_cli/Cargo.toml --features plugin
- name: Run cargo test (plugin)
if: matrix.settings.crate == 'swc_plugin_runner'
run: |

View File

@ -22,7 +22,7 @@ jobs:
profile: minimal
- name: Create rustdoc
run: cargo doc --all --exclude swc_cli --exclude binding_core_node --exclude binding_core_wasm --features plugin_transform --features loader --features utils --features quote --features visit --features transforms --features __testing_transform
run: cargo doc --all --features plugin_transform --features loader --features utils --features quote --features visit --features transforms --features __testing_transform
- name: Create CNAME
run: |

View File

@ -96,6 +96,9 @@ jobs:
# Avoid no space left on device, copyfile
cargo clean
cargo clean --manifest-path ./bindings/binding_core_node/Cargo.toml
cargo clean --manifest-path ./bindings/binding_core_wasm/Cargo.toml
cargo clean --manifest-path ./bindings/swc_cli/Cargo.toml
yarn global add @swc/cli@0.1.56
yarn link

View File

@ -26,23 +26,23 @@ jobs:
- host: macos-latest
target: x86_64-apple-darwin
build: |
cargo build -p swc_cli --release --features plugin
cp ./target/release/swc .
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin
cp ./bindings/swc_cli/target/release/swc .
chmod +x ./swc
yarn build
strip -x *.node
- host: windows-latest
build: |
yarn build
cargo build -p swc_cli --release --features plugin
cp target/release/swc .
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin
cp ./bindings/swc_cli/target/release/swc .
target: x86_64-pc-windows-msvc
- host: windows-latest
build: |
export DISABLE_PLUGIN_E2E_TESTS=true
export CARGO_PROFILE_RELEASE_LTO=false
cargo build -p swc_cli --release --target i686-pc-windows-msvc
cp target/i686-pc-windows-msvc/release/swc .
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --target i686-pc-windows-msvc
cp bindings/swc_cli/target/i686-pc-windows-msvc/release/swc .
yarn build --target i686-pc-windows-msvc --cargo-flags="--no-default-features" --features swc_v1
yarn test
target: i686-pc-windows-msvc
@ -51,9 +51,9 @@ jobs:
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: >-
set -e &&
RUSTFLAGS='-C target-feature=+sse2 -Z new-llvm-pass-manager=no' cargo build -p swc_cli --release --features plugin &&
rm -rf target/x86_64-unknown-linux-gnu/release/.cargo-lock &&
cp target/x86_64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
RUSTFLAGS='-C target-feature=+sse2 -Z new-llvm-pass-manager=no' cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin &&
rm -rf bindings/swc_cli/target/target/x86_64-unknown-linux-gnu/release/.cargo-lock &&
cp bindings/swc_cli/target/x86_64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
yarn build --target x86_64-unknown-linux-gnu &&
strip swc.linux-x64-gnu.node
- host: ubuntu-latest
@ -63,9 +63,9 @@ jobs:
build: >-
set -e &&
export CARGO_PROFILE_RELEASE_LTO=false &&
RUSTFLAGS='-C target-feature=+sse2 -Z new-llvm-pass-manager=no' cargo build -p swc_cli --release --features plugin &&
RUSTFLAGS='-C target-feature=+sse2 -Z new-llvm-pass-manager=no' cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin &&
rm -rf target/release/.cargo-lock &&
cp target/release/swc . && chmod +x ./swc &&
cp bindings/swc_cli/target/release/swc . && chmod +x ./swc &&
RUSTFLAGS='-C target-feature=+sse2 -C target-feature=-crt-static -Z new-llvm-pass-manager=no' yarn build &&
llvm-strip -x swc.linux-x64-musl.node
- host: macos-latest
@ -76,8 +76,8 @@ jobs:
export CXX=$(xcrun -f clang++);
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
cargo build -p swc_cli --release --features plugin --target=aarch64-apple-darwin
cp ./target/aarch64-apple-darwin/release/swc .
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target=aarch64-apple-darwin
cp ./bindings/swc_cli/target/aarch64-apple-darwin/release/swc .
chmod +x ./swc
yarn build --target=aarch64-apple-darwin
strip -x *.node
@ -87,8 +87,8 @@ jobs:
build: >-
set -e &&
rustup target add aarch64-unknown-linux-gnu &&
RUSTFLAGS='-Z new-llvm-pass-manager=no' cargo build -p swc_cli --release --features plugin --target aarch64-unknown-linux-gnu &&
cp ./target/aarch64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
RUSTFLAGS='-Z new-llvm-pass-manager=no' cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-unknown-linux-gnu &&
cp ./bindings/swc_cli/target/aarch64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
export CC_aarch64_unknown_linux_gnu=/usr/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc &&
yarn build --target aarch64-unknown-linux-gnu &&
llvm-strip -x swc.linux-arm64-gnu.node
@ -99,8 +99,8 @@ jobs:
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
build: |
export DISABLE_PLUGIN_E2E_TESTS=true
cargo build -p swc_cli --release --target=armv7-unknown-linux-gnueabihf
cp ./target/armv7-unknown-linux-gnueabihf/release/swc .
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --target=armv7-unknown-linux-gnueabihf
cp ./bindings/swc_cli/target/armv7-unknown-linux-gnueabihf/release/swc .
chmod +x ./swc
yarn build --target=armv7-unknown-linux-gnueabihf --cargo-flags='--no-default-features --features swc_v1'
arm-linux-gnueabihf-strip swc.linux-arm-gnueabihf.node
@ -116,8 +116,8 @@ jobs:
touch "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/${CLANG_VERSION}/lib/linux/aarch64/libgcc.a"
chmod 777 "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/${CLANG_VERSION}/lib/linux/aarch64/libgcc.a"
echo "INPUT(-lunwind)" > "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/${CLANG_VERSION}/lib/linux/aarch64/libgcc.a"
cargo build -p swc_cli --release --features plugin --target aarch64-linux-android
cp ./target/aarch64-linux-android/release/swc .
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-linux-android
cp ./bindings/swc_cli/target/aarch64-linux-android/release/swc .
chmod +x ./swc
yarn build --target aarch64-linux-android
${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
@ -134,8 +134,8 @@ jobs:
touch "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/${CLANG_VERSION}/lib/linux/arm/libgcc.a"
chmod 777 "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/${CLANG_VERSION}/lib/linux/arm/libgcc.a"
echo "INPUT(-lunwind)" > "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/${CLANG_VERSION}/lib/linux/arm/libgcc.a"
cargo build -p swc_cli --release --target armv7-linux-androideabi
cp ./target/armv7-linux-androideabi/release/swc .
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --target armv7-linux-androideabi
cp ./bindings/swc_cli/target/armv7-linux-androideabi/release/swc .
chmod +x ./swc
yarn build --target armv7-linux-androideabi --cargo-flags='--no-default-features --features swc_v1'
${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
@ -146,9 +146,9 @@ jobs:
build: >-
rustup toolchain install $(cat ./rust-toolchain) &&
rustup target add aarch64-unknown-linux-musl &&
RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-lgcc -Z new-llvm-pass-manager=no' cargo build -p swc_cli --release --features plugin --target aarch64-unknown-linux-musl &&
RUSTFLAGS='-C target-feature=+crt-static -C link-arg=-lgcc -Z new-llvm-pass-manager=no' cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-unknown-linux-musl &&
rm -rf target/release/.cargo-lock &&
cp target/aarch64-unknown-linux-musl/release/swc . && chmod +x ./swc &&
cp bindings/swc_cli/target/aarch64-unknown-linux-musl/release/swc . && chmod +x ./swc &&
env RUSTFLAGS='-C target-feature=-crt-static -Z new-llvm-pass-manager=no' yarn build --target=aarch64-unknown-linux-musl &&
/aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip swc.linux-arm64-musl.node
- host: windows-latest
@ -158,8 +158,8 @@ jobs:
export DISABLE_PLUGIN_E2E_TESTS=true
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=256
export CARGO_PROFILE_RELEASE_LTO=false
cargo build -p swc_cli --release --target aarch64-pc-windows-msvc
cp target/aarch64-pc-windows-msvc/release/swc.exe .
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --target aarch64-pc-windows-msvc
cp bindings/swc_cli/target/aarch64-pc-windows-msvc/release/swc.exe .
yarn build --target aarch64-pc-windows-msvc --cargo-flags='--no-default-features --features swc_v1'
name: stable - ${{ matrix.settings.target }} - node@16
runs-on: ${{ matrix.settings.host }}
@ -329,8 +329,8 @@ jobs:
freebsd-version
yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000
yarn build --cargo-flags="--no-default-features" --features "swc_v1"
cargo build -p swc_cli --release --features plugin
cp ./target/release/swc .
cargo build --manifest-path ./bindings/swc_cli/Cargo.toml --release --features plugin
cp ./bindings/swc_cli/target/release/swc .
yarn test
rm -rf node_modules
rm -rf target

View File

@ -39,7 +39,7 @@ jobs:
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build
working-directory: crates/binding_core_wasm
working-directory: bindings/binding_core_wasm
run: |
wasm-pack build --out-name wasm --release --scope=swc --target nodejs
sed -i -e 's/"name": "@swc\/binding_core_wasm"/"name": "@swc\/wasm"/g' pkg/package.json
@ -47,7 +47,7 @@ jobs:
- name: Publish
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
(cd crates/binding_core_wasm/pkg && npm publish --access public)
(cd bindings/binding_core_wasm/pkg && npm publish --access public)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
@ -80,7 +80,7 @@ jobs:
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build
working-directory: crates/binding_core_wasm
working-directory: bindings/binding_core_wasm
run: |
wasm-pack build --out-name wasm-web --release --scope=swc --target web
sed -i -e 's/"name": "@swc\/binding_core_wasm"/"name": "@swc\/wasm-web"/g' pkg/package.json
@ -88,7 +88,7 @@ jobs:
- name: Publish
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
(cd crates/binding_core_wasm/pkg && npm publish --access public)
(cd bindings/binding_core_wasm/pkg && npm publish --access public)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

View File

@ -46,9 +46,9 @@ jobs:
- name: Build
run: |
(cd crates/binding_core_wasm && yarn)
(cd crates/binding_core_wasm && ./scripts/build.sh --features plugin)
(cd bindings/binding_core_wasm && yarn)
(cd bindings/binding_core_wasm && ./scripts/build.sh --features plugin)
- name: Test
run: |
(cd crates/binding_core_wasm && ./scripts/test.sh)
(cd bindings/binding_core_wasm && ./scripts/test.sh)

1842
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -3,10 +3,7 @@ members = [
"crates/swc_core",
"crates/dbg-swc",
"crates/jsdoc",
"crates/binding_core_node",
"crates/binding_core_wasm",
"crates/binding_macros",
"crates/swc_cli",
"crates/swc_css",
"crates/swc_css_lints",
"crates/swc_css_prefixer",

6
bindings/README.md Normal file
View File

@ -0,0 +1,6 @@
## SWC bindings
This folder contains actual bindings binary SWC will build for the supported platforms (`@swc/core`, `swc_cli`, `@swc/wasm`).
All the bindings binary uses publicly published `swc_core` SDK to build deterministic host binary for the specific changes, in result Cargo's workspace gets confused to select dependency versions if it belongs to the workspace contains unpublished packages. To avoid those problems, these bindings are not being built as part of the workspace.

3775
bindings/binding_core_node/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
[workspace]
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
build = "build.rs"
@ -56,3 +57,24 @@ swc_core = { version = "0.7.11", features = [
"base_node",
"base_concurrent",
] }
[profile.release]
# lto = true
# We use CARGO_PROFILE_RELEASE_LTO for production builds
# lto = "fat"
# debug = true
# opt-level = 'z'
[profile.bench]
debug = true
lto = true
# Without this, printing diff consumes more than a minute.
[profile.dev.package.pretty_assertions]
opt-level = 3
[profile.test.package.pretty_assertions]
opt-level = 3

3028
bindings/binding_core_wasm/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
[workspace]
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
description = "wasm module for swc"

View File

@ -3,14 +3,14 @@ authors = ["강동윤 <kdy1997.dev@gmail.com>"]
edition = "2021"
exclude = ["artifacts.json", "index.node"]
license = "Apache-2.0"
name = "node_macro_deps"
name = "node_macro_deps"
publish = false
version = "0.1.0"
[lib]
bench = false
bench = false
proc-macro = true
[dependencies]
proc-macro2 = "1"
quote = "1"
quote = "1"

3595
bindings/swc_cli/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
[workspace]
[package]
authors = ["강동윤 <kdy1997.dev@gmail.com>", "OJ Kwon <kwon.ohjoong@gmail.com>"]
description = "Commandline for SWC"

View File

@ -654,7 +654,7 @@ dependencies = [
[[package]]
name = "swc_core"
version = "0.7.11"
version = "0.7.14"
dependencies = [
"once_cell",
"swc_atoms",
@ -733,7 +733,7 @@ dependencies = [
[[package]]
name = "swc_plugin_proxy"
version = "0.18.6"
version = "0.18.7"
dependencies = [
"better_scoped_tls",
"bytecheck",

View File

@ -28,8 +28,8 @@ const buildHost = async (feature) => {
"build",
"--cargo-name",
"binding_core_node",
"-p",
"binding_core_node",
"--cargo-cwd",
"./bindings/binding_core_node",
`--cargo-flags=--no-default-features --features swc_v1 --features ${feature}`,
"--config",
`./node-swc/e2e/fixtures/napi.host.${feature}.config.js`,

View File

@ -16,6 +16,7 @@ import * as assert from "assert";
// Allow overrides to the location of the .node binding file
const bindingsOverride = process.env["SWC_BINARY_PATH"];
// `@swc/core` includes d.ts for the `@swc/wasm` to provide typed fallback bindings
// todo: fix package.json scripts
let fallbackBindings: any;
const bindings: typeof import('./binding') = (() => {
let binding

View File

@ -59,9 +59,9 @@
"prepublishOnly": "tsc -d && napi prepublish -p scripts/npm --tagstyle npm",
"pack": "wasm-pack",
"build:ts": "tsc -d",
"build:wasm": "npm-run-all \"pack -- build ./crates/binding_core_wasm --scope swc {1} -t {2} --features plugin\" --",
"build": "tsc -d && napi build --platform --cargo-name binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts -p binding_core_node --release",
"build:dev": "tsc -d && napi build --platform --cargo-name binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts -p binding_core_node",
"build:wasm": "npm-run-all \"pack -- build ./bindings/binding_core_wasm --scope swc {1} -t {2} --features plugin\" --",
"build": "tsc -d && napi build --platform --cargo-name binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts --cargo-cwd ./bindings/binding_core_node --release",
"build:dev": "tsc -d && napi build --platform --cargo-name binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts --cargo-cwd ./bindings/binding_core_node",
"test": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --config ./node-swc/jest.config.js",
"version": "napi version -p scripts/npm"
},
@ -171,6 +171,6 @@
"spack.d.ts",
"types.js",
"postinstall.js",
"crates/binding_core_wasm/pkg/binding_core_wasm.d.ts"
"bindings/binding_core_wasm/pkg/binding_core_wasm.d.ts"
]
}
}