Skip to content

Commit e488d9d

Browse files
szegediclaude
andauthored
Add node-gyp-build-major parameter to support v4 naming convention (#90)
* Add node-gyp-build-major parameter to support v4 naming convention node-gyp-build v4 changed prebuild naming from: prebuilds/${platform}${libc}-${arch}/node-${abi}.node to a tag-based convention: prebuilds/${platform}-${arch}/${name}[.musl].node.[napi|abi${N}].node Add NODE_GYP_BUILD_MAJOR (default: 3) to prebuild/index.js, exposed as node-gyp-build-major workflow input. When set to 4: - Directory: platform-arch (no libc suffix; glibc is assumed by default) - Filename: name[.musl].node.[napi|abi${N}].node (libc encoded as tag) - Artifact upload uses prebuilds/**/* to match the new directory names Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Pin action references to support-node-gyp-build-v4 branch SHA Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix lint: use single quotes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Pin action references to updated branch SHA Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Restore action SHA pins to main Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b9488a5 commit e488d9d

3 files changed

Lines changed: 51 additions & 5 deletions

File tree

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ on:
6868
default: 12
6969
required: false
7070
type: number
71+
node-gyp-build-major:
72+
description: Major version of node-gyp-build used by the package (3 or 4). Controls the prebuild directory and filename naming convention.
73+
default: 3
74+
required: false
75+
type: number
7176

7277
concurrency:
7378
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
@@ -86,6 +91,7 @@ env:
8691
GYP: ${{ !inputs.napi && !inputs.napi-rs && !inputs.neon && !inputs.rust }}
8792
DIRECTORY_PATH: ${{ inputs.directory-path }}
8893
NODE_VERSIONS: '>=${{ inputs.min-node-version }}'
94+
NODE_GYP_BUILD_MAJOR: ${{ inputs.node-gyp-build-major }}
8995

9096
jobs:
9197
versions:

prebuild/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ runs:
5454
-e NODE_VERSIONS="$NODE_VERSIONS" \
5555
-e NODE_HEADERS_DIRECTORY="/usr/node_headers" \
5656
-e LIBC="$LIBC" \
57+
-e NODE_GYP_BUILD_MAJOR="$NODE_GYP_BUILD_MAJOR" \
5758
-w /usr/action \
5859
$DOCKER_BUILDER \
5960
/bin/bash -c 'yarn && cd /usr/workspace && yarn exec node /usr/action'
@@ -64,3 +65,10 @@ runs:
6465
name: prebuilds-${{ github.job }}
6566
if-no-files-found: ignore
6667
path: ${{ env.DIRECTORY_PATH }}/prebuilds/**/${{ env.PREBUILDS_DIR || github.job }}/*
68+
if: ${{ env.NODE_GYP_BUILD_MAJOR != '4' }}
69+
- uses: actions/upload-artifact@v4
70+
with:
71+
name: prebuilds-${{ github.job }}
72+
if-no-files-found: ignore
73+
path: ${{ env.DIRECTORY_PATH }}/prebuilds/**/*
74+
if: ${{ env.NODE_GYP_BUILD_MAJOR == '4' }}

prebuild/index.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,41 @@ const {
2424
PREBUILD = '',
2525
DIRECTORY_PATH = '.',
2626
TARGET_NAME = 'addon',
27-
NODE_HEADERS_DIRECTORY = path.join(os.tmpdir(), 'prebuilds')
27+
NODE_HEADERS_DIRECTORY = path.join(os.tmpdir(), 'prebuilds'),
28+
NODE_GYP_BUILD_MAJOR = '3'
2829
} = process.env
2930

31+
// Prebuild directory and filename conventions differ between node-gyp-build v3 and v4:
32+
//
33+
// v3: prebuilds/${platform}${libc}-${arch}/node-${abi}.node
34+
// e.g. prebuilds/linuxglibc-arm64/node-115.node
35+
//
36+
// v4: prebuilds/${platform}-${arch}/${TARGET_NAME}[.musl].node.[napi|abi${N}].node
37+
// e.g. prebuilds/linux-arm64/dd_pprof.node.abi115.node
38+
// prebuilds/linux-arm64/dd_pprof.musl.node.napi.node
39+
//
40+
// When NODE_GYP_BUILD_MAJOR=4, libc is encoded as a filename tag ('musl' only;
41+
// glibc is the default and needs no tag) rather than in the directory name.
42+
43+
function prebuildDir () {
44+
if (NODE_GYP_BUILD_MAJOR === '4') {
45+
return `${DIRECTORY_PATH}/prebuilds/${platform}-${arch}`
46+
}
47+
return `${DIRECTORY_PATH}/prebuilds/${platform}${libc}-${arch}`
48+
}
49+
50+
function prebuildFilename (abi, baseName) {
51+
if (NODE_GYP_BUILD_MAJOR === '4') {
52+
const libcTag = libc === 'musl' ? '.musl' : ''
53+
const abiTag = abi === 'napi' ? '.napi' : `.abi${abi}`
54+
return `${baseName}${libcTag}.node${abiTag}.node`
55+
}
56+
if (abi === 'napi') {
57+
return 'node-napi.node'
58+
}
59+
return `node-${abi}.node`
60+
}
61+
3062
let alpineVersion
3163
if (platform === 'linux' && libc === 'musl') {
3264
try {
@@ -57,7 +89,7 @@ prebuildify()
5789

5890
function prebuildify () {
5991
fs.mkdirSync(NODE_HEADERS_DIRECTORY, { recursive: true })
60-
fs.mkdirSync(`${DIRECTORY_PATH}/prebuilds/${platform}${libc}-${arch}`, { recursive: true })
92+
fs.mkdirSync(prebuildDir(), { recursive: true })
6193

6294
if (PREBUILD) {
6395
execSync(PREBUILD, { cwd, stdio, shell })
@@ -124,13 +156,13 @@ function prebuildTarget (arch, target) {
124156
const names = fs.readdirSync(`${DIRECTORY_PATH}/build/Release`)
125157

126158
for (const name of names) {
127-
const output = `${DIRECTORY_PATH}/prebuilds/${platform}${libc}-${arch}/${name}`
128-
.replace('.node', `-${target.abi}.node`)
159+
const baseName = name.replace(/\.node$/, '')
160+
const output = `${prebuildDir()}/${prebuildFilename(target.abi, baseName)}`
129161

130162
fs.copyFileSync(`${DIRECTORY_PATH}/build/Release/${name}`, output)
131163
}
132164
} else {
133-
const output = `${DIRECTORY_PATH}/prebuilds/${platform}${libc}-${arch}/node-${target.abi}.node`
165+
const output = `${prebuildDir()}/${prebuildFilename(target.abi, TARGET_NAME)}`
134166
const input = NAPI_RS === 'true'
135167
? `${DIRECTORY_PATH}/${TARGET_NAME}.node`
136168
: `${DIRECTORY_PATH}/build/Release/${TARGET_NAME}.node`

0 commit comments

Comments
 (0)