Skip to content

Commit

Permalink
feat(node/core): Include noop swc binaries (#3088)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj authored Dec 21, 2021
1 parent dc6a19d commit 42046e1
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 19 deletions.
40 changes: 34 additions & 6 deletions .github/workflows/publish-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ jobs:
- host: macos-latest
target: x86_64-apple-darwin
build: |
cargo build -p swc_cli --release
cp ./target/release/swc .
yarn build
strip -x *.node
- host: windows-latest
build: yarn build
build: |
yarn build
cargo build -p swc_cli --release
cp target/release/swc .
target: x86_64-pc-windows-msvc
- host: windows-latest
build: |
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=32;
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 .
yarn build --target i686-pc-windows-msvc
yarn test
target: i686-pc-windows-msvc
Expand All @@ -44,14 +51,17 @@ jobs:
docker pull $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian
docker tag $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian builder
build: |
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder sh -c "cargo build -p swc_cli --release; rm -rf target/release/.cargo-lock" && cp target/release/swc .
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build && strip swc.linux-x64-gnu.node
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
docker: |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
docker pull $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine
docker tag $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build && strip swc.linux-x64-musl.node
build: |
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder sh -c "cargo build -p swc_cli --release; rm -rf target/release/.cargo-lock" && cp target/release/swc .
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build && strip swc.linux-x64-musl.node
- host: macos-latest
target: aarch64-apple-darwin
build: |
Expand All @@ -60,6 +70,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 --target=aarch64-apple-darwin
cp ./target/aarch64-apple-darwin/release/swc .
yarn build --target=aarch64-apple-darwin
strip -x *.node
- host: ubuntu-latest
Expand All @@ -68,6 +80,8 @@ jobs:
sudo apt-get update
sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
build: |
cargo build -p swc_cli --release --target=aarch64-unknown-linux-gnu
cp ./target/aarch64-unknown-linux-gnu/release/swc .
yarn build --target=aarch64-unknown-linux-gnu
aarch64-linux-gnu-strip swc.linux-arm64-gnu.node
- host: ubuntu-latest
Expand All @@ -76,12 +90,16 @@ jobs:
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
build: |
cargo build -p swc_cli --release --target=armv7-unknown-linux-gnueabihf
cp ./target/armv7-unknown-linux-gnueabihf/release/swc .
yarn build --target=armv7-unknown-linux-gnueabihf
arm-linux-gnueabihf-strip swc.linux-arm-gnueabihf.node
- host: ubuntu-latest
target: aarch64-linux-android
build: |
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
cargo build -p swc_cli --release --target aarch64-linux-android
cp ./target/aarch64-linux-android/release/swc .
yarn build --target aarch64-linux-android
${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip *.node
- host: ubuntu-latest
Expand All @@ -92,10 +110,14 @@ jobs:
docker pull ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
docker tag ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
build: |
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder sh -c "rustup toolchain install $(cat ./rust-toolchain) && rustup target add aarch64-unknown-linux-musl && cargo build -p swc_cli --release --target=aarch64-unknown-linux-musl && rm -rf target/release/.cargo-lock" && cp target/aarch64-unknown-linux-musl/release/swc .
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder sh -c "rustup toolchain install $(cat ./rust-toolchain) && rustup target add aarch64-unknown-linux-musl && yarn build --target=aarch64-unknown-linux-musl && /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip swc.linux-arm64-musl.node"
- host: windows-latest
target: aarch64-pc-windows-msvc
build: yarn build --target aarch64-pc-windows-msvc
build: |
cargo build -p swc_cli --release --target aarch64-pc-windows-msvc
cp target/aarch64-pc-windows-msvc/release/swc.exe .
yarn build --target aarch64-pc-windows-msvc
name: stable - ${{ matrix.settings.target }} - node@14
runs-on: ${{ matrix.settings.host }}
steps:
Expand Down Expand Up @@ -150,7 +172,8 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: bindings-${{ matrix.settings.target }}
path: swc.*.node
path: |
swc*
if-no-files-found: error
build-freebsd:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
Expand Down Expand Up @@ -222,14 +245,17 @@ jobs:
freebsd-version
yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000
yarn build
cargo build -p swc_cli --release
cp ./target/release/swc .
yarn test
rm -rf node_modules
rm -rf target
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: bindings-freebsd
path: swc.*.node
path: |
swc*
if-no-files-found: error
test-macOS-windows-binding:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
Expand Down Expand Up @@ -514,7 +540,9 @@ jobs:

- name: Move binaries
shell: bash
run: npm run artifacts
run: |
./scripts/cli_artifacts.sh
npm run artifacts
- name: List npm
run: ls -R ./scripts/npm
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
native/artifacts.json
artifacts.json
*.node
/scripts/npm/**/swc
/scripts/npm/**/swc.exe


target/
Expand Down
6 changes: 5 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ rust-toolchain
crates/
packages/
cspell.json
deny.toml
deny.toml
.mocha.setup.js
.mocharc.js
jest.config.js
cliff.toml
15 changes: 15 additions & 0 deletions scripts/cli_artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

# Naive substitution to napi artifacts for the cli binary.
for filename in artifacts/*/*.node
do
BINDING_NAME=${filename#*.}
BINDING_ABI=${BINDING_NAME%%.*}
CLI_BINARY_PATH=${filename%%.*}

if [ -f "$CLI_BINARY_PATH" ]; then
mv $CLI_BINARY_PATH ./scripts/npm/$BINDING_ABI
else
mv $CLI_BINARY_PATH.exe ./scripts/npm/$BINDING_ABI
fi
done
3 changes: 2 additions & 1 deletion scripts/npm/android-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.android-arm64.node",
"files": [
"swc.android-arm64.node"
"swc.android-arm64.node",
"swc"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.darwin-arm64.node",
"files": [
"swc.darwin-arm64.node"
"swc.darwin-arm64.node",
"swc"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.darwin-x64.node",
"files": [
"swc.darwin-x64.node"
"swc.darwin-x64.node",
"swc"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/freebsd-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.freebsd-x64.node",
"files": [
"swc.freebsd-x64.node"
"swc.freebsd-x64.node",
"swc"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/linux-arm-gnueabihf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.linux-arm-gnueabihf.node",
"files": [
"swc.linux-arm-gnueabihf.node"
"swc.linux-arm-gnueabihf.node",
"swc"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.linux-arm64-gnu.node",
"files": [
"swc.linux-arm64-gnu.node"
"swc.linux-arm64-gnu.node",
"swc"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.linux-arm64-musl.node",
"files": [
"swc.linux-arm64-musl.node"
"swc.linux-arm64-musl.node",
"swc"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.linux-x64-gnu.node",
"files": [
"swc.linux-x64-gnu.node"
"swc.linux-x64-gnu.node",
"swc"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.linux-x64-musl.node",
"files": [
"swc.linux-x64-musl.node"
"swc.linux-x64-musl.node",
"swc"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/win32-arm64-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.win32-arm64-msvc.node",
"files": [
"swc.win32-arm64-msvc.node"
"swc.win32-arm64-msvc.node",
"swc.exe"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/win32-ia32-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.win32-ia32-msvc.node",
"files": [
"swc.win32-ia32-msvc.node"
"swc.win32-ia32-msvc.node",
"swc.exe"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion scripts/npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
],
"main": "swc.win32-x64-msvc.node",
"files": [
"swc.win32-x64-msvc.node"
"swc.win32-x64-msvc.node",
"swc.exe"
],
"description": "Super-fast alternative for babel",
"keywords": [
Expand Down

1 comment on commit 42046e1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 42046e1 Previous: dc6a19d Ratio
full_es2015 186755482 ns/iter (± 5880196) 212639426 ns/iter (± 14714584) 0.88
full_es2016 155699605 ns/iter (± 7613667) 175281235 ns/iter (± 13685099) 0.89
full_es2017 162094039 ns/iter (± 10373758) 186731462 ns/iter (± 18657111) 0.87
full_es2018 162118908 ns/iter (± 9709958) 183433279 ns/iter (± 11217627) 0.88
full_es2019 160710004 ns/iter (± 8549167) 181566487 ns/iter (± 10636700) 0.89
full_es2020 161675683 ns/iter (± 10727616) 182302548 ns/iter (± 17032149) 0.89
full_es3 226641960 ns/iter (± 9114783) 253810103 ns/iter (± 26373763) 0.89
full_es5 203571676 ns/iter (± 13465173) 232546335 ns/iter (± 23158662) 0.88
parser 695290 ns/iter (± 18965) 809972 ns/iter (± 97774) 0.86

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.