Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.
/ leveldown Public archive

Commit 26ea717

Browse files
authored
Build universal binary for M1 (Apple silicon) (#781)
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
1 parent 576d135 commit 26ea717

File tree

7 files changed

+45
-10
lines changed

7 files changed

+45
-10
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ jobs:
1818
- os: ubuntu-latest
1919
arch: x64
2020
build-group: android-arm
21-
- os: macos-latest
21+
# At the time of writing macos-latest is mac 10; we need 11 to build a universal binary.
22+
- os: macos-11
2223
arch: x64
23-
build-group: darwin-x64
24+
build-group: darwin-x64+arm64
2425
- os: windows-latest
2526
arch: x86
2627
build-group: win32-x86

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ jobs:
66
test:
77
strategy:
88
matrix:
9-
os: [ubuntu-latest, macos-latest, windows-latest]
9+
# At the time of writing macos-latest is mac 10; we need 11 to build a universal binary.
10+
os: [ubuntu-latest, macos-11, windows-latest]
1011
node: [10, 12, 14]
1112
arch: [x86, x64]
1213
exclude:
1314
- { os: ubuntu-latest, arch: x86 }
14-
- { os: macos-latest, arch: x86 }
15+
- { os: macos-11, arch: x86 }
1516
runs-on: ${{ matrix.os }}
1617
name: ${{ matrix.os }} / Node ${{ matrix.node }} ${{ matrix.arch }}
1718
steps:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ See the section on <a href="#safety">safety</a> below for details of known unsaf
7171

7272
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`.
7373

74-
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:
74+
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:
7575

7676
- **Linux** (including ARM platforms such as Raspberry Pi and Kindle)
77-
- **Mac OS**
77+
- **Mac OS** (10.7 and later)
7878
- **Solaris** (SmartOS & Nodejitsu)
7979
- **FreeBSD**
8080
- **Windows**

binding.gyp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,22 @@
2222
["OS == 'mac'", {
2323
"cflags+": ["-fvisibility=hidden"],
2424
"xcode_settings": {
25-
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES" # -fvisibility=hidden
25+
# -fvisibility=hidden
26+
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES",
27+
28+
# Set minimum target version because we're building on newer
29+
# Same as https://github.com/nodejs/node/blob/v10.0.0/common.gypi#L416
30+
"MACOSX_DEPLOYMENT_TARGET": "10.7",
31+
32+
# Build universal binary to support M1 (Apple silicon)
33+
"OTHER_CFLAGS": [
34+
"-arch x86_64",
35+
"-arch arm64"
36+
],
37+
"OTHER_LDFLAGS": [
38+
"-arch x86_64",
39+
"-arch arm64"
40+
]
2641
}
2742
}],
2843
["OS == 'android'", {

deps/leveldb/leveldb.gyp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@
153153
"-Wno-sign-compare",
154154
"-Wno-unused-variable",
155155
"-Wno-unused-function"
156+
],
157+
158+
# Set minimum target version because we're building on newer
159+
"MACOSX_DEPLOYMENT_TARGET": "10.7",
160+
161+
# Build universal binary to support M1 (Apple silicon)
162+
"OTHER_CFLAGS": [
163+
"-arch x86_64",
164+
"-arch arm64"
156165
]
157166
}
158167
}],

deps/snappy/snappy.gyp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@
7272
"WARNING_CFLAGS": [
7373
"-Wno-sign-compare",
7474
"-Wno-unused-function"
75+
],
76+
77+
# Set minimum target version because we're building on newer
78+
"MACOSX_DEPLOYMENT_TARGET": "10.7",
79+
80+
# Build universal binary to support M1 (Apple silicon)
81+
"OTHER_CFLAGS": [
82+
"-arch x86_64",
83+
"-arch arm64"
7584
]
7685
}
7786
}],

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
"prebuild-linux-arm": "prebuildify-cross -i linux-armv6 -i linux-armv7 -i linux-arm64 -t 8.14.0 --napi --strip",
2121
"prebuild-android-arm": "prebuildify-cross -i android-armv7 -i android-arm64 -t 8.14.0 --napi --strip",
2222
"prebuild-linux-x64": "prebuildify-cross -i centos7-devtoolset7 -i alpine -t 8.14.0 --napi --strip",
23-
"prebuild-darwin-x64": "prebuildify -t 8.14.0 --napi --strip",
23+
"prebuild-darwin-x64+arm64": "prebuildify -t 8.14.0 --napi --strip --arch x64+arm64",
2424
"prebuild-win32-x86": "prebuildify -t 8.14.0 --napi --strip",
2525
"prebuild-win32-x64": "prebuildify -t 8.14.0 --napi --strip"
2626
},
2727
"dependencies": {
2828
"abstract-leveldown": "^7.0.0",
2929
"napi-macros": "~2.0.0",
30-
"node-gyp-build": "~4.2.1"
30+
"node-gyp-build": "^4.3.0"
3131
},
3232
"devDependencies": {
3333
"async-each": "^1.0.3",
@@ -43,7 +43,7 @@
4343
"mkfiletree": "^2.0.0",
4444
"node-gyp": "^7.1.2",
4545
"nyc": "^15.0.0",
46-
"prebuildify": "^4.1.0",
46+
"prebuildify": "^4.2.1",
4747
"prebuildify-ci": "^1.0.4",
4848
"prebuildify-cross": "^4.0.1",
4949
"readfiletree": "^1.0.0",

0 commit comments

Comments
 (0)