| 1 | // @neon/config-runtime 1.6.1, dist/lib/native-packages.js: RUNTIME_TARGET. |
| 2 | export const neonRuntimeTarget = { |
| 3 | os: "linux", |
| 4 | cpu: "arm64", |
| 5 | libc: "glibc", |
| 6 | } as const; |
| 7 | |
| 8 | export const nativeArtifactError = ( |
| 9 | file: string, |
| 10 | content: Uint8Array, |
| 11 | ): string | undefined => { |
| 12 | const elf = |
| 13 | content[0] === 0x7f && |
| 14 | content[1] === 0x45 && |
| 15 | content[2] === 0x4c && |
| 16 | content[3] === 0x46; |
| 17 | const magic = |
| 18 | ((content[0]! << 24) | |
| 19 | (content[1]! << 16) | |
| 20 | (content[2]! << 8) | |
| 21 | content[3]!) >>> |
| 22 | 0; |
| 23 | if (elf) { |
| 24 | // Header checks reject incompatible targets; addon ABI still needs runtime verification. |
| 25 | if ( |
| 26 | content.length < 64 || |
| 27 | content[4] !== 2 || |
| 28 | content[5] !== 1 || |
| 29 | content[6] !== 1 || |
| 30 | ![0, 3].includes(content[7]!) || |
| 31 | ![2, 3].includes(content[16]!) || |
| 32 | content[17] !== 0 || |
| 33 | content[18] !== 183 || |
| 34 | content[19] !== 0 || |
| 35 | Buffer.from(content).includes(Buffer.from("ld-musl-")) |
| 36 | ) |
| 37 | return `Native file is not Linux ARM64 glibc compatible: ${file}.`; |
| 38 | } else if ( |
| 39 | /\.(?:node|dylib|dll|so(?:\.\d+)*)$/.test(file) || |
| 40 | [ |
| 41 | 0xfeedface, 0xfeedfacf, 0xcefaedfe, 0xcffaedfe, 0xcafebabe, 0xbebafeca, |
| 42 | ].includes(magic) || |
| 43 | (content[0] === 0x4d && content[1] === 0x5a) |
| 44 | ) |
| 45 | return `Unsupported native format: ${file}. Expected Linux ARM64 glibc.`; |
| 46 | }; |