Skip to content

Commit 0d404ed

Browse files
authored
feat(napi): add mimalloc (#423)
1 parent a1582b2 commit 0d404ed

File tree

4 files changed

+48
-64
lines changed

4 files changed

+48
-64
lines changed

.github/workflows/release-napi.yml

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,22 @@ jobs:
5454
include:
5555
- os: windows-latest
5656
target: x86_64-pc-windows-msvc
57-
5857
- os: windows-latest
5958
target: aarch64-pc-windows-msvc
60-
6159
- os: ubuntu-latest
6260
target: x86_64-unknown-linux-gnu
63-
6461
- os: ubuntu-latest
6562
target: x86_64-unknown-linux-musl
66-
6763
- os: ubuntu-latest
6864
target: aarch64-unknown-linux-gnu
69-
7065
- os: ubuntu-latest
7166
target: aarch64-unknown-linux-musl
72-
7367
- os: ubuntu-latest
7468
target: armv7-unknown-linux-gnueabihf
75-
7669
- os: macos-latest
7770
target: x86_64-apple-darwin
78-
7971
- os: macos-latest
8072
target: aarch64-apple-darwin
81-
8273
- os: ubuntu-latest
8374
target: wasm32-wasip1-threads
8475

@@ -89,8 +80,7 @@ jobs:
8980

9081
- uses: ./.github/actions/pnpm
9182

92-
- name: Add Rust Target
93-
run: rustup target add ${{ matrix.target }}
83+
- run: rustup target add ${{ matrix.target }}
9484

9585
- uses: goto-bus-stop/setup-zig@abea47f85e598557f500fa1fd2ab7464fcb39406 # v2.2.1
9686
if: ${{ contains(matrix.target, 'musl') }}
@@ -103,58 +93,16 @@ jobs:
10393

10494
- name: Build with napi cross
10595
if: ${{ contains(matrix.target, 'gnu') }}
96+
env:
97+
CC: clang # for mimalloc
10698
run: pnpm build --use-napi-cross --target ${{ matrix.target }}
10799

108100
- name: Build
109101
if: ${{ !contains(matrix.target, 'gnu') && !contains(matrix.target, 'musl') }}
102+
env:
103+
CC: clang # for mimalloc
110104
run: pnpm build --target ${{ matrix.target }}
111105

112-
- name: Test
113-
# if: matrix.target == 'x86_64-pc-windows-msvc' || matrix.target == 'aarch64-apple-darwin' || matrix.target == 'wasm32-wasip1-threads'
114-
if: matrix.target == 'x86_64-unknown-linux-gnu'
115-
run: pnpm test
116-
117-
- name: Output docker params
118-
if: ${{ contains(matrix.target, 'linux') }}
119-
id: docker
120-
run: |
121-
node -e "
122-
if ('${{ matrix.target }}'.startsWith('aarch64')) {
123-
console.log('PLATFORM=linux/arm64')
124-
} else if ('${{ matrix.target }}'.startsWith('armv7')) {
125-
console.log('PLATFORM=linux/arm/v7')
126-
} else {
127-
console.log('PLATFORM=linux/amd64')
128-
}
129-
" >> $GITHUB_OUTPUT
130-
node -e "
131-
if ('${{ matrix.target }}'.endsWith('-musl')) {
132-
console.log('IMAGE=node:lts-alpine')
133-
} else {
134-
console.log('IMAGE=node:lts-slim')
135-
}
136-
" >> $GITHUB_OUTPUT
137-
echo "PNPM_STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
138-
139-
- name: Set up QEMU
140-
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
141-
if: ${{ contains(matrix.target, 'linux') }}
142-
with:
143-
platforms: all
144-
145-
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
146-
if: ${{ contains(matrix.target, 'linux') }}
147-
148-
- name: Run linux test
149-
uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 # v3
150-
if: false # ${{ contains(matrix.target, 'linux') }}
151-
with:
152-
image: ${{ steps.docker.outputs.IMAGE }}
153-
options: -v ${{ steps.docker.outputs.PNPM_STORE_PATH }}:${{ steps.docker.outputs.PNPM_STORE_PATH }} -v ${{ github.workspace }}:/oxc_resolver -w /oxc_resolver --platform ${{ steps.docker.outputs.PLATFORM }}
154-
run: |
155-
corepack enable
156-
pnpm test
157-
158106
- name: Upload artifacts
159107
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
160108
with:
@@ -184,7 +132,7 @@ jobs:
184132
environment_variables: "DEBUG RUSTUP_IO_THREADS"
185133
shell: bash
186134
run: |
187-
sudo pkg install -y -f curl libnghttp2 node22 npm
135+
sudo pkg install -y -f curl libnghttp2 node22 npm cmake
188136
curl https://sh.rustup.rs -sSf --output rustup.sh
189137
sh rustup.sh -y --profile minimal --default-toolchain stable
190138
source "$HOME/.cargo/env"

Cargo.lock

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

napi/Cargo.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
[package]
22
name = "oxc_napi_resolver"
33
version = "0.0.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
6-
rust-version = "1.71"
6+
rust-version = "1.85.0"
77

88
[lib]
99
crate-type = ["cdylib"]
1010
test = false
1111
doctest = false
1212

1313
[dependencies]
14+
oxc_resolver = { path = ".." }
15+
1416
napi = { version = "3.0.0-alpha", default-features = false, features = ["napi3", "serde-json"] }
1517
napi-derive = { version = "3.0.0-alpha" }
16-
oxc_resolver = { path = ".." }
1718
tracing-subscriber = { version = "0.3.18", default-features = false, features = ["std", "fmt"] } # Omit the `regex` feature
1819

20+
[target.'cfg(all(not(target_os = "linux"), not(target_os = "freebsd"), not(target_arch = "arm"), not(target_family = "wasm")))'.dependencies]
21+
mimalloc-safe = { version = "0.1.49", features = ["skip_collect_on_exit"] }
22+
23+
[target.'cfg(any(all(target_os = "linux", not(target_arch = "arm")), target_os = "freebsd"))'.dependencies]
24+
mimalloc-safe = { version = "0.1.49", features = ["skip_collect_on_exit", "local_dynamic_tls"] }
25+
1926
[build-dependencies]
2027
napi-build = "2.1.3"

napi/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
extern crate napi;
2-
extern crate napi_derive;
3-
extern crate oxc_resolver;
1+
#[cfg(all(not(target_arch = "arm"), not(target_family = "wasm")))]
2+
#[global_allocator]
3+
static ALLOC: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc;
44

55
use std::{
66
path::{Path, PathBuf},

0 commit comments

Comments
 (0)