Skip to content

Commit 74ce337

Browse files
authored
Merge pull request #526 from napi-rs/xxhash
feat(xxhash): init
2 parents 4a3765c + 5ea38c3 commit 74ce337

File tree

51 files changed

+957
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+957
-110
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[target.x86_64-pc-windows-msvc]
2+
rustflags = ["-C", "target-cpu=skylake"]
3+
14
[target.aarch64-unknown-linux-gnu]
25
linker = "aarch64-linux-gnu-gcc"
36

.github/workflows/ci.yaml

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ jobs:
2121
settings:
2222
- host: macos-latest
2323
target: 'x86_64-apple-darwin'
24-
build: yarn build
24+
build: |
25+
yarn build
26+
strip -x packages/*/*.node
2527
- host: windows-latest
2628
build: yarn build
2729
target: 'x86_64-pc-windows-msvc'
@@ -35,44 +37,49 @@ jobs:
3537
setup: |
3638
choco install nodejs-lts --x86 -y --force
3739
echo "C:\\Program Files (x86)\\nodejs" >> $GITHUB_PATH
38-
- host: ubuntu-20.04
40+
- host: ubuntu-latest
3941
target: 'x86_64-unknown-linux-gnu'
4042
docker: |
41-
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
4243
docker pull $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian
4344
docker tag $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian builder
4445
build: |
4546
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build
46-
- host: ubuntu-20.04
47+
- host: ubuntu-latest
4748
target: 'x86_64-unknown-linux-musl'
4849
docker: |
49-
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
5050
docker pull $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine
5151
docker tag $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine builder
5252
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build
5353
- host: macos-latest
5454
target: 'aarch64-apple-darwin'
55-
build: npx lerna exec "yarn build --target aarch64-apple-darwin" --concurrency 1 --stream --no-prefix
56-
- host: ubuntu-20.04
55+
build: |
56+
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
57+
export CC=$(xcrun -f clang);
58+
export CXX=$(xcrun -f clang++);
59+
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
60+
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
61+
npx lerna exec "yarn build --target aarch64-apple-darwin" --concurrency 1 --stream --no-prefix
62+
strip -x packages/*/*.node
63+
- host: ubuntu-latest
5764
target: 'aarch64-unknown-linux-gnu'
5865
setup: |
5966
sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
6067
build: npx lerna exec "yarn build --target aarch64-unknown-linux-gnu" --concurrency 1 --stream --no-prefix
61-
- host: ubuntu-20.04
68+
- host: ubuntu-latest
6269
target: 'armv7-unknown-linux-gnueabihf'
6370
setup: |
6471
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
6572
build: npx lerna exec "yarn build --target armv7-unknown-linux-gnueabihf" --concurrency 1 --stream --no-prefix
66-
- host: ubuntu-20.04
73+
- host: ubuntu-latest
6774
target: 'aarch64-linux-android'
6875
build: |
6976
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
77+
export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"
7078
npx lerna exec "yarn build --target aarch64-linux-android" --concurrency 1 --stream --no-prefix
7179
- host: ubuntu-latest
7280
target: 'aarch64-unknown-linux-musl'
7381
downloadTarget: 'aarch64-unknown-linux-musl'
7482
docker: |
75-
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
7683
docker pull ghcr.io/brooooooklyn/canvas/musl-builder:lts
7784
docker tag ghcr.io/brooooooklyn/canvas/musl-builder:lts builder
7885
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/node-rs -w /node-rs builder sh -c "rustup toolchain install $(cat ./rust-toolchain) && rustup target add aarch64-unknown-linux-musl && npx lerna exec \"yarn build --target aarch64-unknown-linux-musl\" --concurrency 1 --stream --no-prefix"
@@ -105,19 +112,19 @@ jobs:
105112
command: generate-lockfile
106113

107114
- name: Cache cargo registry
108-
uses: actions/cache@v1
115+
uses: actions/cache@v2
109116
with:
110117
path: ~/.cargo/registry
111118
key: ${{ matrix.settings.target }}-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
112119

