From 0d0d6d85945aff67030f91423b912c9d9903428c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 23 Apr 2021 03:30:41 -0500 Subject: [PATCH 1/6] chore: add github actions for prebuilding --- .github/workflows/CI.yml | 59 ++++++++++++++++++++++++++++++++++++ .travis.yml | 65 ---------------------------------------- script/ci/prebuild.sh | 9 ++---- 3 files changed, 62 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/CI.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 00000000..d7422d35 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,59 @@ +name: CI +on: + pull_request: + push: + +defaults: + run: + shell: bash + +jobs: + Build: + if: "!contains(github.event.head_commit.message, '[skip ci]')" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-20.04 + - macos-latest + - windows-latest + node_version: + - 14 + node_arch: + - x64 + include: + - os: windows-latest + node_version: 14 + node_arch: ia32 + # - os: macos-11.0 + # node_version: 15 + # node_arch: arm64 + steps: + - uses: actions/checkout@v2 + + - name: Install Node + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node_version }} + architecture: ${{ matrix.node_arch }} + + - name: Install Dependencies and Build + run: npm install + + - name: Prebuildify + run: sh script/ci/prebuild.sh + env: + ARCH: ${{ matrix.node_arch }} + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + path: ./prebuilds + + Skip: + if: contains(github.event.head_commit.message, '[skip ci]') + runs-on: ubuntu-latest + steps: + - name: Skip CI 🚫 + run: echo skip ci diff --git a/.travis.yml b/.travis.yml index 1c8c48ad..a444f467 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,12 +75,6 @@ jobs: ## PREBUILD STAGE - - stage: prebuild - os: linux - env: ARCHIVE_SUFFIX=-x64 - node_js: "14" - script: script/ci/prebuild.sh - - stage: prebuild os: linux env: ALPINE_CHROOT=3.10 ARCHIVE_SUFFIX=-x64-musl @@ -101,74 +95,15 @@ jobs: addons: {apt: {packages: [gcc-8-aarch64-linux-gnu, g++-8-aarch64-linux-gnu]}} script: script/ci/prebuild.sh - - stage: prebuild - os: osx - osx_image: xcode10 - node_js: "14" - script: script/ci/prebuild.sh - - - stage: prebuild - os: windows - node_js: "14" - # https://travis-ci.community/t/build-doesnt-finish-after-completing-tests/288 - env: YARN_GPG=no ARCHIVE_SUFFIX=-x64 - script: script/ci/prebuild.sh - - - stage: prebuild - os: windows - node_js: "14/x86" - # https://travis-ci.community/t/build-doesnt-finish-after-completing-tests/288 - env: YARN_GPG=no ARCHIVE_SUFFIX=-x86 - script: script/ci/prebuild.sh - - ## PUBLISH STAGE - - - stage: publish - os: linux - node_js: "14" - env: IGNORE_SCRIPTS=true - script: script/ci/package.sh - fast_finish: true stages: - name: test - name: prebuild if: tag IS present -- name: publish - if: tag IS present install: - travis_retry script/ci/install.sh script: - travis_retry script/ci/test.sh - -deploy: -# Deploy prebuilds to Github releases. -- provider: releases - draft: false - file: "${TRAVIS_TAG:-latest}-${TRAVIS_OS_NAME}${ARCHIVE_SUFFIX}.tar.gz" - skip_cleanup: true - on: - tags: true - condition: "$TRAVIS_BUILD_STAGE_NAME = Prebuild" - api_key: - # Github API token for @zeromqjs-integration - secure: CvjUt3eRB1J6H9vxx/WrI4jOMX+jjgUSuC3z0r1tEfTKsrkt0Eoovn22tWP45aYeZd0clbV0aIhi3jvkZVAXvQ6y+WPdY9ZsQ1AJtZkVyT3qOdxeybcM0x5NY0q6dnROOwJ8O8Y6FeOrNdEuSImrCrCcPaPv9ZIM9Dv8jto5d5VypFtF5GaZ0nZPRuUgKVXDEKcHVZPgDhgHmjPzVAO0XXdHbgQtUlGYvhQmNhSE5njGFg1lm4+CWkDdpWAiehv0kwtCSx3pn3WtfO4Romt9fk662ykRYDSve0TryR2HBvISqmM64E2NU1VjqGy0nSdyVD7s9gV2hE+FG/N3/n4lYUH3UtaIwjqNmlgQpl/mDz/y5W0nTscigWkzPuk0HqiEHQ0Wk6jZLvw3cUD5YXBgESg0nbBIt+TIaCp2/Z+vENtD3blaXH0n4vXJhRDAlbQ/E7CvIWOUTaSuXfK3ugGoifzc78MyAK0TdYCX+EJoIWe5l+o8TExrWdSp4485dcsex1vOo5Wd7bPIvfsDzfNjmraanoFxUCfU+lrxuQqPN4Ot/MoltThhMJwTZJCdnZsZPYR3oznI7Dn5gLyijpNwLWTlHDsSTcZuronE8WEFHUiNwsVnt29tvp6m6OBin6gZUCXoR78c0DQoyTpS8Nc2zKbK1ps6pelKhs39K1n+d+U= - -# Deploy package including all generated prebuilds to NPM. -- provider: npm - email: rolftimmermans+zeromqjs@voormedia.com - skip_cleanup: true - on: - tags: true - condition: "$TRAVIS_BUILD_STAGE_NAME = Publish" - api_key: - # NPM API token for @zeromqjs-integration - secure: 2dWaYpf8DDmfD0zoDLs2QFhE+vNT9vq2UOb6A+SHnsqkxfTh3xkkT0EyKEjAF7vQ03QKI6cYMcz9YVr7pwfoN1xWS1JA78YcZ9aG2+De1HW2tbi0SsDJgMzMv+OejloH9T0Mzth5k45ehRkXjijkBnTGT1j1AdXvTg0+MAOxEO0Q30aMUMBQ4y+0JB9S9UCE6Cs/BWt0mdoKXsb4pL+gJBSbE4wzrkthIkvG8Am6EybztLOjyGlWdvtDQeNe0JwMjeHMlmp/k4auXS+3x+JBcjCqxXxGQnDUHaZ31nFGVx6ns9rmsupe9FzWqOBYBwWRO0G0+Ku17gjluQLvqalib9SEcZiLv+nCpWlHoQNBuAoVz+CoCkfWCp6OUkJ5NpAkQRDSF/7s4A1gzzT7Ne+Ux670PhkvHLJpH4Pt08QqtRsSdjuj566DbYqdEmdW8SwOnRzigs4eVY6m+O6PDD6j4vBzeoE0zIDsCfCEsk6CaErdMQhQOb+wZTL1DRz49YgwUTZym9ekgf/hNrDqMkVuM1RT8L2CUqBHhmqAq6yJ4c11C1O2DEWC4MgIqw7/sfrsFtZlauaU/NyUDf2q6NXnPLISp8M+06ES+eNynyM1w8F+6bBebAe6GN4+DAUlt+VKtREIzxqKRG/2PZ7aYYbt2nlmTa4e/Lp7/MLqoZEOvPw= - -env: - global: - # GITHUB_TOKEN= - secure: x3reA0+odqmuxZbUfQCbT/bXI4pBC2VDidUyt2kn0BFmEWI5J8dXV0rXM0Ai/iCh5ESm6mIbzAjw1mOBgke6OET9gbZbAdMMqX30abAEBsvBu+z/t/cpXmTEOPCTjBIvJhmJxOZxjyR3iG+lI9L8DdheWt0sS/ucD3w1Qd0eoD8wo2+ynWxdeeC0ZZLdO94UM/1QJMDqsShLQBu9tvhDWgmxjzyENC6vhXKuesLV4lwqZTCw4Kqp4SeWml5R1sY7PZWCj0EoxIskSK8KDCHHrvNWcXCB5gTIbmpcpnHZyci6gi3Tl5FhRVXUrYwfm87hPrqrqBOMeCcEmrEHz7AfwgrPpunneq8cCd4JJp9LHQMGurUy5eX9ArJFGiLS1PkygOu6N7Ob3nzUxIQp5psO9u0aMLWOAWmlgFLi5VRdDGiKIBIdy0uwKB1Cxk1R4ULjgBvAVhCmikuOd48H4a6cUmblOFoapWeVYX/p34L62sJEXLSYUENiCJ3hFV3Yq3YiozkcyGAbnmrqfXPT1fSJa21AMyn0D2x+I4/BDvMGOnoX9yVxJPqwNP4C7adevsYod4Z6x6dhhHfYFyP8kKMLzydXdK9tkPi20VNvpQYHBoQCRKO4Rk+VDzBnhqSowYJqiOu2Wp6v+MaaJhmWMWOZKC/9hww7PA9DMIULQmXT3Do= diff --git a/script/ci/prebuild.sh b/script/ci/prebuild.sh index 244c16c4..6e30455b 100755 --- a/script/ci/prebuild.sh +++ b/script/ci/prebuild.sh @@ -17,14 +17,11 @@ if [ -n "${TRIPLE}" ]; then fi if [ -n "${ALPINE_CHROOT}" ]; then - /alpine/enter-chroot yarn ci:prebuild --tag-libc + /alpine/enter-chroot npm run ci:prebuild --tag-libc else if [ "${TRAVIS_OS_NAME}" = "linux" ]; then - yarn ci:prebuild --tag-libc + npm run ci:prebuild -- --tag-libc --arch="${ARCH}" else - yarn ci:prebuild + npm run ci:prebuild -- --arch="${ARCH}" fi fi - -ARCHIVE_NAME="${TRAVIS_TAG:-latest}-${TRAVIS_OS_NAME}${ARCHIVE_SUFFIX}.tar.gz" -tar -zcvf "${ARCHIVE_NAME}" -C "${TRAVIS_BUILD_DIR}" prebuilds From c8797b39dec7cc71db18dad61541a164e50a9aaf Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 23 Apr 2021 05:03:43 -0500 Subject: [PATCH 2/6] chore: add default value for sanitizers variable --- binding.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/binding.gyp b/binding.gyp index e3450169..b7a8eefd 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,6 +3,7 @@ 'zmq_shared%': 'false', 'zmq_draft%': 'false', 'zmq_no_sync_resolve%': 'false', + 'sanitizers%': 'false', }, 'targets': [ From d8aaa0c3e3ec3540ca54b6b2715adcf9527f2c86 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 24 Apr 2021 11:16:28 -0500 Subject: [PATCH 3/6] chore: convert the prebuild script to typescript --- .github/workflows/CI.yml | 6 ++--- .travis.yml | 6 ++--- package.json | 3 +-- script/ci/prebuild.sh | 27 ------------------- script/prebuild.ts | 56 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 35 deletions(-) delete mode 100755 script/ci/prebuild.sh create mode 100644 script/prebuild.ts diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d7422d35..3a58cac9 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -25,7 +25,7 @@ jobs: include: - os: windows-latest node_version: 14 - node_arch: ia32 + node_arch: x86 # - os: macos-11.0 # node_version: 15 # node_arch: arm64 @@ -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 }} diff --git a/.travis.yml b/.travis.yml index a444f467..cd49b788 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/package.json b/package.json index 9392a93d..b7cf3537 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/script/ci/prebuild.sh b/script/ci/prebuild.sh deleted file mode 100755 index 6e30455b..00000000 --- a/script/ci/prebuild.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -set -e - -echo "Building distribution binary..." - -if [ -n "${TRIPLE}" ]; then - export CC="${TRIPLE}-gcc-${GCC}" - export CXX="${TRIPLE}-g++-${GCC}" - export STRIP="${TRIPLE}-strip" - export ZMQ_BUILD_OPTIONS="--host=${TRIPLE}" - - export npm_config_arch=${ARCH} - export npm_config_target_arch=${ARCH} - - export PREBUILD_ARCH="${ARCH}" - export PREBUILD_STRIP_BIN="${STRIP}" -fi - -if [ -n "${ALPINE_CHROOT}" ]; then - /alpine/enter-chroot npm run ci:prebuild --tag-libc -else - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then - npm run ci:prebuild -- --tag-libc --arch="${ARCH}" - else - npm run ci:prebuild -- --arch="${ARCH}" - fi -fi diff --git a/script/prebuild.ts b/script/prebuild.ts new file mode 100644 index 00000000..dc77fe0c --- /dev/null +++ b/script/prebuild.ts @@ -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 --arch=${prebuildArch} -t 12.0.0 -t electron@9.4.4 --strip` + + 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 + } +} From a8b8a8a6c8d056b30284edd8d4a30d68a5ff84dd Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 24 Apr 2021 11:36:36 -0500 Subject: [PATCH 4/6] chore: add windows x86 build support --- script/build.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/script/build.sh b/script/build.sh index 3ad3a92d..3e2689a0 100755 --- a/script/build.sh +++ b/script/build.sh @@ -12,6 +12,12 @@ if [ -n "${WINDIR}" ]; then # Working directory is NAPI temporary build directory. PATH_PREFIX="${PWD}/libzmq" ARTIFACT="${PATH_PREFIX}/lib/libzmq.lib" + + # Handle x86 or x64 build + if [ -z "${ARCH}" ]; then + ARCH="x64" + fi + BUILD_OPTIONS="-DCMAKE_GENERATOR_PLATFORM=${ARCH} ${BUILD_OPTIONS}" else # Working directory is project root. PATH_PREFIX="${PWD}/build/libzmq" From d8fccb26317c945f788a1fedceee48ef222073bd Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 24 Apr 2021 11:41:56 -0500 Subject: [PATCH 5/6] chore: remove vendor related code from dev:build script --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b7cf3537..88dceea6 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "prebuildify": "^4.1.2", "prettier": "^1.19.1", "semver": ">= 0", + "shx": "^0.3.3", "tar-fs": "^2.0.0", "ts-morph": "^7.0.0", "ts-node": ">= 7", @@ -76,8 +77,8 @@ "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", "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:build": "prebuildify --napi --build-from-source --debug", + "dev:test": "tsc --project tsconfig-build.json && node script/ci/downlevel-dts.js && mocha && script/format.sh && shx rm -f tmp/*", "dev:bench": "node --expose-gc test/bench" }, "keywords": [ From 7578890e320052e1b68f3b6dbac3e12d63cfea4e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 24 Apr 2021 14:35:40 -0500 Subject: [PATCH 6/6] chore: only set DCMAKE_GENERATOR_PLATFORM if x86 --- script/build.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/script/build.sh b/script/build.sh index 3e2689a0..3e79f5b7 100755 --- a/script/build.sh +++ b/script/build.sh @@ -14,10 +14,9 @@ if [ -n "${WINDIR}" ]; then ARTIFACT="${PATH_PREFIX}/lib/libzmq.lib" # Handle x86 or x64 build - if [ -z "${ARCH}" ]; then - ARCH="x64" + if [ "${ARCH}" = "x86" ]; then + BUILD_OPTIONS="-DCMAKE_GENERATOR_PLATFORM=x86 ${BUILD_OPTIONS}" fi - BUILD_OPTIONS="-DCMAKE_GENERATOR_PLATFORM=${ARCH} ${BUILD_OPTIONS}" else # Working directory is project root. PATH_PREFIX="${PWD}/build/libzmq"