Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to napi@1 #1244

Merged
merged 1 commit into from
Dec 30, 2020
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
23 changes: 22 additions & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@
[build]
rustflags = [
"--cfg", "procmacro2_semver_exempt",
"-Z", "thinlto=no",
"-C", "target-feature=+sse2",
]

rustdocflags = [
"--cfg", "procmacro2_semver_exempt",
]

[target.aarch64-apple-darwin]
rustflags = [
"--cfg", "procmacro2_semver_exempt",
]

[target.aarch64-unknown-linux-gnu]
rustflags = [
"--cfg", "procmacro2_semver_exempt",
]
linker = "aarch64-linux-gnu-gcc"

[target.armv7-unknown-linux-gnueabihf]
rustflags = [
"--cfg", "procmacro2_semver_exempt",
]
linker = "arm-linux-gnueabihf-gcc"

[target.aarch64-linux-android]
rustflags = [
"--cfg", "procmacro2_semver_exempt",
]

[target.wasm32-unknown-unknown]
rustflags = [
"--cfg", "procmacro2_semver_exempt",
Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ jobs:
npm i browserslist regenerator-runtime sourcemap-validator progress
npm i -g jest

- name: Install llvm
if: matrix.os == 'windows-latest'
run: choco install -y llvm

- name: Set llvm path
if: matrix.os == 'windows-latest'
uses: allenevans/[email protected]
with:
LIBCLANG_PATH: 'C:\\Program Files\\LLVM\\bin'

- name: Cache
uses: actions/cache@v2
with:
Expand Down
241 changes: 192 additions & 49 deletions .github/workflows/publish-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,12 @@ jobs:
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 12

- name: Cache
uses: actions/cache@v2
with:
path: |
~/.cargo/
**/target/
key: ${{ runner.os }}-publish-integration

- name: Set platform name
run: |
export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
echo "PLATFORM_NAME=$NODE_PLATFORM_NAME" >> $GITHUB_ENV
shell: bash

- name: Install llvm
if: matrix.os == 'windows-latest'
run: choco install -y llvm

- name: Set llvm path
if: matrix.os == 'windows-latest'
uses: allenevans/[email protected]
with:
LIBCLANG_PATH: 'C:\\Program Files\\LLVM\\bin'
node-version: 14

- name: Install node dependencies
run: npm i

- name: Build
if: matrix.os != 'macos-latest'
shell: bash
run: npm run build

- name: Build
if: matrix.os == 'macos-latest'
shell: bash
run: npm run build
env:
Expand All @@ -69,17 +39,13 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: bindings
path: swc.${{ env.PLATFORM_NAME }}.node

- name: List packages
run: ls -R ./scripts/npm/
shell: bash
path: swc.*.node

- name: Test bindings
run: npm test

build_musl:
name: stable - linux-musl - node@12
build-linux-musl:
name: stable - linux-musl - node@10
runs-on: ubuntu-latest

steps:
Expand All @@ -93,45 +59,218 @@ jobs:
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

- name: Cache
uses: actions/cache@v2
with:
path: |
target/
key: linux-musl-publish-integration

- name: Pull docker image
run: |
docker pull docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts
docker tag docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts builder
docker pull docker.pkg.github.com/napi-rs/napi-rs/nodejs-rust:10-alpine
docker tag docker.pkg.github.com/napi-rs/napi-rs/nodejs-rust:10-alpine builder
- name: "Install dependencies"
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
run: npm i

- name: "Build"
run: |
docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/node-rs -w /node-rs builder sh -c "cargo build -p node --release"
docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/node-rs -w /node-rs builder sh -c "./node_modules/.bin/napi build --platform --cargo-name node --musl --release -c ./package.json ./scripts/npm"
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/swc -w /swc builder sh -c "./node_modules/.bin/napi build --platform --cargo-name node --release -c ./package.json --cargo-flags='-p node'"

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: bindings
path: swc.*.node

build-apple-silicon:
name: nightly - aarch64-apple-darwin - node@14
runs-on: macos-latest

steps:
- uses: actions/checkout@v2

- name: List packages
run: ls -R ./scripts/npm/
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 14

- name: Install
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
override: true

- name: Install aarch64 toolchain
run: rustup target add aarch64-apple-darwin

- name: Cache
uses: actions/cache@v2
with:
path: |
target/
key: aarch64-apple-darwin-publish-integration

- name: Install dependencies
run: npm i

- name: Cross build aarch64
run: yarn build --target aarch64-apple-darwin

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: bindings
path: swc.*.node

build-linux-aarch64:
name: stable - aarch64-unknown-linux-gnu - node@14
runs-on: ubuntu-latest

steps:
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset

- uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 14

- name: Install
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Install aarch64 toolchain
run: rustup target add aarch64-unknown-linux-gnu

- name: Cache
uses: actions/cache@v2
with:
path: |
target/
key: aarch64-linux-gnu-publish-integration


- name: Install cross compile toolchain
run: |
sudo apt-get update
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y

- name: Install dependencies
run: npm i

- name: Cross build aarch64
run: yarn build --target aarch64-unknown-linux-gnu

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: bindings
path: swc.*.node

build-linux-arm7:
name: stable - arm7-unknown-linux-gnu - node@14
runs-on: ubuntu-latest

steps:
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset

- uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 14

- name: Install
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Install aarch64 toolchain
run: rustup target add armv7-unknown-linux-gnueabihf

- name: Cache
uses: actions/cache@v2
with:
path: |
target/
key: arm7-linux-gnu-publish-integration

- name: Install cross compile toolchain
run: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf -y

- name: Install dependencies
run: npm i

- name: Cross build aarch64
run: yarn build --target armv7-unknown-linux-gnueabihf

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: bindings
path: swc.*.node

build-android-aarch64:
name: Build - Android - aarch64
runs-on: macos-latest
steps:
- uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 14

- name: Install aarch64 toolchain
run: rustup target add aarch64-linux-android

- name: Install node dependencies
run: npm i

- name: Build
shell: bash
run: |
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android24-clang"
yarn build --target aarch64-linux-android

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: bindings
path: scripts/npm/swc.linux-musl.node
path: swc.*.node

publish:
name: npm
runs-on: ubuntu-latest
needs:
- build
- build_musl
- build-linux-musl
- build-linux-arm7
- build-linux-aarch64
- build-apple-silicon
- build-android-aarch64
steps:
- uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14

- name: Set release name
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

# Do not cache node_modules, or yarn workspace links broken
- name: Install dependencies
run: npm i

Expand All @@ -148,6 +287,10 @@ jobs:
shell: bash
run: npm run artifacts

- name: List npm
run: ls -R ./scripts/npm
shell: bash

- name: Publish
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
Expand Down
1 change: 0 additions & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
format_strings = true
required_version = "1.4.20"
use_field_init_shorthand = true
wrap_comments = true
8 changes: 4 additions & 4 deletions native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ version = "0.1.0"
crate-type = ["cdylib"]

[build-dependencies]
napi-build = "0.2.1"
napi-build = {version = "1.0"}

[dependencies]
anyhow = "1"
backtrace = "0.3"
fxhash = "0.2"
napi = {version = "0.5.0", features = ["serde-json"]}
napi-derive = "0.5.0"
napi = {version = "1.0", features = ["serde-json"]}
napi-derive = {version = "1.0"}
path-clean = "0.1"
serde = {version = "1", features = ["derive"]}
serde_json = "1"
Expand All @@ -31,7 +31,7 @@ swc_common = {path = "../common", features = ["tty-emitter", "sourcemap"]}
swc_ecma_ast = {path = "../ecmascript/ast"}
swc_ecma_parser = {path = "../ecmascript/parser"}

[target.'cfg(all(unix, not(target_env = "musl")))'.dependencies]
[target.'cfg(all(unix, not(target_env = "musl"), not(target_arch = "aarch64")))'.dependencies]
jemallocator = {version = "0.3", features = ["disable_initial_exec_tls"]}

[target.'cfg(windows)'.dependencies]
Expand Down
Loading