113120
- name: Cache cargo index
114-
uses: actions/cache@v1
121+
uses: actions/cache@v2
115122
with:
116123
path: ~/.cargo/git
117124
key: ${{ matrix.settings.target }}-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
118125

119126
- name: Cache NPM dependencies
120-
uses: actions/cache@v1
127+
uses: actions/cache@v2
121128
with:
122129
path: node_modules
123130
key: npm-cache-${{ matrix.settings.target }}-node@14-${{ hashFiles('yarn.lock') }}
@@ -296,7 +303,7 @@ jobs:
296303
fail-fast: false
297304
matrix:
298305
node: ['12', '14', '16']
299-
runs-on: ubuntu-20.04
306+
runs-on: ubuntu-latest
300307

301308
steps:
302309
- uses: actions/checkout@v2
@@ -338,7 +345,7 @@ jobs:
338345
fail-fast: false
339346
matrix:
340347
node: ['12', '14', '16']
341-
runs-on: ubuntu-20.04
348+
runs-on: ubuntu-latest
342349

343350
steps:
344351
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
@@ -363,27 +370,21 @@ jobs:
363370
shell: bash
364371

365372
- name: Setup and run tests
366-
uses: docker://multiarch/ubuntu-core:arm64-focal
373+
uses: addnab/docker-run-action@v3
367374
with:
368-
args: >
369-
sh -c "
370-
apt-get update && \
371-
apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
372-
curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
373-
apt-get install -y nodejs && \
374-
npm install -g yarn && \
375-
yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 && \
376-
yarn build:ts && \
377-
yarn test && \
378-
ls -la
379-
"
375+
image: ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}
376+
options: -v ${{ github.workspace }}:/skia -w /skia
377+
run: |
378+
pnpm install --ignore-scripts && \
379+
npm test && \
380+
ls -la
380381
381382
test-linux-aarch64-musl-binding:
382383
name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }}
383384
needs:
384385
- build
385386

386-
runs-on: ubuntu-20.04
387+
runs-on: ubuntu-latest
387388

388389
steps:
389390
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
@@ -426,7 +427,7 @@ jobs:
426427
fail-fast: false
427428
matrix:
428429
node: ['12', '14', '16']
429-
runs-on: ubuntu-20.04
430+
runs-on: ubuntu-latest
430431

431432
steps:
432433
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
@@ -451,20 +452,14 @@ jobs:
451452
shell: bash
452453

453454
- name: Setup and run tests
454-
uses: docker://multiarch/ubuntu-core:armhf-focal
455+
uses: addnab/docker-run-action@v3
455456
with:
456-
args: >
457-
sh -c "
458-
apt-get update && \
459-
apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
460-
curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
461-
apt-get install -y nodejs && \
462-
npm install -g yarn && \
463-
yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 && \
464-
yarn build:ts && \
465-
yarn test && \
466-
ls -la
467-
"
457+
image: ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.node }}
458+
options: -v ${{ github.workspace }}:/skia -w /skia
459+
run: |
460+
pnpm install --ignore-scripts && \
461+
npm test && \
462+
ls -la
468463
469464
publish:
470465
name: Publish
@@ -486,7 +481,7 @@ jobs:
486481
check-latest: true
487482

488483
- name: Cache NPM dependencies
489-
uses: actions/cache@v1
484+
uses: actions/cache@v2
490485
with:
491486
path: node_modules
492487
key: npm-cache-ubuntu-latest-publish-${{ hashFiles('yarn.lock') }}

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
components: rustfmt, clippy
2929

3030
- name: Cache NPM dependencies
31-
uses: actions/cache@v1
31+
uses: actions/cache@v2
3232
with:
3333
path: node_modules
3434
key: npm-cache-lint-node@14-${{ hashFiles('yarn.lock') }}

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ cargo-features = ["strip"]
22

