From f8eb4570175919f0c7fc04ab92382f0f07e392b0 Mon Sep 17 00:00:00 2001 From: Hongcai Deng Date: Mon, 6 Jan 2025 16:53:56 +0800 Subject: [PATCH] feat: support MacOS arm and newer node (#11) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 🎸 support arm and newer node --- .github/workflows/ci.yml | 87 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 62 ---------------------------- index.js | 2 +- package.json | 14 +++---- 4 files changed, 95 insertions(+), 70 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f3eba1b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,87 @@ +name: CI + +on: + push: + branches: + - '*' + tags: + - '*' + pull_request: + branches: + - '*' + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + node-version: [16, 18, 20, 22] + + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Set macOS system controls + if: runner.os == 'macOS' + run: | + sudo sysctl -w kern.sysv.shmall=65536 + sudo sysctl -w kern.sysv.shmmax=16777216 + + - name: Setup build tools + run: | + npm install -g node-gyp + npm install -g node-pre-gyp-github + + - name: Setup macOS build tools + if: runner.os == 'macOS' + run: | + env HOMEBREW_NO_AUTO_UPDATE=1 brew install autoconf automake libtool + + - name: Set publish flag + run: | + echo "PUBLISH_BINARY=false" >> $GITHUB_ENV + if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then + echo "PUBLISH_BINARY=true" >> $GITHUB_ENV + fi + if [[ "${{ github.event.head_commit.message }}" == *"[publish binary]"* ]]; then + echo "PUBLISH_BINARY=true" >> $GITHUB_ENV + fi + + - name: Setup Linux compiler + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y g++ + echo "CXX=g++" >> $GITHUB_ENV + + - name: Install + run: | + npm install --build-from-source + npm test + + - name: Publish + env: + NODE_PRE_GYP_GITHUB_TOKEN: ${{ secrets.NODE_PRE_GYP_GITHUB_TOKEN }} + run: | + if [[ $PUBLISH_BINARY == true ]]; then node-pre-gyp package; node-pre-gyp-github publish --release; fi; + ./node_modules/.bin/node-pre-gyp clean + node-gyp clean + + - name: Publish Check + run: | + INSTALL_RESULT=0 + if [[ $PUBLISH_BINARY == true ]]; then INSTALL_RESULT=$(npm install --fallback-to-build=false > /dev/null)$? || true; fi; + if [[ $INSTALL_RESULT != 0 ]]; then echo "returned $INSTALL_RESULT";false; fi + ./node_modules/.bin/node-pre-gyp clean diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 335a882..0000000 --- a/.travis.yml +++ /dev/null @@ -1,62 +0,0 @@ -os: - - linux - - osx - -language: node_js - -node_js: - - "8" - - "10" - - "12" - - "14" - -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-4.8 - -before_install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo sysctl -w kern.sysv.shmall=65536 ; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo sysctl -w kern.sysv.shmmax=16777216; fi - # get commit message - - COMMIT_MESSAGE=$(git show -s --format=%B $TRAVIS_COMMIT | tr -d '\n') - # put local node-pre-gyp on PATH - - export PATH=./node_modules/.bin/:$PATH - # put global node-gyp on PATH - - npm install node-gyp -g - # install node-pre-gyp-github so it is available for publishing - - npm install -g node-pre-gyp-github - # figure out if we should publish - - PUBLISH_BINARY=false - # if we are building a tag then publish - - if [[ $TRAVIS_BRANCH == `git describe --tags --always HEAD` ]]; then PUBLISH_BINARY=true; fi; - # or if we put [publish binary] in the commit message - - if test "${COMMIT_MESSAGE#*'[publish binary]'}" != "$COMMIT_MESSAGE"; then PUBLISH_BINARY=true; fi; - -install: - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CXX=g++-4.8 ; fi - # ensure source install works - - npm install --build-from-source - - npm test - -before_script: - # if publishing, do it - - if [[ $PUBLISH_BINARY == true ]]; then node-pre-gyp package; node-pre-gyp-github publish --release; fi; - # cleanup - - node-pre-gyp clean - - node-gyp clean - -script: - # if publishing, test installing from remote - - INSTALL_RESULT=0 - - if [[ $PUBLISH_BINARY == true ]]; then INSTALL_RESULT=$(npm install --fallback-to-build=false > /dev/null)$? || true; fi; - # if install returned non zero (errored) then we first unpublish and then call false so travis will bail at this line - - if [[ $INSTALL_RESULT != 0 ]]; then echo "returned $INSTALL_RESULT";false; fi - # If success then we arrive here so lets clean up - - node-pre-gyp clean - -after_success: - # if success then query and display all published binaries - - node-pre-gyp info diff --git a/index.js b/index.js index 5cb1e73..8fc3871 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -var binary = require('node-pre-gyp'); +var binary = require('@mapbox/node-pre-gyp'); var path = require('path'); var binding_path = binary.find(path.resolve(path.join(__dirname,'./package.json'))); var binding = require(binding_path); diff --git a/package.json b/package.json index b48fea3..ffc426b 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,9 @@ "clean": "node-pre-gyp clean", "test": "mocha", "install": "node-pre-gyp install --fallback-to-build || (npm run build:fastcommon && npm run build:shmcache && npm run build:libbson && node-pre-gyp install --fallback-to-build)", - "build:fastcommon": "cd deps/libfastcommon && MACOSX_DEPLOYMENT_TARGET=10.7 ./make.sh", - "build:shmcache": "cd deps/libshmcache/src && MACOSX_DEPLOYMENT_TARGET=10.7 LIBRARY_PATH=../../libfastcommon/src INC_PATH=\" -I../../libfastcommon/src\" make -e", - "build:libbson": "cd deps/ && MACOSX_DEPLOYMENT_TARGET=10.7 ./build-libbson.sh", + "build:fastcommon": "cd deps/libfastcommon && MACOSX_DEPLOYMENT_TARGET=11.0 ./make.sh", + "build:shmcache": "cd deps/libshmcache/src && MACOSX_DEPLOYMENT_TARGET=11.0 LIBRARY_PATH=../../libfastcommon/src INC_PATH=\" -I../../libfastcommon/src\" make -e", + "build:libbson": "cd deps/ && MACOSX_DEPLOYMENT_TARGET=11.0 ./build-libbson.sh", "trim": "cd deps/ && rm -rf libbson/.git && rm -rf libshmcache/.git && rm -rf libfastcommon/.git && rm libbson/.gitignore && rm libbson/README && cp libbson/README.rst libbson/README" }, "binary": { @@ -18,14 +18,14 @@ "remote_path": "{version}" }, "devDependencies": { + "@mapbox/node-pre-gyp": "^1.0.11", "mocha": "^3.2.0", + "node-gyp": "^11.0.0", "node-pre-gyp-github": "^1.3.1" }, "dependencies": { "bindings": "^1.5.0", - "nan": "^2.14.1", - "node-gyp": "^3.8.0", - "node-pre-gyp": "^0.6.39" + "nan": "^2.22.0" }, "gypfile": true, "name": "shm-cache", @@ -49,6 +49,6 @@ }, "homepage": "https://github.com/denghongcai/node-shm-cache#readme", "engines": { - "node": ">=8" + "node": ">=16" } }