From b508587c76d4ac5558ba7389990feec99b22a404 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sat, 22 Jul 2023 18:47:42 +0300 Subject: [PATCH] Support prebuild (#366) Simplifies distribution of pre-built binaries. * Fixes #201 * Fixes #297 --- .github/workflows/prebuild.yml | 57 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + .prebuildrc | 8 +++++ package.json | 18 +++++++++-- 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/prebuild.yml create mode 100644 .prebuildrc diff --git a/.github/workflows/prebuild.yml b/.github/workflows/prebuild.yml new file mode 100644 index 00000000..fb49b67f --- /dev/null +++ b/.github/workflows/prebuild.yml @@ -0,0 +1,57 @@ +name: Add native binaries to release + +on: + release: + types: [created] + +jobs: + prebuild: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + fail-fast: false + steps: + - uses: actions/checkout@v3 + - name: Use Node.js 18.x + uses: actions/setup-node@v3 + with: + node-version: 18.x + - name: Add msbuild to PATH + if: matrix.os == 'windows-latest' + uses: microsoft/setup-msbuild@v1.3 + - name: Install node-gyp + if: matrix.os == 'windows-latest' + run: | + npm install --global node-gyp@latest + - name: Build + run: | + npm install --ignore-scripts + - name: Prebuild + run: | + npm run prebuild + - name: Upload + run: | + npx prebuild --upload ${{ secrets.UPLOAD_TOKEN }} + env: + MAKEFLAGS: -j4 + + prebuild-alpine: + runs-on: ubuntu-latest + container: node:18-alpine3.18 + steps: + - uses: actions/checkout@v3 + - name: install build deps + run: | + apk add g++ make python3 + - name: Build + run: | + npm install --ignore-scripts + - name: Prebuild + run: | + npm run prebuild + - name: Upload + run: | + npx prebuild --upload ${{ secrets.UPLOAD_TOKEN }} + env: + MAKEFLAGS: -j4 diff --git a/.gitignore b/.gitignore index 75367e7d..ad6e3721 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ package-lock.json out/ .cache/ compile_commands.json +/prebuilds/ diff --git a/.prebuildrc b/.prebuildrc new file mode 100644 index 00000000..5bc65bd3 --- /dev/null +++ b/.prebuildrc @@ -0,0 +1,8 @@ +{ + "target": [ + "16.20.1", + "18.16.1", + "20.4.0" + ], + "strip": true +} diff --git a/package.json b/package.json index 7b34e05c..e04e5a91 100644 --- a/package.json +++ b/package.json @@ -8,13 +8,25 @@ "node": ">=16.0.0" }, "scripts": { - "install": "node-gyp rebuild --release -j 4", - "postinstall": "node-gyp clean", + "install": "prebuild-install || (node-gyp rebuild --release -j 4 && node-gyp clean)", + "rebuild": "node-gyp rebuild --release -j 4", + "prebuild": "prebuild", + "upload": "prebuild --upload ${GITHUB_TOKEN}", "lint": "find src -name '*.cc' | xargs -n1 clang-tidy", "test": "node test.js" }, + "dependencies": { + "prebuild-install": "^7.1.1" + }, "devDependencies": { - "isolated-vm": "." + "isolated-vm": ".", + "prebuild": "^11.0.4" + }, + "overrides": { + "node-gyp": "^9.4.0" + }, + "binary": { + "module_path": "out" }, "repository": { "type": "git",