Skip to content

Commit 0e31505

Browse files
LongYinanBrooooooklyn
authored andcommitted
feat: support linux musl
1 parent 3ed354b commit 0e31505

27 files changed

+151
-48
lines changed

.github/workflows/ci.yaml

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,51 @@ jobs:
107107
name: bindings-${{ env.PLATFORM_NAME }}
108108
path: packages/*/*.${{ env.PLATFORM_NAME }}.node
109109

110+
build_musl:
111+
if: "!contains(github.event.head_commit.message, 'skip ci')"
112+
name: stable - linux-musl - node@12
113+
runs-on: ubuntu-latest
114+
115+
steps:
116+
- uses: actions/checkout@v2
117+
118+
- name: Login to registry
119+
run: |
120+
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
121+
env:
122+
DOCKER_REGISTRY_URL: docker.pkg.github.com
123+
DOCKER_USERNAME: ${{ github.actor }}
124+
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
125+
126+
- name: Pull docker image
127+
run: |
128+
docker pull docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts
129+
docker tag docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts builder
130+
131+
- name: 'Install dependencies'
132+
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
133+
134+
- name: 'Build'
135+
run: |
136+
docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/node-rs -w /node-rs builder sh -c "cargo build --release"
137+
docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/node-rs -w /node-rs builder sh -c "./node_modules/.bin/lerna run build --stream -- --musl"
138+
139+
- name: Upload artifact
140+
uses: actions/upload-artifact@v2
141+
with:
142+
name: bindings-musl
143+
path: packages/*/*.musl.node
144+
110145
test_binding:
111146
name: Test bindings on ${{ matrix.os }} - node@${{ matrix.node }}
112-
needs: lint_and_build
147+
needs:
148+
- lint_and_build
149+
- build_musl
113150
strategy:
114151
fail-fast: false
115152
matrix:
116153
os: [ubuntu-latest, macos-latest, windows-latest]
117-
node: ['10', '12', '13', '14']
154+
node: ['10', '12', '14']
118155
runs-on: ${{ matrix.os }}
119156

120157
steps:
@@ -158,6 +195,45 @@ jobs:
158195
- name: Run benchmark
159196
run: yarn bench
160197

198+
test_musl_binding:
199+
name: Test bindings on alpine - node@${{ matrix.node }}
200+
needs:
201+
- lint_and_build
202+
- build_musl
203+
strategy:
204+
fail-fast: false
205+
matrix:
206+
node: ['10', '12', '14']
207+
runs-on: ubuntu-latest
208+
209+
steps:
210+
- uses: actions/checkout@v2
211+
212+
- name: Download artifacts
213+
uses: actions/download-artifact@v2
214+
with:
215+
name: bindings-musl
216+
path: artifacts
217+
218+
- name: Move artifacts
219+
run: node scripts/mv-artifacts.js
220+
shell: bash
221+
env:
222+
MOVE_TARGET: musl
223+
224+
- name: List packages
225+
run: ls -R packages
226+
shell: bash
227+
228+
- name: 'Install dependencies'
229+
run: yarn install --frozen-lockfile --ignore-scripts --registry https://registry.npmjs.org
230+
231+
- name: Build TypeScript
232+
run: yarn build:ts
233+
234+
- name: Run simple tests
235+
run: docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/node-rs -w /node-rs node:${{ matrix.node }}-alpine sh -c "./node_modules/.bin/lerna run test:simple --stream"
236+
161237
publish:
162238
name: Publish
163239
if: "startsWith(github.event.head_commit.message, 'chore(release): publish')"

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ members = [
44
"./packages/crc32",
55
"./packages/jieba"
66
]
7+
8+
[profile.release]
9+
opt-level = 3
10+
lto = true

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Make rust crates binding to NodeJS use [napi-rs](https://github.com/Brooooooklyn
88

99
# Support matrix
1010

11-
| | node 10 | node12 | node13 | node14 |
12-
| ----------------- | ------- | ------ | ------ | ------ |
13-
| Windows 64 latest |||||
14-
| macOS latest |||||
15-
| Linux |||||
11+
| | node 10 | node12 | node14 |
12+
| ----------------- | ------- | ------ | ------ |
13+
| Windows 64 latest ||||
14+
| macOS latest ||||
15+
| Linux ||||
1616

1717
# Packages
1818

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"husky": "^4.2.5",
3737
"lerna": "^3.20.2",
3838
"lint-staged": "^10.1.7",
39-
"napi-rs": "^0.2.3",
39+
"napi-rs": "^0.2.4",
4040
"npm-run-all": "^4.1.5",
4141
"nyc": "^15.0.1",
4242
"prettier": "^2.0.5",

packages/bcrypt/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ napi-rs-derive = { version = "0.2" }
1616
rand = "0.7"
1717
phf = { version = "0.8", features = ["macros"] }
1818

19-
[target.'cfg(unix)'.dependencies]
19+
[target.'cfg(all(unix, not(target_env = "musl")))'.dependencies]
2020
jemallocator = { version = "0.3", features = ["disable_initial_exec_tls"] }
2121

2222
[dev-dependencies]

packages/bcrypt/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
## Support matrix
88

9-
| | node 10 | node12 | node13 | node14 |
10-
| ----------------- | ------- | ------ | ------ | ------ |
11-
| Windows 64 latest |||||
12-
| macOS latest |||||
13-
| Linux |||||
9+
| | node 10 | node12 | node14 |
10+
| ----------------- | ------- | ------ | ------ |
11+
| Windows 64 latest ||||
12+
| macOS latest ||||
13+
| Linux ||||
1414

1515
## Usage
1616

packages/bcrypt/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { locateBinding } = require('@node-rs/helper')
1+
const { loadBinding } = require('@node-rs/helper')
22

3-
const binding = require(locateBinding(__dirname, 'bcrypt'))
3+
const binding = loadBinding(__dirname, 'bcrypt')
44

55
const DEFAULT_COST = 12
66

packages/bcrypt/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"scripts": {
2525
"bench": "cross-env NODE_ENV=production node benchmark/bcrypt.js",
2626
"build": "napi --release ./bcrypt",
27-
"build:debug": "napi ./bcrypt.debug"
27+
"build:debug": "napi ./bcrypt.debug",
28+
"test:simple": "node ./simple-test.js"
2829
},
2930
"bugs": {
3031
"url": "https://github.com/Brooooooklyn/node-rs/issues"

packages/bcrypt/simple-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const { verifySync } = require('./index')
2+
3+
console.assert(verifySync('hello', '$2b$12$k4V9p7YpSYHY05bORujyyeesfPaWNQfPkjVzETFGfozAN/fH0LtdG'))

packages/bcrypt/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use verify_task::VerifyTask;
1515
mod hash_task;
1616
mod verify_task;
1717

18-
#[cfg(unix)]
18+
#[cfg(all(unix, not(target_env = "musl")))]
1919
#[global_allocator]
2020
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
2121

0 commit comments

Comments
 (0)