Skip to content

Commit 6fc46b4

Browse files
committed
ci: add example build test
1 parent 645efa2 commit 6fc46b4

File tree

10 files changed

+1396
-2
lines changed

10 files changed

+1396
-2
lines changed

.github/workflows/ci.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: CI
22

33
on:
44
push:
5+
branches:
6+
- main
57
pull_request:
68
# Run daily to catch when Rust updates cause problems to happen.
79
schedule:
@@ -102,3 +104,75 @@ jobs:
102104

103105
- name: 'Check documentation links in `libmimalloc-sys`'
104106
run: cargo rustdoc -p libmimalloc-sys2 -- -D warnings
107+
108+
build-example:
109+
name: Build example
110+
strategy:
111+
fail-fast: false
112+
matrix:
113+
settings:
114+
- host: macos-latest
115+
target: x86_64-apple-darwin
116+
- host: windows-latest
117+
target: x86_64-pc-windows-msvc
118+
- host: windows-latest
119+
target: i686-pc-windows-msvc
120+
- host: ubuntu-latest
121+
target: x86_64-unknown-linux-gnu
122+
- host: ubuntu-latest
123+
target: x86_64-unknown-linux-musl
124+
- host: macos-latest
125+
target: aarch64-apple-darwin
126+
- host: ubuntu-24.04-arm
127+
target: aarch64-unknown-linux-gnu
128+
- host: ubuntu-latest
129+
target: armv7-unknown-linux-gnueabihf
130+
- host: ubuntu-latest
131+
target: aarch64-linux-android
132+
- host: ubuntu-latest
133+
target: armv7-linux-androideabi
134+
- host: ubuntu-24.04-arm
135+
target: aarch64-unknown-linux-musl
136+
- host: windows-latest
137+
target: aarch64-pc-windows-msvc
138+
- host: ubuntu-latest
139+
target: powerpc64le-unknown-linux-gnu
140+
- host: ubuntu-latest
141+
target: s390x-unknown-linux-gnu
142+
- host: ubuntu-latest
143+
target: wasm32-wasip1-threads
144+
145+
runs-on: ${{ matrix.settings.host }}
146+
147+
steps:
148+
- uses: actions/checkout@v4
149+
with:
150+
submodules: recursive
151+
152+
- name: Install
153+
run: rustup target add ${{ matrix.settings.target }}
154+
155+
- name: Enable corepack
156+
working-directory: example
157+
run: corepack enable
158+
159+
- uses: actions/setup-node@v4
160+
with:
161+
node-version: 22
162+
cache: yarn
163+
cache-dependency-path: example/yarn.lock
164+
165+
- name: Install dependencies
166+
working-directory: example
167+
run: yarn install
168+
169+
- name: Build
170+
working-directory: example
171+
run: |
172+
if [[ "${{ matrix.settings.target }}" == *"musl"* ]]; then
173+
yarn build --target ${{ matrix.settings.target }} -x
174+
elif [[ "${{ matrix.settings.target }}" == *"gnu"* ]]; then
175+
yarn build --target ${{ matrix.settings.target }} --use-napi-cross
176+
else
177+
yarn build --target ${{ matrix.settings.target }}
178+
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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use napi_derive::napi;
2+
3+
#[global_allocator]
4+
static ALLOC: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc;
5+
6+
#[napi]
7+
pub fn hello() -> String {
8+
"Hello, world!".to_string()
9+
}

0 commit comments

Comments
 (0)