Skip to content

Commit

Permalink
Build universal binary for M1 (Apple silicon) (#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 #766
  • Loading branch information
vweevers committed Sep 28, 2021
1 parent 576d135 commit 26ea717
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ jobs:
- os: ubuntu-latest
arch: x64
build-group: android-arm
- os: macos-latest
# 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
build-group: darwin-x64+arm64
- os: windows-latest
arch: x86
build-group: win32-x86
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# 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-latest, arch: x86 }
- { os: macos-11, arch: x86 }
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} / Node ${{ matrix.node }} ${{ matrix.arch }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,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 5.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 `10.12.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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,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": "^7.0.0",
"napi-macros": "~2.0.0",
"node-gyp-build": "~4.2.1"
"node-gyp-build": "^4.3.0"
},
"devDependencies": {
"async-each": "^1.0.3",
Expand All @@ -43,7 +43,7 @@
"mkfiletree": "^2.0.0",
"node-gyp": "^7.1.2",
"nyc": "^15.0.0",
"prebuildify": "^4.1.0",
"prebuildify": "^4.2.1",
"prebuildify-ci": "^1.0.4",
"prebuildify-cross": "^4.0.1",
"readfiletree": "^1.0.0",
Expand Down

0 comments on commit 26ea717

Please sign in to comment.