Skip to content

Commit 1056d0d

Browse files
vweeversan9949an
authored andcommitted
Build universal binary for M1 (Apple silicon) (Level#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 Level#766 (cherry picked from commit 26ea717)
1 parent 0e332ee commit 1056d0d

7 files changed

Lines changed: 162 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Release
2+
on:
3+
push:
4+
tags: ['*']
5+
jobs:
6+
build:
7+
permissions:
8+
contents: read
9+
strategy:
10+
matrix:
11+
include:
12+
- os: ubuntu-latest
13+
arch: x64
14+
build-group: linux-x64
15+
- os: ubuntu-latest
16+
arch: x64
17+
build-group: linux-arm
18+
- os: ubuntu-latest
19+
arch: x64
20+
build-group: android-arm
21+
# At the time of writing macos-latest is mac 10; we need 11 to build a universal binary.
22+
- os: macos-11
23+
arch: x64
24+
build-group: darwin-x64+arm64
25+
- os: windows-latest
26+
arch: x86
27+
build-group: win32-x86
28+
- os: windows-latest
29+
arch: x64
30+
build-group: win32-x64
31+
runs-on: ${{ matrix.os }}
32+
name: Build ${{ matrix.build-group }}
33+
env:
34+
BUILD_GROUP: ${{ matrix.build-group }}
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v2
38+
with:
39+
submodules: recursive
40+
- name: Set up node
41+
uses: actions/setup-node@v2
42+
with:
43+
node-version: 14
44+
architecture: ${{ matrix.arch }}
45+
- name: Install
46+
run: npm install --ignore-scripts
47+
- name: Prebuild
48+
run: npm run prebuild-$BUILD_GROUP
49+
shell: bash
50+
- name: Prepare artifact
51+
run: tar -zcvf $BUILD_GROUP.tar.gz -C prebuilds .
52+
shell: bash
53+
- name: Upload artifact
54+
uses: actions/upload-artifact@v2
55+
with:
56+
name: ${{ env.BUILD_GROUP }}
57+
path: ${{ env.BUILD_GROUP }}.tar.gz
58+
retention-days: 1
59+
release:
60+
needs: build
61+
permissions:
62+
contents: write
63+
runs-on: ubuntu-latest
64+
name: Release
65+
steps:
66+
- name: Checkout
67+
uses: actions/checkout@v2
68+
- name: Download artifacts
69+
uses: actions/download-artifact@v2
70+
with:
71+
path: artifacts
72+
- name: Create GitHub release
73+
uses: docker://antonyurchenko/git-release:v4
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
with:
77+
args: artifacts/*/*.tar.gz

.github/workflows/test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Test
2+
on: [push, pull_request]
3+
permissions:
4+
contents: read
5+
jobs:
6+
test:
7+
strategy:
8+
matrix:
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]
11+
node: [10, 12, 14]
12+
arch: [x86, x64]
13+
exclude:
14+
- { os: ubuntu-latest, arch: x86 }
15+
- { os: macos-11, arch: x86 }
16+
runs-on: ${{ matrix.os }}
17+
name: ${{ matrix.os }} / Node ${{ matrix.node }} ${{ matrix.arch }}
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
with:
22+
submodules: recursive
23+
- name: Use node ${{ matrix.node }}
24+
uses: actions/setup-node@v2
25+
with:
26+
node-version: ${{ matrix.node }}
27+
architecture: ${{ matrix.arch }}
28+
- name: Install
29+
run: npm install
30+
- name: Test
31+
run: npm test
32+
- name: Coverage
33+
run: npm run coverage
34+
- name: Codecov
35+
uses: codecov/codecov-action@v2
36+
with:
37+
file: coverage/lcov.info
38+
- name: Test Electron
39+
if: ${{ matrix.node == '14' }}
40+
uses: GabrielBB/xvfb-action@v1
41+
with:
42+
run: npm run test-electron
43+
- name: Test GC
44+
run: npm run test-gc

README.md

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

4141
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`.
4242

43-
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:
43+
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:
4444

4545
- **Linux** (including ARM platforms such as Raspberry Pi and Kindle)
46-
- **Mac OS**
46+
- **Mac OS** (10.7 and later)
4747
- **Solaris** (SmartOS & Nodejitsu)
4848
- **FreeBSD**
4949
- **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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
"prebuild-linux-arm": "prebuildify-cross -i linux-armv6 -i linux-armv7 -i linux-arm64 -t 8.14.0 --napi --strip",
2222
"prebuild-android-arm": "prebuildify-cross -i android-armv7 -i android-arm64 -t 8.14.0 --napi --strip",
2323
"prebuild-linux-x64": "prebuildify-cross -i centos7-devtoolset7 -i alpine -t 8.14.0 --napi --strip",
24-
"prebuild-darwin-x64": "prebuildify -t 8.14.0 --napi --strip"
24+
"prebuild-darwin-x64+arm64": "prebuildify -t 8.14.0 --napi --strip --arch x64+arm64",
25+
"prebuild-win32-x86": "prebuildify -t 8.14.0 --napi --strip",
26+
"prebuild-win32-x64": "prebuildify -t 8.14.0 --napi --strip"
2527
},
2628
"dependencies": {
2729
"abstract-leveldown": "~6.2.1",
2830
"napi-macros": "~2.0.0",
29-
"node-gyp-build": "~4.1.0"
31+
"node-gyp-build": "^4.3.0"
3032
},
3133
"devDependencies": {
3234
"async-each": "^1.0.3",
@@ -44,7 +46,7 @@
4446
"mkfiletree": "^2.0.0",
4547
"node-gyp": "^6.0.0",
4648
"nyc": "^15.0.0",
47-
"prebuildify": "^3.0.0",
49+
"prebuildify": "^4.2.1",
4850
"prebuildify-ci": "^1.0.4",
4951
"prebuildify-cross": "github:prebuild/prebuildify-cross#v4.0.0",
5052
"readfiletree": "^1.0.0",

0 commit comments

Comments
 (0)