33
[workspace]
44
members = [
5+
"./crates/alloc",
56
"./packages/bcrypt",
67
"./packages/crc32",
78
"./packages/deno-lint",
89
"./packages/jieba",
10+
"./packages/xxhash",
911
]
1012

1113
[profile.release]
14+
codegen-units = 1
1215
lto = true
16+
overflow-checks = false
1317
strip = 'symbols'

crates/alloc/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
edition = "2021"
3+
name = "global_alloc"
4+
version = "0.1.0"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[target.'cfg(not(all(target_os = "windows", target_arch = "aarch64")))'.dependencies]
9+
mimalloc-rust = {version = "0.1"}

crates/alloc/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[cfg(all(
2+
not(debug_assertions),
3+
not(all(target_os = "windows", target_arch = "aarch64"))
4+
))]
5+
#[global_allocator]
6+
static ALLOC: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"devDependencies": {
2525
"@napi-rs/cli": "^1.3.3",
2626
"@swc-node/register": "^1.3.6",
27+
"@types/node": "^16.11.1",
2728
"@typescript-eslint/eslint-plugin": "^4.33.0",
2829
"@typescript-eslint/parser": "^4.33.0",
2930
"ava": "^3.15.0",

packages/bcrypt/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
authors = ["LongYinan <[email protected]>"]
3-
edition = "2018"
3+
edition = "2021"
44
name = "node-rs-bcrypt"
55
version = "0.1.0"
66

@@ -10,15 +10,13 @@ crate-type = ["cdylib"]
1010
[dependencies]
1111
blowfish = {version = "0.8", features = ["bcrypt"]}
1212
byteorder = "1"
13+
global_alloc = {path = "../../crates/alloc"}
1314
napi = "1"
1415
napi-derive = "1"
1516
phf = {version = "0.10", features = ["macros"]}
1617
radix64 = "0.6"
1718
rand = "0.8"
1819

19-
[target.'cfg(all(target_arch = "x86_64", not(target_env = "musl")))'.dependencies]
20-
mimalloc = {version = "0.1"}
21-
2220
[dev-dependencies]
2321
quickcheck = "1.0"
2422

packages/bcrypt/src/lib.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#![deny(clippy::all)]
22
#![allow(clippy::nonstandard_macro_braces)]
33

4-
#[macro_use]
5-
extern crate napi_derive;
4+
/// Explicit extern crate to use allocator.
5+
extern crate global_alloc;
66

7-
use std::convert::TryInto;
87
use std::str::FromStr;
98

109
use napi::{CallContext, Error, JsBoolean, JsBuffer, JsNumber, JsObject, JsString, Result, Status};
10+
use napi_derive::*;
1111

1212
use crate::hash_task::HashTask;
1313
use crate::lib_bcrypt::{format_salt, gen_salt, Version};
@@ -21,14 +21,6 @@ mod lib_bcrypt;
2121
mod salt_task;
2222
mod verify_task;
2323

24-
#[cfg(all(
25-
target_arch = "x86_64",
26-
not(target_env = "musl"),
27-
not(debug_assertions)
28-
))]
29-
#[global_allocator]
30-
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
31-
3224
#[module_exports]
3325
fn init(mut exports: JsObject) -> Result<()> {
3426
exports.create_named_method("genSaltSync", js_salt)?;

packages/crc32/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
authors = ["LongYinan <[email protected]>"]
3-
edition = "2018"
3+
edition = "2021"
44
name = "node-rs-crc32"
55
version = "0.1.0"
66

@@ -10,11 +10,9 @@ crate-type = ["cdylib"]
1010
[dependencies]
1111
crc32c = {version = "0.6"}
1212
crc32fast = {version = "1.2", features = ["nightly"]}
13+
global_alloc = {path = "../../crates/alloc"}
1314
napi = "1"
1415
napi-derive = "1"
1516

16-
[target.'cfg(all(target_arch = "x86_64", not(target_env = "musl")))'.dependencies]
17-
mimalloc = {version = "0.1"}
18-
1917
[build-dependencies]
2018
napi-build = "1"

0 commit comments

Comments
 (0)