-
Notifications
You must be signed in to change notification settings - Fork 0
346 lines (296 loc) · 12.3 KB
/
Copy pathbuild.yml
File metadata and controls
346 lines (296 loc) · 12.3 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
name: Build libnode
on:
push:
branches: [main]
workflow_dispatch:
inputs:
node_version:
description: 'Node.js version (e.g., 22.13.0). Leave empty for latest LTS.'
required: false
default: ''
force_rebuild:
description: 'Force rebuild even if release exists'
required: false
default: 'false'
type: choice
options:
- 'false'
- 'true'
include_x86:
description: 'Include Windows x86 build (not supported on Node >= 25)'
required: false
default: 'false'
type: choice
options:
- 'false'
- 'true'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
NODE_LTS_MAJOR: 22
jobs:
resolve-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.resolve.outputs.version }}
skip_build: ${{ steps.decide.outputs.skip_build }}
steps:
- name: Resolve Node.js version
id: resolve
run: |
if [ -n "${{ github.event.inputs.node_version }}" ]; then
VERSION="${{ github.event.inputs.node_version }}"
else
VERSION=$(curl -s https://nodejs.org/dist/index.json | jq -r '[.[] | select(.lts != false) | select(.version | startswith("v${{ env.NODE_LTS_MAJOR }}"))][0].version' | sed 's/^v//')
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Resolved Node.js version: $VERSION"
- name: Check if release already exists
id: check_release
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ steps.resolve.outputs.version }}"
TAG="libnode-v${VERSION}"
if gh release view "$TAG" --repo ${{ github.repository }} > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "::notice::Release $TAG already exists"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "::notice::Release $TAG does not exist, will build"
fi
- name: Decide what to build
id: decide
run: |
FORCE="${{ github.event.inputs.force_rebuild }}"
EXISTS="${{ steps.check_release.outputs.exists }}"
if [ "$EXISTS" == "true" ] && [ "$FORCE" != "true" ]; then
echo "skip_build=true" >> $GITHUB_OUTPUT
echo "::warning::Skipping build - release already exists"
else
echo "skip_build=false" >> $GITHUB_OUTPUT
fi
build-windows:
needs: resolve-version
if: needs.resolve-version.outputs.skip_build != 'true'
runs-on: windows-latest
strategy:
matrix:
arch:
- x64
include: ${{ github.event.inputs.include_x86 == 'true' && fromJson('[{"arch":"x86"}]') || fromJson('[]') }}
steps:
- name: Free disk space
shell: pwsh
run: |
$dirs = @(
"C:\hostedtoolcache\CodeQL",
"C:\hostedtoolcache\Java_Temurin-Hotspot_jdk",
"C:\hostedtoolcache\Ruby",
"C:\hostedtoolcache\go",
"C:\mingw64",
"C:\Program Files\dotnet\sdk",
"C:\Program Files\dotnet\shared"
)
foreach ($d in $dirs) {
if (Test-Path $d) { Remove-Item -Recurse -Force $d -ErrorAction SilentlyContinue }
}
Get-PSDrive C | Select-Object Used,Free
- name: Install NASM
shell: pwsh
run: |
choco install nasm --no-progress -y --timeout 300
echo "C:\Program Files\NASM" >> $env:GITHUB_PATH
- name: Clone Node.js
run: |
git clone --depth 1 --branch v${{ needs.resolve-version.outputs.version }} https://github.com/nodejs/node.git node-src
- name: Build Node.js (shared library)
shell: cmd
run: |
cd node-src
set NUMBER_OF_PROCESSORS=2
call vcbuild.bat release dll ${{ matrix.arch }} full-icu
- name: Prepare artifacts
shell: pwsh
run: |
$version = "${{ needs.resolve-version.outputs.version }}"
$arch = "${{ matrix.arch }}"
$outDir = "libnode-v$version-win-$arch"
New-Item -ItemType Directory -Force -Path "$outDir/lib"
New-Item -ItemType Directory -Force -Path "$outDir/include"
New-Item -ItemType Directory -Force -Path "$outDir/bin"
# Copy libraries
Copy-Item "node-src/out/Release/libnode.dll" "$outDir/lib/"
Copy-Item "node-src/out/Release/libnode.lib" "$outDir/lib/"
Copy-Item "node-src/out/Release/lib/libuv.lib" "$outDir/lib/"
Copy-Item "node-src/out/Release/lib/v8_libbase.lib" "$outDir/lib/"
Copy-Item "node-src/out/Release/lib/v8_libplatform.lib" "$outDir/lib/"
# Copy abseil library (required by v8_libbase in V8 13+/Node.js 25+)
if (Test-Path "node-src/out/Release/lib/abseil.lib") {
Copy-Item "node-src/out/Release/lib/abseil.lib" "$outDir/lib/"
}
# Copy headers (top-level + all subdirectories containing .h files)
Copy-Item -Recurse "node-src/src/*.h" "$outDir/include/"
Get-ChildItem -Path "node-src/src" -Directory | ForEach-Object {
$hFiles = Get-ChildItem -Path $_.FullName -Filter "*.h" -ErrorAction SilentlyContinue
if ($hFiles) {
$subdir = $_.Name
New-Item -ItemType Directory -Force -Path "$outDir/include/$subdir" | Out-Null
Copy-Item "$($_.FullName)/*.h" "$outDir/include/$subdir/"
}
}
Copy-Item -Recurse "node-src/deps/v8/include/*" "$outDir/include/"
Copy-Item -Recurse "node-src/deps/uv/include/*" "$outDir/include/"
# Copy node executable
Copy-Item "node-src/out/Release/node.exe" "$outDir/bin/"
# Create zip
Compress-Archive -Path "$outDir" -DestinationPath "libnode-v$version-win-$arch.zip"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: libnode-win-${{ matrix.arch }}
path: libnode-v${{ needs.resolve-version.outputs.version }}-win-${{ matrix.arch }}.zip
build-macos:
needs: resolve-version
if: needs.resolve-version.outputs.skip_build != 'true'
runs-on: macos-15
steps:
- name: Clone Node.js
run: |
git clone --depth 1 --branch v${{ needs.resolve-version.outputs.version }} https://github.com/nodejs/node.git node-src
- name: Build Node.js (shared library)
run: |
cd node-src
./configure --shared --with-intl=full-icu
make -j$(sysctl -n hw.ncpu)
- name: Prepare artifacts
run: |
VERSION="${{ needs.resolve-version.outputs.version }}"
OUTDIR="libnode-v$VERSION-darwin-arm64"
mkdir -p "$OUTDIR/lib"
mkdir -p "$OUTDIR/include"
mkdir -p "$OUTDIR/bin"
# Copy libraries (dylib is versioned, e.g., libnode.127.dylib)
cp node-src/out/Release/libnode*.dylib "$OUTDIR/lib/"
# Create unversioned symlink for convenience
cd "$OUTDIR/lib" && ln -sf libnode.*.dylib libnode.dylib && cd -
# Copy headers (top-level + all subdirectories containing .h files)
cp node-src/src/*.h "$OUTDIR/include/"
find node-src/src -mindepth 1 -maxdepth 1 -type d | while IFS= read -r dir; do
if ls "$dir"/*.h &>/dev/null; then
subdir=$(basename "$dir")
mkdir -p "$OUTDIR/include/$subdir"
cp "$dir"/*.h "$OUTDIR/include/$subdir/"
fi
done
cp -R node-src/deps/v8/include/* "$OUTDIR/include/"
cp -R node-src/deps/uv/include/* "$OUTDIR/include/"
# Copy node executable
cp node-src/out/Release/node "$OUTDIR/bin/"
# Create tarball
tar -czvf "libnode-v$VERSION-darwin-arm64.tar.gz" "$OUTDIR"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: libnode-darwin-arm64
path: libnode-v${{ needs.resolve-version.outputs.version }}-darwin-arm64.tar.gz
build-linux:
needs: resolve-version
if: needs.resolve-version.outputs.skip_build != 'true'
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential python3
- name: Clone Node.js
run: |
git clone --depth 1 --branch v${{ needs.resolve-version.outputs.version }} https://github.com/nodejs/node.git node-src
- name: Build Node.js (shared library)
run: |
cd node-src
./configure --shared --with-intl=full-icu
make -j$(nproc)
- name: Prepare artifacts
run: |
VERSION="${{ needs.resolve-version.outputs.version }}"
OUTDIR="libnode-v$VERSION-linux-x64"
mkdir -p "$OUTDIR/lib"
mkdir -p "$OUTDIR/include"
mkdir -p "$OUTDIR/bin"
# Copy shared library
cp node-src/out/Release/lib.target/libnode.so* "$OUTDIR/lib/" || cp node-src/out/Release/libnode.so* "$OUTDIR/lib/"
# Copy static libraries
find node-src/out/Release -name "libuv.a" -exec cp {} "$OUTDIR/lib/" \;
find node-src/out/Release -name "v8_libbase.a" -exec cp {} "$OUTDIR/lib/" \;
find node-src/out/Release -name "v8_libplatform.a" -exec cp {} "$OUTDIR/lib/" \;
# Copy abseil library (required by v8_libbase in V8 13+/Node.js 25+)
find node-src/out/Release -name "libabseil.a" -exec cp {} "$OUTDIR/lib/" \; 2>/dev/null || true
# Copy headers (top-level + all subdirectories containing .h files)
cp node-src/src/*.h "$OUTDIR/include/"
find node-src/src -mindepth 1 -maxdepth 1 -type d | while IFS= read -r dir; do
if ls "$dir"/*.h &>/dev/null; then
subdir=$(basename "$dir")
mkdir -p "$OUTDIR/include/$subdir"
cp "$dir"/*.h "$OUTDIR/include/$subdir/"
fi
done
cp -R node-src/deps/v8/include/* "$OUTDIR/include/"
cp -R node-src/deps/uv/include/* "$OUTDIR/include/"
# Copy node executable
cp node-src/out/Release/node "$OUTDIR/bin/"
# Create tarball
tar -czvf "libnode-v$VERSION-linux-x64.tar.gz" "$OUTDIR"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: libnode-linux-x64
path: libnode-v${{ needs.resolve-version.outputs.version }}-linux-x64.tar.gz
release:
needs: [resolve-version, build-windows, build-macos, build-linux]
if: |
always() &&
needs.resolve-version.outputs.skip_build != 'true' &&
needs.build-windows.result == 'success' &&
needs.build-macos.result == 'success' &&
needs.build-linux.result == 'success'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: libnode-*
path: artifacts
- name: Create Release
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ needs.resolve-version.outputs.version }}"
TAG="libnode-v${VERSION}"
FILES=$(find artifacts -type f \( -name "*.zip" -o -name "*.tar.gz" \))
# Delete existing release if present (force rebuild case)
gh release delete "$TAG" --repo ${{ github.repository }} --yes 2>/dev/null || true
git push --delete origin "$TAG" 2>/dev/null || true
gh release create "$TAG" \
--repo ${{ github.repository }} \
--title "libnode v${VERSION}" \
--notes "Pre-built Node.js ${VERSION} libraries for embedding in C++ projects.
## Contents
### Windows (x64)
- libnode.dll / libnode.lib
- libuv.lib
- v8_libbase.lib, v8_libplatform.lib, abseil.lib
### macOS (arm64)
- libnode.*.dylib (versioned)
- libnode.dylib (symlink)
### Linux (x64)
- libnode.so
- libuv.a
- v8_libbase.a, v8_libplatform.a, libabseil.a
All archives include Node.js, V8, and libuv headers.
## Usage
Link against libnode and include the headers for full Node.js runtime embedding (require(), npm modules, async I/O, etc.)." \
$FILES