Skip to content

Commit ddaea6f

Browse files
authored
Add gnu->musl loader fallback via @napi-rs/cli patch
Mirror PR #7's approach (which added the linux-ia32-gnu branch by patching the napi-rs loader template) and add a gnu->musl fallback the same way, instead of the runtime regex string-rewrite that was in strip-binding-fallbacks.js. The generated loader picks gnu vs musl purely by libc *family* (isMusl()), with no glibc-version check. On a glibc host whose system glibc is older than what our gnu prebuild was linked against, requiring ./index.linux-<arch>-gnu.node throws (e.g. GLIBC_2.33 not found) and the loader gives up — even though we also bundle a statically-linked musl binary that runs fine on glibc hosts. This patches @napi-rs/cli's requireNative() template so the linux x64 and arm64 gnu (else) branches also try ./index.linux-<arch>-musl.node after the gnu require fails, using the generator's own requireTuple() helper so the emitted code matches the generated style exactly. Because the fallback is baked into the template at install time, the generated binding.js comes out correct on every build regardless of how many times the build runs — avoiding the docker+host double-pass idempotency problem that affected the regex post-processor.
1 parent 0140d1a commit ddaea6f

1 file changed

Lines changed: 51 additions & 6 deletions

File tree

.yarn/patches/@napi-rs-cli-npm-3.6.2-b710c59d43.patch

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
diff --git a/dist/cli.js b/dist/cli.js
2-
index 5787d8d0398b48987f9e59a628770259cf9c830c..260f2a7f742c3a14fbabb7b67c6121311a99a703 100755
2+
index 5787d8d..2cb0557 100755
33
--- a/dist/cli.js
44
+++ b/dist/cli.js
5-
@@ -802,6 +802,8 @@ function requireNative() {
5+
@@ -773,12 +773,14 @@ function requireNative() {
6+
${requireTuple("linux-x64-musl", 10)}
7+
} else {
8+
${requireTuple("linux-x64-gnu", 10)}
9+
+ ${requireTuple("linux-x64-musl", 10)}
10+
}
11+
} else if (process.arch === 'arm64') {
12+
if (isMusl()) {
13+
${requireTuple("linux-arm64-musl", 10)}
14+
} else {
15+
${requireTuple("linux-arm64-gnu", 10)}
16+
+ ${requireTuple("linux-arm64-musl", 10)}
17+
}
18+
} else if (process.arch === 'arm') {
19+
if (isMusl()) {
20+
@@ -802,6 +804,8 @@ function requireNative() {
621
${requireTuple("linux-ppc64-gnu")}
722
} else if (process.arch === 's390x') {
823
${requireTuple("linux-s390x-gnu")}
@@ -12,10 +27,25 @@ index 5787d8d0398b48987f9e59a628770259cf9c830c..260f2a7f742c3a14fbabb7b67c612131
1227
loadErrors.push(new Error(\`Unsupported architecture on Linux: \${process.arch}\`))
1328
}
1429
diff --git a/dist/index.cjs b/dist/index.cjs
15-
index 8f467564ab9b95d009c562cb9a78aa513b6d2bb2..291d75aca1095ce67e80ced2de16b5cd59c161c0 100644
30+
index 8f46756..ac31f59 100644
1631
--- a/dist/index.cjs
1732
+++ b/dist/index.cjs
18-
@@ -827,6 +827,8 @@ function requireNative() {
33+
@@ -798,12 +798,14 @@ function requireNative() {
34+
${requireTuple("linux-x64-musl", 10)}
35+
} else {
36+
${requireTuple("linux-x64-gnu", 10)}
37+
+ ${requireTuple("linux-x64-musl", 10)}
38+
}
39+
} else if (process.arch === 'arm64') {
40+
if (isMusl()) {
41+
${requireTuple("linux-arm64-musl", 10)}
42+
} else {
43+
${requireTuple("linux-arm64-gnu", 10)}
44+
+ ${requireTuple("linux-arm64-musl", 10)}
45+
}
46+
} else if (process.arch === 'arm') {
47+
if (isMusl()) {
48+
@@ -827,6 +829,8 @@ function requireNative() {
1949
${requireTuple("linux-ppc64-gnu")}
2050
} else if (process.arch === 's390x') {
2151
${requireTuple("linux-s390x-gnu")}
@@ -25,10 +55,25 @@ index 8f467564ab9b95d009c562cb9a78aa513b6d2bb2..291d75aca1095ce67e80ced2de16b5cd
2555
loadErrors.push(new Error(\`Unsupported architecture on Linux: \${process.arch}\`))
2656
}
2757
diff --git a/dist/index.js b/dist/index.js
28-
index e2bfc6368247a58ea3a712bb156e15b440bf139a..f74f13e7189be927cedbd4fd5ba9dd4ca335e6f9 100644
58+
index e2bfc63..263ceae 100644
2959
--- a/dist/index.js
3060
+++ b/dist/index.js
31-
@@ -801,6 +801,8 @@ function requireNative() {
61+
@@ -772,12 +772,14 @@ function requireNative() {
62+
${requireTuple("linux-x64-musl", 10)}
63+
} else {
64+
${requireTuple("linux-x64-gnu", 10)}
65+
+ ${requireTuple("linux-x64-musl", 10)}
66+
}
67+
} else if (process.arch === 'arm64') {
68+
if (isMusl()) {
69+
${requireTuple("linux-arm64-musl", 10)}
70+
} else {
71+
${requireTuple("linux-arm64-gnu", 10)}
72+
+ ${requireTuple("linux-arm64-musl", 10)}
73+
}
74+
} else if (process.arch === 'arm') {
75+
if (isMusl()) {
76+
@@ -801,6 +803,8 @@ function requireNative() {
3277
${requireTuple("linux-ppc64-gnu")}
3378
} else if (process.arch === 's390x') {
3479
${requireTuple("linux-s390x-gnu")}

0 commit comments

Comments
 (0)