Skip to content

Commit

Permalink
chore: convert the prebuild script to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 24, 2021
1 parent c8797b3 commit cd4f56d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
- name: Install Dependencies and Build
run: npm install

- name: Prebuildify
run: sh script/ci/prebuild.sh
- name: Prebuild
run: npm run prebuild
env:
ARCH: ${{ matrix.node_arch }}

Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ jobs:
os: linux
env: ALPINE_CHROOT=3.10 ARCHIVE_SUFFIX=-x64-musl
sudo: required
script: script/ci/prebuild.sh
script: npm run prebuild

- stage: prebuild
os: linux
node_js: "14"
env: ARCH=arm TRIPLE=arm-linux-gnueabihf GCC=8 ARCHIVE_SUFFIX=-armv7
addons: {apt: {packages: [gcc-8-arm-linux-gnueabihf, g++-8-arm-linux-gnueabihf]}}
script: script/ci/prebuild.sh
script: npm run prebuild

- stage: prebuild
os: linux
node_js: "14"
env: ARCH=arm64 TRIPLE=aarch64-linux-gnu GCC=8 ARCHIVE_SUFFIX=-armv8
addons: {apt: {packages: [gcc-8-aarch64-linux-gnu, g++-8-aarch64-linux-gnu]}}
script: script/ci/prebuild.sh
script: npm run prebuild

fast_finish: true

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@
"install": "node-gyp-build",
"ci:compile": "tsc --project tsconfig-build.json && node script/ci/downlevel-dts.js",
"ci:doc": "typedoc --out docs --name zeromq.js --excludeProtected --excludePrivate --excludeNotExported --excludeExternals --externalPattern 'src/+(draft|native|compat).ts' --tsconfig tsconfig-build.json --mode file",
"ci:prebuild": "npm run prebuildify",
"prebuildify": "prebuildify --napi -t 12.0.0 -t electron@9.4.4 --strip",
"prebuild": "ts-node -P ./tsconfig.json ./script/prebuild.ts",
"dev:build": "rm -f vendor/* && touch vendor/.gitkeep && cp node_modules/node-addon-api/{*.h,LICENSE.md} vendor && prebuildify --napi --build-from-source --debug",
"dev:test": "tsc --project tsconfig-build.json && node script/ci/downlevel-dts.js && mocha && script/format.sh && rm -f tmp/*",
"dev:bench": "node --expose-gc test/bench"
Expand Down
27 changes: 0 additions & 27 deletions script/ci/prebuild.sh

This file was deleted.

56 changes: 56 additions & 0 deletions script/prebuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable @typescript-eslint/camelcase */

import {spawnSync} from "child_process"

main().catch(e => {
throw e
})

async function main() {
console.log("Building distribution binary...")

const prebuildArch = getNodearch(process.env.ARCH)

if (process.env.TRIPLE) {
const TRIPLE = process.env.TRIPLE

const GCC = process.env.GCC
process.env.CC = `${TRIPLE}-gcc-${GCC}`
process.env.CXX = `${TRIPLE}-g++-${GCC}`

const STRIP = `${TRIPLE}-strip`
process.env.PREBUILD_STRIP_BIN = STRIP

process.env.npm_config_arch = prebuildArch
process.env.npm_config_target_arch = prebuildArch
process.env.PREBUILD_arch = prebuildArch

process.env.ZMQ_BUILD_OPTIONS = `--host=${TRIPLE}`
}

let prebuildScript = `prebuildify --napi -t 12.0.0 -t electron@9.4.4 --strip --arch=${prebuildArch}`

if (process.platform == "linux") {
prebuildScript = `${prebuildScript} --tag-libc`
}
if (process.env.ALPINE_CHROOT) {
prebuildScript = `/alpine/enter-chroot ${prebuildScript}`
}

spawnSync(prebuildScript, {
shell: true,
stdio: "inherit",
encoding: "utf8",
})
}

function getNodearch(arch: string | undefined): string {
if (!arch) {
return process.arch
}
if (arch === "x86") {
return "ia32"
} else {
return arch
}
}

0 comments on commit cd4f56d

Please sign in to comment.