Skip to content

Commit 0c45a31

Browse files
authored
Upgrade to napi@1 (#1244)
node-swc: - Support apple silicon. - Support linux aarch64. - Support linux armv7. - Support android aarch64. - Support yarn pnp.
1 parent 254efc4 commit 0c45a31

File tree

33 files changed

+552
-208
lines changed

33 files changed

+552
-208
lines changed

.cargo/config

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,35 @@
22
[build]
33
rustflags = [
44
"--cfg", "procmacro2_semver_exempt",
5-
"-Z", "thinlto=no",
65
"-C", "target-feature=+sse2",
76
]
87

98
rustdocflags = [
109
"--cfg", "procmacro2_semver_exempt",
1110
]
1211

12+
[target.aarch64-apple-darwin]
13+
rustflags = [
14+
"--cfg", "procmacro2_semver_exempt",
15+
]
16+
17+
[target.aarch64-unknown-linux-gnu]
18+
rustflags = [
19+
"--cfg", "procmacro2_semver_exempt",
20+
]
21+
linker = "aarch64-linux-gnu-gcc"
22+
23+
[target.armv7-unknown-linux-gnueabihf]
24+
rustflags = [
25+
"--cfg", "procmacro2_semver_exempt",
26+
]
27+
linker = "arm-linux-gnueabihf-gcc"
28+
29+
[target.aarch64-linux-android]
30+
rustflags = [
31+
"--cfg", "procmacro2_semver_exempt",
32+
]
33+
1334
[target.wasm32-unknown-unknown]
1435
rustflags = [
1536
"--cfg", "procmacro2_semver_exempt",

.github/workflows/cargo.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ jobs:
5252
npm i browserslist regenerator-runtime sourcemap-validator progress
5353
npm i -g jest
5454
55-
- name: Install llvm
56-
if: matrix.os == 'windows-latest'
57-
run: choco install -y llvm
58-
59-
- name: Set llvm path
60-
if: matrix.os == 'windows-latest'
61-
uses: allenevans/set-env@v1.0.0
62-
with:
63-
LIBCLANG_PATH: 'C:\\Program Files\\LLVM\\bin'
64-
6555
- name: Cache
6656
uses: actions/cache@v2
6757
with:

.github/workflows/publish-node.yml

Lines changed: 192 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,12 @@ jobs:
2424
- name: Setup node
2525
uses: actions/setup-node@v1
2626
with:
27-
node-version: 12
28-
29-
- name: Cache
30-
uses: actions/cache@v2
31-
with:
32-
path: |
33-
~/.cargo/
34-
**/target/
35-
key: ${{ runner.os }}-publish-integration
36-
37-
- name: Set platform name
38-
run: |
39-
export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
40-
echo "PLATFORM_NAME=$NODE_PLATFORM_NAME" >> $GITHUB_ENV
41-
shell: bash
42-
43-
- name: Install llvm
44-
if: matrix.os == 'windows-latest'
45-
run: choco install -y llvm
46-
47-
- name: Set llvm path
48-
if: matrix.os == 'windows-latest'
49-
uses: allenevans/set-env@v2.0.0
50-
with:
51-
LIBCLANG_PATH: 'C:\\Program Files\\LLVM\\bin'
27+
node-version: 14
5228

5329
- name: Install node dependencies
5430
run: npm i
5531

5632
- name: Build
57-
if: matrix.os != 'macos-latest'
58-
shell: bash
59-
run: npm run build
60-
61-
- name: Build
62-
if: matrix.os == 'macos-latest'
6333
shell: bash
6434
run: npm run build
6535
env:
@@ -69,17 +39,13 @@ jobs:
6939
uses: actions/upload-artifact@v2
7040
with:
7141
name: bindings
72-
path: swc.${{ env.PLATFORM_NAME }}.node
73-
74-
- name: List packages
75-
run: ls -R ./scripts/npm/
76-
shell: bash
42+
path: swc.*.node
7743

7844
- name: Test bindings
7945
run: npm test
8046

81-
build_musl:
82-
name: stable - linux-musl - node@12
47+
build-linux-musl:
48+
name: stable - linux-musl - node@10
8349
runs-on: ubuntu-latest
8450

8551
steps:
@@ -93,45 +59,218 @@ jobs:
9359
DOCKER_USERNAME: ${{ github.actor }}
9460
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
9561

62+
- name: Cache
63+
uses: actions/cache@v2
64+
with:
65+
path: |
66+
target/
67+
key: linux-musl-publish-integration
68+
9669
- name: Pull docker image
9770
run: |
98-
docker pull docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts
99-
docker tag docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts builder
71+
docker pull docker.pkg.github.com/napi-rs/napi-rs/nodejs-rust:10-alpine
72+
docker tag docker.pkg.github.com/napi-rs/napi-rs/nodejs-rust:10-alpine builder
10073
- name: "Install dependencies"
101-
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
74+
run: npm i
10275

10376
- name: "Build"
10477
run: |
105-
docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/node-rs -w /node-rs builder sh -c "cargo build -p node --release"
106-
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"
78+
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'"
79+
80+
- name: Upload artifact
81+
uses: actions/upload-artifact@v2
82+
with:
83+
name: bindings
84+
path: swc.*.node
85+
86+
build-apple-silicon:
87+
name: nightly - aarch64-apple-darwin - node@14
88+
runs-on: macos-latest
89+
90+
steps:
91+
- uses: actions/checkout@v2
10792

108-
- name: List packages
109-
run: ls -R ./scripts/npm/
93+
- name: Setup node
94+
uses: actions/setup-node@v1
95+
with:
96+
node-version: 14
97+
98+
- name: Install
99+
uses: actions-rs/toolchain@v1
100+
with:
101+
toolchain: nightly
102+
profile: minimal
103+
override: true
104+
105+
- name: Install aarch64 toolchain
106+
run: rustup target add aarch64-apple-darwin
107+
108+
- name: Cache
109+
uses: actions/cache@v2
110+
with:
111+
path: |
112+
target/
113+
key: aarch64-apple-darwin-publish-integration
114+
115+
- name: Install dependencies
116+
run: npm i
117+
118+
- name: Cross build aarch64
119+
run: yarn build --target aarch64-apple-darwin
120+
121+
- name: Upload artifact
122+
uses: actions/upload-artifact@v2
123+
with:
124+
name: bindings
125+
path: swc.*.node
126+
127+
build-linux-aarch64:
128+
name: stable - aarch64-unknown-linux-gnu - node@14
129+
runs-on: ubuntu-latest
130+
131+
steps:
132+
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
133+
134+
- uses: actions/checkout@v2
135+
136+
- name: Setup node
137+
uses: actions/setup-node@v1
138+
with:
139+
node-version: 14
140+
141+
- name: Install
142+
uses: actions-rs/toolchain@v1
143+
with:
144+
toolchain: stable
145+
profile: minimal
146+
override: true
147+
148+
- name: Install aarch64 toolchain
149+
run: rustup target add aarch64-unknown-linux-gnu
150+
151+
- name: Cache
152+
uses: actions/cache@v2
153+
with:
154+
path: |
155+
target/
156+
key: aarch64-linux-gnu-publish-integration
157+
158+
159+
- name: Install cross compile toolchain
160+
run: |
161+
sudo apt-get update
162+
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y
163+
164+
- name: Install dependencies
165+
run: npm i
166+
167+
- name: Cross build aarch64
168+
run: yarn build --target aarch64-unknown-linux-gnu
169+
170+
- name: Upload artifact
171+
uses: actions/upload-artifact@v2
172+
with:
173+
name: bindings
174+
path: swc.*.node
175+
176+
build-linux-arm7:
177+
name: stable - arm7-unknown-linux-gnu - node@14
178+
runs-on: ubuntu-latest
179+
180+
steps:
181+
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
182+
183+
- uses: actions/checkout@v2
184+
185+
- name: Setup node
186+
uses: actions/setup-node@v1
187+
with:
188+
node-version: 14
189+
190+
- name: Install
191+
uses: actions-rs/toolchain@v1
192+
with:
193+
toolchain: stable
194+
profile: minimal
195+
override: true
196+
197+
- name: Install aarch64 toolchain
198+
run: rustup target add armv7-unknown-linux-gnueabihf
199+
200+
- name: Cache
201+
uses: actions/cache@v2
202+
with:
203+
path: |
204+
target/
205+
key: arm7-linux-gnu-publish-integration
206+
207+
- name: Install cross compile toolchain
208+
run: |
209+
sudo apt-get update
210+
sudo apt-get install gcc-arm-linux-gnueabihf -y
211+
212+
- name: Install dependencies
213+
run: npm i
214+
215+
- name: Cross build aarch64
216+
run: yarn build --target armv7-unknown-linux-gnueabihf
217+
218+
- name: Upload artifact
219+
uses: actions/upload-artifact@v2
220+
with:
221+
name: bindings
222+
path: swc.*.node
223+
224+
build-android-aarch64:
225+
name: Build - Android - aarch64
226+
runs-on: macos-latest
227+
steps:
228+
- uses: actions/checkout@v2
229+
230+
- name: Setup node
231+
uses: actions/setup-node@v1
232+
with:
233+
node-version: 14
234+
235+
- name: Install aarch64 toolchain
236+
run: rustup target add aarch64-linux-android
237+
238+
- name: Install node dependencies
239+
run: npm i
240+
241+
- name: Build
110242
shell: bash
243+
run: |
244+
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android24-clang"
245+
yarn build --target aarch64-linux-android
111246
112247
- name: Upload artifact
113248
uses: actions/upload-artifact@v2
114249
with:
115250
name: bindings
116-
path: scripts/npm/swc.linux-musl.node
251+
path: swc.*.node
252+
117253
publish:
118254
name: npm
119255
runs-on: ubuntu-latest
120256
needs:
121257
- build
122-
- build_musl
258+
- build-linux-musl
259+
- build-linux-arm7
260+
- build-linux-aarch64
261+
- build-apple-silicon
262+
- build-android-aarch64
123263
steps:
124264
- uses: actions/checkout@v2
125265

126266
- name: Setup node
127267
uses: actions/setup-node@v1
128268
with:
129-
node-version: 12
269+
node-version: 14
130270

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

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

@@ -148,6 +287,10 @@ jobs:
148287
shell: bash
149288
run: npm run artifacts
150289

290+
- name: List npm
291+
run: ls -R ./scripts/npm
292+
shell: bash
293+
151294
- name: Publish
152295
run: |
153296
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc

.rustfmt.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
format_strings = true
2-
required_version = "1.4.20"
32
use_field_init_shorthand = true
43
wrap_comments = true

native/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ version = "0.1.0"
1212
crate-type = ["cdylib"]
1313

1414
[build-dependencies]
15-
napi-build = "0.2.1"
15+
napi-build = {version = "1.0"}
1616

1717
[dependencies]
1818
anyhow = "1"
1919
backtrace = "0.3"
2020
fxhash = "0.2"
21-
napi = {version = "0.5.0", features = ["serde-json"]}
22-
napi-derive = "0.5.0"
21+
napi = {version = "1.0", features = ["serde-json"]}
22+
napi-derive = {version = "1.0"}
2323
path-clean = "0.1"
2424
serde = {version = "1", features = ["derive"]}
2525
serde_json = "1"
@@ -31,7 +31,7 @@ swc_common = {path = "../common", features = ["tty-emitter", "sourcemap"]}
3131
swc_ecma_ast = {path = "../ecmascript/ast"}
3232
swc_ecma_parser = {path = "../ecmascript/parser"}
3333

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

3737
[target.'cfg(windows)'.dependencies]

0 commit comments

Comments
 (0)