Skip to content

Commit 4d6a486

Browse files
authored
ci: add example build test (#2)
1 parent 645efa2 commit 4d6a486

File tree

10 files changed

+1420
-2
lines changed

10 files changed

+1420
-2
lines changed

.github/workflows/ci.yml

Lines changed: 93 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,94 @@ 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 ${{ matrix.settings.target }}
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-24.04-arm
133+
target: aarch64-unknown-linux-musl
134+
- host: windows-latest
135+
target: aarch64-pc-windows-msvc
136+
- host: ubuntu-latest
137+
target: powerpc64le-unknown-linux-gnu
138+
- host: ubuntu-latest
139+
target: s390x-unknown-linux-gnu
140+
- host: ubuntu-latest
141+
target: wasm32-wasip1-threads
142+
143+
runs-on: ${{ matrix.settings.host }}
144+
145+
steps:
146+
- uses: actions/checkout@v4
147+
with:
148+
submodules: recursive
149+
150+
- name: Install
151+
run: rustup target add ${{ matrix.settings.target }}
152+
153+
- uses: goto-bus-stop/setup-zig@v2
154+
if: ${{ contains(matrix.settings.target, 'musl') }}
155+
with:
156+
version: 0.14.0
157+
158+
- name: Install cargo-zigbuild
159+
uses: taiki-e/install-action@v2
160+
if: ${{ contains(matrix.settings.target, 'musl') }}
161+
env:
162+
GITHUB_TOKEN: ${{ github.token }}
163+
with:
164+
tool: cargo-zigbuild
165+
166+
- uses: actions/setup-node@v4
167+
with:
168+
node-version: 22
169+
170+
- name: Install dependencies
171+
working-directory: example
172+
run: |
173+
corepack enable
174+
yarn install
175+
176+
- name: Install wasi-sdk
177+
run: |
178+
mkdir -p $HOME/wasi-sdk
179+
curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz | tar -xzf - -C $HOME/wasi-sdk --strip-components=1
180+
echo "WASI_SDK_PATH=$HOME/wasi-sdk" >> $GITHUB_ENV
181+
182+
- name: Build
183+
working-directory: example
184+
shell: bash
185+
run: |
186+
if [[ "${{ matrix.settings.target }}" == *"musl"* ]]; then
187+
yarn build --target ${{ matrix.settings.target }} -x
188+
yarn build --target ${{ matrix.settings.target }} -x --release
189+
elif [[ "${{ matrix.settings.target }}" == *"gnu"* ]]; then
190+
export CFLAGS="-fuse-ld=lld"
191+
export CC=clang
192+
yarn build --target ${{ matrix.settings.target }} --use-napi-cross
193+
yarn build --target ${{ matrix.settings.target }} --use-napi-cross --release
194+
else
195+
yarn build --target ${{ matrix.settings.target }}
196+
yarn build --target ${{ matrix.settings.target }} --release
197+
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
13+
[target.'cfg(target_os = "linux")'.dependencies]
14+
mimalloc-safe = { path = "../", features = ["local_dynamic_tls", "skip_collect_on_exit"] }
15+
16+
[target.'cfg(not(target_os = "linux"))'.dependencies]
17+
mimalloc-safe = { path = "../", features = ["skip_collect_on_exit"] }
18+
19+
[build-dependencies]
20+
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)