Skip to content

Commit

Permalink
Build universal binary for M1 (Apple silicon) (Level#781)
Browse files Browse the repository at this point in the history
On mac, the prebuilt binary (as well as the binary built by
`npm i --build-from-source`) is now a universal binary that's
suitable for both x86_64 (as before) and arm64 (new).

Also sets MACOSX_DEPLOYMENT_TARGET, to 10.7 which is the same target
that Node.js 10 uses and thus what we already supported, but now
explicitly.

Ref Level#766

(cherry picked from commit 26ea717)
  • Loading branch information
vweevers authored and an9949an committed Aug 15, 2023
1 parent 0e332ee commit 1056d0d
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 6 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Release
on:
push:
tags: ['*']
jobs:
build:
permissions:
contents: read
strategy:
matrix:
include:
- os: ubuntu-latest
arch: x64
build-group: linux-x64
- os: ubuntu-latest
arch: x64
build-group: linux-arm
- os: ubuntu-latest
arch: x64
build-group: android-arm
# At the time of writing macos-latest is mac 10; we need 11 to build a universal binary.
- os: macos-11
arch: x64
build-group: darwin-x64+arm64
- os: windows-latest
arch: x86
build-group: win32-x86
- os: windows-latest
arch: x64
build-group: win32-x64
runs-on: ${{ matrix.os }}
name: Build ${{ matrix.build-group }}
env:
BUILD_GROUP: ${{ matrix.build-group }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up node
uses: actions/setup-node@v2
with:
node-version: 14
architecture: ${{ matrix.arch }}
- name: Install
run: npm install --ignore-scripts
- name: Prebuild
run: npm run prebuild-$BUILD_GROUP
shell: bash
- name: Prepare artifact
run: tar -zcvf $BUILD_GROUP.tar.gz -C prebuilds .
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.BUILD_GROUP }}
path: ${{ env.BUILD_GROUP }}.tar.gz
retention-days: 1
release:
needs: build
permissions:
contents: write
runs-on: ubuntu-latest
name: Release
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Download artifacts
uses: actions/download-artifact@v2
with:
path: artifacts
- name: Create GitHub release
uses: docker://antonyurchenko/git-release:v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: artifacts/*/*.tar.gz
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test
on: [push, pull_request]
permissions:
contents: read
jobs:
test:
strategy:
matrix:
# At the time of writing macos-latest is mac 10; we need 11 to build a universal binary.
os: [ubuntu-latest, macos-11, windows-latest]
node: [10, 12, 14]
arch: [x86, x64]
exclude:
- { os: ubuntu-latest, arch: x86 }
- { os: macos-11, arch: x86 }
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} / Node ${{ matrix.node }} ${{ matrix.arch }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Use node ${{ matrix.node }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
architecture: ${{ matrix.arch }}
- name: Install
run: npm install
- name: Test
run: npm test
- name: Coverage
run: npm run coverage
- name: Codecov
uses: codecov/codecov-action@v2
with:
file: coverage/lcov.info
- name: Test Electron
if: ${{ matrix.node == '14' }}
uses: GabrielBB/xvfb-action@v1
with:
run: npm run test-electron
- name: Test GC
run: npm run test-gc
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ See the section on <a href="#safety">safety</a> below for details of known unsaf

We aim to support _at least_ Active LTS and Current Node.js releases, Electron 4.0.0, as well as any future Node.js and Electron releases thanks to [N-API](https://nodejs.org/api/n-api.html). The minimum node version for `leveldown` is `8.6.0`. Conversely, for node >= 12, the minimum `leveldown` version is `5.0.0`.

The `leveldown` npm package ships with prebuilt binaries for popular 64-bit platforms as well as ARM, Android and Alpine (musl) and is known to work on:
The `leveldown` npm package ships with prebuilt binaries for popular 64-bit platforms as well as ARM, M1, Android and Alpine (musl) and is known to work on:

- **Linux** (including ARM platforms such as Raspberry Pi and Kindle)
- **Mac OS**
- **Mac OS** (10.7 and later)
- **Solaris** (SmartOS & Nodejitsu)
- **FreeBSD**
- **Windows**
Expand Down
17 changes: 16 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@
["OS == 'mac'", {
"cflags+": ["-fvisibility=hidden"],
"xcode_settings": {
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES" # -fvisibility=hidden
# -fvisibility=hidden
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES",

# Set minimum target version because we're building on newer
# Same as https://github.com/nodejs/node/blob/v10.0.0/common.gypi#L416
"MACOSX_DEPLOYMENT_TARGET": "10.7",

# Build universal binary to support M1 (Apple silicon)
"OTHER_CFLAGS": [
"-arch x86_64",
"-arch arm64"
],
"OTHER_LDFLAGS": [
"-arch x86_64",
"-arch arm64"
]
}
}],
["OS == 'android'", {
Expand Down
9 changes: 9 additions & 0 deletions deps/leveldb/leveldb.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@
"-Wno-sign-compare",
"-Wno-unused-variable",
"-Wno-unused-function"
],

# Set minimum target version because we're building on newer
"MACOSX_DEPLOYMENT_TARGET": "10.7",

# Build universal binary to support M1 (Apple silicon)
"OTHER_CFLAGS": [
"-arch x86_64",
"-arch arm64"
]
}
}],
Expand Down
9 changes: 9 additions & 0 deletions deps/snappy/snappy.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@
"WARNING_CFLAGS": [
"-Wno-sign-compare",
"-Wno-unused-function"
],

# Set minimum target version because we're building on newer
"MACOSX_DEPLOYMENT_TARGET": "10.7",

# Build universal binary to support M1 (Apple silicon)
"OTHER_CFLAGS": [
"-arch x86_64",
"-arch arm64"
]
}
}],
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
"prebuild-linux-arm": "prebuildify-cross -i linux-armv6 -i linux-armv7 -i linux-arm64 -t 8.14.0 --napi --strip",
"prebuild-android-arm": "prebuildify-cross -i android-armv7 -i android-arm64 -t 8.14.0 --napi --strip",
"prebuild-linux-x64": "prebuildify-cross -i centos7-devtoolset7 -i alpine -t 8.14.0 --napi --strip",
"prebuild-darwin-x64": "prebuildify -t 8.14.0 --napi --strip"
"prebuild-darwin-x64+arm64": "prebuildify -t 8.14.0 --napi --strip --arch x64+arm64",
"prebuild-win32-x86": "prebuildify -t 8.14.0 --napi --strip",
"prebuild-win32-x64": "prebuildify -t 8.14.0 --napi --strip"
},
"dependencies": {
"abstract-leveldown": "~6.2.1",
"napi-macros": "~2.0.0",
"node-gyp-build": "~4.1.0"
"node-gyp-build": "^4.3.0"
},
"devDependencies": {
"async-each": "^1.0.3",
Expand All @@ -44,7 +46,7 @@
"mkfiletree": "^2.0.0",
"node-gyp": "^6.0.0",
"nyc": "^15.0.0",
"prebuildify": "^3.0.0",
"prebuildify": "^4.2.1",
"prebuildify-ci": "^1.0.4",
"prebuildify-cross": "github:prebuild/prebuildify-cross#v4.0.0",
"readfiletree": "^1.0.0",
Expand Down

0 comments on commit 1056d0d

Please sign in to comment.