Skip to content
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
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-cpu=skylake"]

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"

Expand Down
83 changes: 39 additions & 44 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ jobs:
settings:
- host: macos-latest
target: 'x86_64-apple-darwin'
build: yarn build
build: |
yarn build
strip -x packages/*/*.node
- host: windows-latest
build: yarn build
target: 'x86_64-pc-windows-msvc'
Expand All @@ -35,44 +37,49 @@ jobs:
setup: |
choco install nodejs-lts --x86 -y --force
echo "C:\\Program Files (x86)\\nodejs" >> $GITHUB_PATH
- host: ubuntu-20.04
- host: ubuntu-latest
target: 'x86_64-unknown-linux-gnu'
docker: |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
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 yarn build
- host: ubuntu-20.04
- 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
- host: macos-latest
target: 'aarch64-apple-darwin'
build: npx lerna exec "yarn build --target aarch64-apple-darwin" --concurrency 1 --stream --no-prefix
- host: ubuntu-20.04
build: |
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
export CC=$(xcrun -f clang);
export CXX=$(xcrun -f clang++);
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
npx lerna exec "yarn build --target aarch64-apple-darwin" --concurrency 1 --stream --no-prefix
strip -x packages/*/*.node
- host: ubuntu-latest
target: 'aarch64-unknown-linux-gnu'
setup: |
sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
build: npx lerna exec "yarn build --target aarch64-unknown-linux-gnu" --concurrency 1 --stream --no-prefix
- host: ubuntu-20.04
- host: ubuntu-latest
target: 'armv7-unknown-linux-gnueabihf'
setup: |
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
build: npx lerna exec "yarn build --target armv7-unknown-linux-gnueabihf" --concurrency 1 --stream --no-prefix
- host: ubuntu-20.04
- 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"
export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"
npx lerna exec "yarn build --target aarch64-linux-android" --concurrency 1 --stream --no-prefix
- host: ubuntu-latest
target: 'aarch64-unknown-linux-musl'
downloadTarget: 'aarch64-unknown-linux-musl'
docker: |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
docker pull ghcr.io/brooooooklyn/canvas/musl-builder:lts
docker tag ghcr.io/brooooooklyn/canvas/musl-builder:lts builder
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"
Expand Down Expand Up @@ -105,19 +112,19 @@ jobs:
command: generate-lockfile

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

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

- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-${{ matrix.settings.target }}-node@14-${{ hashFiles('yarn.lock') }}
Expand Down Expand Up @@ -296,7 +303,7 @@ jobs:
fail-fast: false
matrix:
node: ['12', '14', '16']
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -338,7 +345,7 @@ jobs:
fail-fast: false
matrix:
node: ['12', '14', '16']
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

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

- name: Setup and run tests
uses: docker://multiarch/ubuntu-core:arm64-focal
uses: addnab/docker-run-action@v3
with:
args: >
sh -c "
apt-get update && \
apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
apt-get install -y nodejs && \
npm install -g yarn && \
yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 && \
yarn build:ts && \
yarn test && \
ls -la
"
image: ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}
options: -v ${{ github.workspace }}:/skia -w /skia
run: |
pnpm install --ignore-scripts && \
npm test && \
ls -la

test-linux-aarch64-musl-binding:
name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }}
needs:
- build

runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
Expand Down Expand Up @@ -426,7 +427,7 @@ jobs:
fail-fast: false
matrix:
node: ['12', '14', '16']
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

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

- name: Setup and run tests
uses: docker://multiarch/ubuntu-core:armhf-focal
uses: addnab/docker-run-action@v3
with:
args: >
sh -c "
apt-get update && \
apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
apt-get install -y nodejs && \
npm install -g yarn && \
yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 && \
yarn build:ts && \
yarn test && \
ls -la
"
image: ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.node }}
options: -v ${{ github.workspace }}:/skia -w /skia
run: |
pnpm install --ignore-scripts && \
npm test && \
ls -la

publish:
name: Publish
Expand All @@ -486,7 +481,7 @@ jobs:
check-latest: true

- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-ubuntu-latest-publish-${{ hashFiles('yarn.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
components: rustfmt, clippy

- name: Cache NPM dependencies
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-lint-node@14-${{ hashFiles('yarn.lock') }}
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ cargo-features = ["strip"]

[workspace]
members = [
"./crates/alloc",
"./packages/bcrypt",
"./packages/crc32",
"./packages/deno-lint",
"./packages/jieba",
"./packages/xxhash",
]

[profile.release]
codegen-units = 1
lto = true
overflow-checks = false
strip = 'symbols'
9 changes: 9 additions & 0 deletions crates/alloc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
edition = "2021"
name = "global_alloc"
version = "0.1.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[target.'cfg(not(all(target_os = "windows", target_arch = "aarch64")))'.dependencies]
mimalloc-rust = {version = "0.1"}
6 changes: 6 additions & 0 deletions crates/alloc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[cfg(all(
not(debug_assertions),
not(all(target_os = "windows", target_arch = "aarch64"))
))]
#[global_allocator]
static ALLOC: mimalloc_rust::GlobalMiMalloc = mimalloc_rust::GlobalMiMalloc;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"devDependencies": {
"@napi-rs/cli": "^1.3.3",
"@swc-node/register": "^1.3.6",
"@types/node": "^16.11.1",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"ava": "^3.15.0",
Expand Down
6 changes: 2 additions & 4 deletions packages/bcrypt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
authors = ["LongYinan <lynweklm@gmail.com>"]
edition = "2018"
edition = "2021"
name = "node-rs-bcrypt"
version = "0.1.0"

Expand All @@ -10,15 +10,13 @@ crate-type = ["cdylib"]
[dependencies]
blowfish = {version = "0.8", features = ["bcrypt"]}
byteorder = "1"
global_alloc = {path = "../../crates/alloc"}
napi = "1"
napi-derive = "1"
phf = {version = "0.10", features = ["macros"]}
radix64 = "0.6"
rand = "0.8"

[target.'cfg(all(target_arch = "x86_64", not(target_env = "musl")))'.dependencies]
mimalloc = {version = "0.1"}

[dev-dependencies]
quickcheck = "1.0"

Expand Down
14 changes: 3 additions & 11 deletions packages/bcrypt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#![deny(clippy::all)]
#![allow(clippy::nonstandard_macro_braces)]

#[macro_use]
extern crate napi_derive;
/// Explicit extern crate to use allocator.
extern crate global_alloc;

use std::convert::TryInto;
use std::str::FromStr;

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

use crate::hash_task::HashTask;
use crate::lib_bcrypt::{format_salt, gen_salt, Version};
Expand All @@ -21,14 +21,6 @@ mod lib_bcrypt;
mod salt_task;
mod verify_task;

#[cfg(all(
target_arch = "x86_64",
not(target_env = "musl"),
not(debug_assertions)
))]
#[global_allocator]
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[module_exports]
fn init(mut exports: JsObject) -> Result<()> {
exports.create_named_method("genSaltSync", js_salt)?;
Expand Down
6 changes: 2 additions & 4 deletions packages/crc32/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
authors = ["LongYinan <lynweklm@gmail.com>"]
edition = "2018"
edition = "2021"
name = "node-rs-crc32"
version = "0.1.0"

Expand All @@ -10,11 +10,9 @@ crate-type = ["cdylib"]
[dependencies]
crc32c = {version = "0.6"}
crc32fast = {version = "1.2", features = ["nightly"]}
global_alloc = {path = "../../crates/alloc"}
napi = "1"
napi-derive = "1"

[target.'cfg(all(target_arch = "x86_64", not(target_env = "musl")))'.dependencies]
mimalloc = {version = "0.1"}

[build-dependencies]
napi-build = "1"
22 changes: 7 additions & 15 deletions packages/crc32/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
#![deny(clippy::all)]
#![allow(clippy::nonstandard_macro_braces)]

#[macro_use]
extern crate napi_derive;
/// Explicit extern crate to use allocator.
extern crate global_alloc;

use crc32c::crc32c_append;
use crc32fast::Hasher;
use napi::{CallContext, JsBuffer, JsNumber, JsObject, Result};
use std::convert::TryInto;

#[cfg(all(
target_arch = "x86_64",
not(target_env = "musl"),
not(debug_assertions)
))]
#[global_allocator]
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
use napi_derive::*;

#[module_exports]
fn init(mut exports: JsObject) -> Result<()> {
Expand All @@ -27,16 +19,16 @@ fn init(mut exports: JsObject) -> Result<()> {
#[js_function(2)]
fn crc32c(ctx: CallContext) -> Result<JsNumber> {
let input_data = ctx.get::<JsBuffer>(0)?.into_value()?;
let init_state = ctx.get::<JsNumber>(1)?;
let result = crc32c_append(init_state.try_into()?, &input_data);
let init_state = ctx.get::<JsNumber>(1)?.get_uint32()?;
let result = crc32c_append(init_state, &input_data);
ctx.env.create_uint32(result)
}

#[js_function(2)]
fn crc32(ctx: CallContext) -> Result<JsNumber> {
let input_data = ctx.get::<JsBuffer>(0)?.into_value()?;
let init_state = ctx.get::<JsNumber>(1)?;
let mut hasher = Hasher::new_with_initial(init_state.try_into()?);
let init_state = ctx.get::<JsNumber>(1)?.get_uint32()?;
let mut hasher = Hasher::new_with_initial(init_state);
hasher.update(&input_data);
ctx.env.create_uint32(hasher.finalize())
}
Loading