Skip to content

Commit 8cd9375

Browse files
committed
ci: add example build test
1 parent 645efa2 commit 8cd9375

File tree

10 files changed

+1387
-2
lines changed

10 files changed

+1387
-2
lines changed

.github/workflows/ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,69 @@ jobs:
102102

103103
- name: 'Check documentation links in `libmimalloc-sys`'
104104
run: cargo rustdoc -p libmimalloc-sys2 -- -D warnings
105+
106+
build-example:
107+
name: Build example
108+
strategy:
109+
matrix:
110+
settings:
111+
- host: macos-latest
112+
target: x86_64-apple-darwin
113+
- host: windows-latest
114+
target: x86_64-pc-windows-msvc
115+
- host: windows-latest
116+
target: i686-pc-windows-msvc
117+
- host: ubuntu-latest
118+
target: x86_64-unknown-linux-gnu
119+
- host: ubuntu-latest
120+
target: x86_64-unknown-linux-musl
121+
- host: macos-latest
122+
target: aarch64-apple-darwin
123+
- host: ubuntu-24.04-arm
124+
target: aarch64-unknown-linux-gnu
125+
- host: ubuntu-latest
126+
target: armv7-unknown-linux-gnueabihf
127+
- host: ubuntu-latest
128+
target: aarch64-linux-android
129+
- host: ubuntu-latest
130+
target: armv7-linux-androideabi
131+
- host: ubuntu-24.04-arm
132+
target: aarch64-unknown-linux-musl
133+
- host: windows-latest
134+
target: aarch64-pc-windows-msvc
135+
- host: ubuntu-latest
136+
target: powerpc64le-unknown-linux-gnu
137+
- host: ubuntu-latest
138+
target: s390x-unknown-linux-gnu
139+
- host: ubuntu-latest
140+
target: wasm32-wasip1-threads
141+
142+
runs-on: ${{ matrix.settings.host }}
143+
144+
steps:
145+
- uses: actions/checkout@v4
146+
with:
147+
submodules: recursive
148+
149+
- name: Install
150+
run: rustup target add ${{ matrix.settings.target }}
151+
152+
- uses: actions/setup-node@v4
153+
with:
154+
node-version: 22
155+
cache: yarn
156+
157+
- name: Install dependencies
158+
working-directory: example
159+
run: yarn install
160+
161+
- name: Build
162+
working-directory: example
163+
run: |
164+
if [[ "${{ matrix.settings.target }}" == *"musl"* ]]; then
165+
yarn build --target ${{ matrix.settings.target }} -x
166+
elif [[ "${{ matrix.settings.target }}" == *"gnu"* ]]; then
167+
yarn build --target ${{ matrix.settings.target }} --use-napi-cross
168+
else
169+
yarn build --target ${{ matrix.settings.target }}
170+
fi

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ license = "MIT"
1616
readme = "README.md"
1717

1818
[workspace]
19-
members = ["libmimalloc-sys", "libmimalloc-sys/sys-test"]
19+
members = ["libmimalloc-sys", "libmimalloc-sys/sys-test", "example"]
2020

2121
[badges]
2222
travis-ci = { repository = "purpleprotocol/mimalloc_rust" }

example/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.yarn
3+
*.node
4+
*.wasm

example/.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

example/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "mimalloc_example"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[lib]
7+
crate-type = ["cdylib", "lib"]
8+
9+
[dependencies]
10+
napi = "3.0.0-alpha"
11+
napi-derive = "3.0.0-alpha"
12+
mimalloc-safe = { path = "../" }
13+
14+
[build-dependencies]
15+
napi-build = "2"

example/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
napi_build::setup();
3+
}

example/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "mimalloc-example",
3+
"private": true,
4+
"scripts": {
5+
"build": "napi build"
6+
},
7+
"devDependencies": {
8+
"@napi-rs/cli": "canary"
9+
},
10+
"packageManager": "[email protected]"
11+
}

example/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[global_allocator]
2+
static ALLOC: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc;
3+
4+
#[unsafe(no_mangle)]
5+
pub unsafe extern "C" fn alloc_test() {
6+
let v = vec![0; 1000];
7+
println!("v: {:?}", v);
8+
}

0 commit comments

Comments
 (0)