From 0bda9bae03efcd8adfc50f08d6cf9d28661e7bb9 Mon Sep 17 00:00:00 2001 From: Juan Gonzalez Date: Tue, 28 Sep 2021 15:56:59 +0200 Subject: [PATCH] Build a universal binary to support M1 (Apple silicon) (#181) 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 adds 'rocksdb/util/crc32c_arm64.cc' to the includes, needed for arm64 architectures in general. --- .github/workflows/release.yml | 5 +++-- .github/workflows/test.yml | 3 ++- binding.gyp | 8 +++++++- deps/rocksdb/rocksdb.gyp | 3 +++ deps/snappy/snappy.gyp | 4 ++++ package.json | 6 +++--- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 668a01a9..e081b969 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,8 +11,9 @@ jobs: include: - os: ubuntu-latest build-group: linux-x64 - - os: macos-latest - build-group: darwin-x64 + # At the time of writing macos-latest is mac 10; we need 11 to build a universal binary. + - os: macos-11 + build-group: darwin-x64+arm64 - os: windows-latest build-group: win32-x64 runs-on: ${{ matrix.os }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c8a9caf0..a647deb8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,8 @@ 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] runs-on: ${{ matrix.os }} name: ${{ matrix.os }} / Node ${{ matrix.node }} diff --git a/binding.gyp b/binding.gyp index 976e7cb0..0ecee2ab 100644 --- a/binding.gyp +++ b/binding.gyp @@ -41,8 +41,14 @@ '-mmacosx-version-min=10.8' , '-std=c++11' , '-stdlib=libc++' + , '-arch x86_64' + , '-arch arm64' + ] + , 'OTHER_LDFLAGS': [ + '-stdlib=libc++' + , '-arch x86_64' + , '-arch arm64' ] - , 'OTHER_LDFLAGS': ['-stdlib=libc++'] , 'GCC_ENABLE_CPP_RTTI': 'YES' , 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' , 'MACOSX_DEPLOYMENT_TARGET': '10.8' diff --git a/deps/rocksdb/rocksdb.gyp b/deps/rocksdb/rocksdb.gyp index c5f66637..523543f9 100644 --- a/deps/rocksdb/rocksdb.gyp +++ b/deps/rocksdb/rocksdb.gyp @@ -166,6 +166,8 @@ , '-stdlib=libc++' , '-fno-omit-frame-pointer' , '-momit-leaf-frame-pointer' + , '-arch x86_64' + , '-arch arm64' ] # , 'OTHER_LDFLAGS': ['-stdlib=libc++'] , 'GCC_ENABLE_CPP_RTTI': 'YES' @@ -376,6 +378,7 @@ , 'rocksdb/util/compression_context_cache.cc' , 'rocksdb/util/concurrent_task_limiter_impl.cc' , 'rocksdb/util/crc32c.cc' + , 'rocksdb/util/crc32c_arm64.cc' , 'rocksdb/util/dynamic_bloom.cc' , 'rocksdb/util/hash.cc' , 'rocksdb/util/murmurhash.cc' diff --git a/deps/snappy/snappy.gyp b/deps/snappy/snappy.gyp index 1041e4fb..2c898cfa 100644 --- a/deps/snappy/snappy.gyp +++ b/deps/snappy/snappy.gyp @@ -71,6 +71,10 @@ '-Wno-sign-compare' , '-Wno-unused-function' ] + , 'OTHER_CFLAGS': [ + '-arch x86_64' + , '-arch arm64' + ] } }] ] diff --git a/package.json b/package.json index 8241ce5f..edb8ef17 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "rebuild": "npm run install --build-from-source", "prebuild": "prebuildify -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-x64": "prebuildify -t 8.14.0 --napi --strip", "download-prebuilds": "prebuildify-ci download", "hallmark": "hallmark --fix", @@ -24,7 +24,7 @@ "dependencies": { "abstract-leveldown": "^7.0.0", "napi-macros": "^2.0.0", - "node-gyp-build": "^4.2.3" + "node-gyp-build": "^4.3.0" }, "devDependencies": { "async-each": "^1.0.3", @@ -40,7 +40,7 @@ "mkfiletree": "^2.0.0", "node-gyp": "^7.1.2", "nyc": "^15.0.0", - "prebuildify": "^4.1.1", + "prebuildify": "^4.2.1", "prebuildify-ci": "^1.0.4", "prebuildify-cross": "^4.0.1", "readfiletree": "^1.0.0",