1+ import { execaCommandSync } from "execa" ;
2+ import * as buildUtils from "./utils.js" ;
3+ const { toString } = buildUtils ;
4+ function parserOptions ( ) {
5+ return {
6+ arch : toString ( process . env . npm_config_arch ) ?? process . arch ,
7+ } ;
8+ }
9+ async function main ( ) {
10+ const opts = parserOptions ( ) ;
11+ console . log ( "Building distribution binary with options " , opts ) ;
12+ const prebuildArch = getNodearch ( opts ) ;
13+ process . env . ARCH = prebuildArch ;
14+ process . env . npm_config_arch = prebuildArch ;
15+ process . env . npm_config_target_arch = prebuildArch ;
16+ process . env . PREBUILD_arch = prebuildArch ;
17+ // TODO test the triple feature
18+ if ( typeof process . env . TRIPLE === "string" ) {
19+ const TRIPLE = process . env . TRIPLE ;
20+ const GCC = process . env . GCC ;
21+ process . env . CC = `${ TRIPLE } -gcc-${ GCC } ` ;
22+ process . env . CXX = `${ TRIPLE } -g++-${ GCC } ` ;
23+ const STRIP = `${ TRIPLE } -strip` ;
24+ process . env . PREBUILD_STRIP_BIN = STRIP ;
25+ process . env . ZMQ_BUILD_OPTIONS = `--host=${ TRIPLE } ` ;
26+ }
27+ // use the current node version to build the prebuild
28+ // If the distribution for that particular architecture is not available, updated your Node:
29+ // https://nodejs.org/dist/
30+ const nodeVersion = process . version . replace ( "v" , "" ) ;
31+ let prebuildScript = `prebuildify --napi --arch=${ prebuildArch } --strip --tag-libc -t ${ nodeVersion } ` ;
32+ if ( typeof process . env . ALPINE_CHROOT === "string" ) {
33+ prebuildScript = `/alpine/enter-chroot ${ prebuildScript } ` ;
34+ }
35+ execaCommandSync ( prebuildScript , {
36+ env : process . env ,
37+ shell : true ,
38+ windowsHide : true ,
39+ stdio : "inherit" ,
40+ encoding : "utf8" ,
41+ } ) ;
42+ }
43+ main ( ) . catch ( e => {
44+ throw e ;
45+ } ) ;
46+ function getNodearch ( opts ) {
47+ switch ( opts . arch ) {
48+ case "x86" : {
49+ return "ia32" ;
50+ }
51+ case "x86_64" : {
52+ return "x64" ;
53+ }
54+ default : {
55+ return opts . arch ;
56+ }
57+ }
58+ }
59+ //# sourceMappingURL=prebuild.mjs.map
0 commit comments