-
Notifications
You must be signed in to change notification settings - Fork 130
273 lines (227 loc) · 7.74 KB
/
Copy pathbuild.yml
File metadata and controls
273 lines (227 loc) · 7.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
name: Build native binaries
on:
push:
branches: [main, staging]
pull_request:
branches: [main, staging]
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
# ── CPU builds ──
- target: x86_64-apple-darwin
os: macos-14
suffix: darwin-x64
lib_ext: dylib
feature: cpu
- target: aarch64-apple-darwin
os: macos-14
suffix: darwin-arm64
lib_ext: dylib
feature: cpu
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
suffix: linux-x64-gnu
lib_ext: so
feature: cpu
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
suffix: linux-arm64-gnu
lib_ext: so
feature: cpu
cross: true
- target: x86_64-pc-windows-msvc
os: windows-latest
suffix: win32-x64-msvc
lib_ext: dll
feature: cpu
# ── WebGPU builds ──
- target: aarch64-apple-darwin
os: macos-14
suffix: darwin-arm64-webgpu
lib_ext: dylib
feature: webgpu
- target: x86_64-apple-darwin
os: macos-14
suffix: darwin-x64-webgpu
lib_ext: dylib
feature: webgpu
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
suffix: linux-x64-gnu-webgpu
lib_ext: so
feature: webgpu
- target: x86_64-pc-windows-msvc
os: windows-latest
suffix: win32-x64-msvc-webgpu
lib_ext: dll
feature: webgpu
runs-on: ${{ matrix.os }}
name: Build ${{ matrix.suffix }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools (Linux ARM64)
if: matrix.cross
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: Install Vulkan SDK (Linux WebGPU)
if: matrix.feature == 'webgpu' && runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libvulkan-dev
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
src/native/target
key: cargo-${{ matrix.target }}-${{ matrix.feature }}-${{ hashFiles('src/native/Cargo.lock') }}
restore-keys: cargo-${{ matrix.target }}-${{ matrix.feature }}-
- name: Build native addon
working-directory: src/native
shell: bash
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: ${{ matrix.cross && 'aarch64-linux-gnu-gcc' || '' }}
run: |
cargo build --release --target ${{ matrix.target }} --no-default-features --features ${{ matrix.feature }}
- name: Copy binary
shell: bash
run: |
BINARY_NAME="mni-framework-native.${{ matrix.suffix }}.node"
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
cp "src/native/target/${{ matrix.target }}/release/mni_framework_native.dll" "npm/${{ matrix.suffix }}/$BINARY_NAME"
else
cp "src/native/target/${{ matrix.target }}/release/libmni_framework_native.${{ matrix.lib_ext }}" "npm/${{ matrix.suffix }}/$BINARY_NAME"
fi
ls -lh "npm/${{ matrix.suffix }}/$BINARY_NAME"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: native-${{ matrix.suffix }}
path: npm/${{ matrix.suffix }}/mni-framework-native.*.node
if-no-files-found: error
build-cuda:
runs-on: ubuntu-latest
name: Build linux-x64-gnu-cuda
container:
image: nvidia/cuda:12.8.1-devel-ubuntu24.04
steps:
- uses: actions/checkout@v4
- name: Install build tools and build CUDA addon
working-directory: src/native
run: |
apt-get update
apt-get install -y --no-install-recommends curl ca-certificates build-essential pkg-config
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path
. "$HOME/.cargo/env"
cargo build --release --no-default-features --features cuda
- name: Copy binary
run: |
cp src/native/target/release/libmni_framework_native.so npm/linux-x64-gnu-cuda/mni-framework-native.linux-x64-gnu-cuda.node
ls -lh npm/linux-x64-gnu-cuda/mni-framework-native.linux-x64-gnu-cuda.node
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: native-linux-x64-gnu-cuda
path: npm/linux-x64-gnu-cuda/mni-framework-native.*.node
if-no-files-found: error
build-cuda-windows:
runs-on: windows-latest
name: Build win32-x64-msvc-cuda
steps:
- uses: actions/checkout@v4
- name: Install CUDA Toolkit
uses: Jimver/cuda-toolkit@v0.2.35
id: cuda-toolkit
with:
cuda: '12.6.3'
method: 'network'
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-pc-windows-msvc
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
src/native/target
key: cargo-x86_64-pc-windows-msvc-cuda-${{ hashFiles('src/native/Cargo.lock') }}
restore-keys: cargo-x86_64-pc-windows-msvc-cuda-
- name: Build CUDA addon
working-directory: src/native
shell: bash
run: cargo build --release --target x86_64-pc-windows-msvc --no-default-features --features cuda
- name: Copy binary
shell: bash
run: |
cp src/native/target/x86_64-pc-windows-msvc/release/mni_framework_native.dll npm/win32-x64-msvc-cuda/mni-framework-native.win32-x64-msvc-cuda.node
ls -lh npm/win32-x64-msvc-cuda/mni-framework-native.win32-x64-msvc-cuda.node
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: native-win32-x64-msvc-cuda
path: npm/win32-x64-msvc-cuda/mni-framework-native.*.node
if-no-files-found: error
test:
needs: build
if: ${{ !cancelled() }}
strategy:
fail-fast: false
matrix:
include:
- os: macos-14
suffix: darwin-arm64
artifact: native-darwin-arm64
- os: ubuntu-latest
suffix: linux-x64-gnu
artifact: native-linux-x64-gnu
- os: windows-latest
suffix: win32-x64-msvc
artifact: native-win32-x64-msvc
runs-on: ${{ matrix.os }}
name: Test ${{ matrix.suffix }}
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Download binary
uses: actions/download-artifact@v4
with:
name: ${{ matrix.artifact }}
path: src/native/
- name: List downloaded binary
working-directory: src/native
shell: bash
run: ls -lh *.node
- name: Install dependencies and build TypeScript
shell: bash
run: |
npm install --no-optional
npx tsc
- name: Run tests
run: npm test