Skip to content

Commit 61bedf2

Browse files
committed
build universal macOS binaries on arm64 runners
1 parent b1dfb4c commit 61bedf2

File tree

4 files changed

+60
-16
lines changed

4 files changed

+60
-16
lines changed

.github/buildomat/jobs/artifacts-macos.sh

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
#: series = "darwin-amd64"
1818
#: name = "cockroach.tgz.sha256"
1919
#: from_output = "/work/oxidecomputer/cockroach/cockroach.tgz.sha256"
20+
#:
21+
#: [[publish]]
22+
#: series = "darwin-arm64"
23+
#: name = "cockroach.tgz"
24+
#: from_output = "/work/oxidecomputer/cockroach/cockroach.tgz"
25+
#:
26+
#: [[publish]]
27+
#: series = "darwin-arm64"
28+
#: name = "cockroach.tgz.sha256"
29+
#: from_output = "/work/oxidecomputer/cockroach/cockroach.tgz.sha256"
2030

2131
set -o errexit
2232
set -o pipefail

.github/workflows/build-macos.yml

+37-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@ on:
55
pull_request:
66

77
jobs:
8-
build:
9-
runs-on: macos-13
8+
build-arch:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
arch:
13+
- arch: amd64
14+
makeargs: >-
15+
XGOOS=darwin XGOARCH=amd64 TARGET_TRIPLE=x86_64-apple-darwin19 XCC=cc XCXX=c++
16+
EXTRA_XCMAKE_FLAGS=-DCMAKE_OSX_ARCHITECTURES=x86_64
17+
EXTRA_XCONFIGURE_FLAGS="CFLAGS='-arch x86_64'"
18+
- arch: arm64
19+
runs-on: macos-14
1020
steps:
1121
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
1222
with:
@@ -18,9 +28,33 @@ jobs:
1828
source .github/workflows/macos-setup.sh
1929
echo "PATH=$PATH" >>"$GITHUB_ENV"
2030
- name: Build
21-
run: gmake -j`sysctl -n hw.ncpu` cockroach.tgz BUILDTYPE=release
31+
run: gmake -j`sysctl -n hw.ncpu` cockroachoss BUILDTYPE=release ${{ matrix.arch.makeargs }}
2232
env:
2333
BROWSERSLIST_IGNORE_OLD_DATA: 1
34+
CGO_ENABLED: 1
35+
MACOSX_DEPLOYMENT_TARGET: 13
36+
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
37+
with:
38+
name: ${{ matrix.arch.arch }}
39+
path: |
40+
cockroachoss
41+
lib/libgeos.dylib
42+
lib/libgeos_c.dylib
43+
if-no-files-found: error
44+
45+
build:
46+
needs: build-arch
47+
runs-on: macos-14
48+
steps:
49+
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
50+
- name: Create universal binaries
51+
run: |
52+
mkdir -p artifacts/cockroach/lib
53+
lipo -create -output artifacts/cockroach/cockroach {amd64,arm64}/cockroachoss
54+
lipo -create -output artifacts/cockroach/lib/libgeos.dylib {amd64,arm64}/lib/libgeos.dylib
55+
lipo -create -output artifacts/cockroach/lib/libgeos_c.dylib {amd64,arm64}/lib/libgeos_c.dylib
56+
tar -cvf - -C artifacts cockroach | gzip -9 > cockroach.tgz
57+
sha256sum cockroach.tgz | awk '{ print $1 }' > cockroach.tgz.sha256
2458
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
2559
with:
2660
name: build

.github/workflows/macos-setup.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
SOURCE_DIR=$PWD
22
source .github/buildomat/versions.sh
33

4-
brew install coreutils make
4+
brew install autoconf coreutils make
55

66
mkdir "$HOME/toolchain"
77
pushd "$HOME/toolchain"
8-
curl -sSfL --retry 10 -O "https://go.dev/dl/go$GO_VERSION.darwin-amd64.tar.gz"
9-
curl -sSfL --retry 10 -O "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-darwin-x64.tar.xz"
8+
curl -sSfL --retry 10 -O "https://go.dev/dl/go$GO_VERSION.darwin-arm64.tar.gz"
9+
curl -sSfL --retry 10 -O "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-darwin-arm64.tar.xz"
1010
curl -sSfL --retry 10 -O "https://github.com/yarnpkg/yarn/releases/download/v$YARN_VERSION/yarn-$YARN_VERSION.js"
11-
sha256sum --ignore-missing -c "$OLDPWD/.github/buildomat/SHA256SUMS"
12-
tar xf "go$GO_VERSION.darwin-amd64.tar.gz"
13-
tar xf "node-v$NODE_VERSION-darwin-x64.tar.xz"
14-
mv "yarn-$YARN_VERSION.js" "node-v$NODE_VERSION-darwin-x64/bin/yarn"
15-
chmod a+x "node-v$NODE_VERSION-darwin-x64/bin/yarn"
16-
export PATH="$PWD/go/bin:$PWD/node-v$NODE_VERSION-darwin-x64/bin:$PATH"
11+
sha256sum --ignore-missing -c "$SOURCE_DIR/.github/buildomat/SHA256SUMS"
12+
tar xf "go$GO_VERSION.darwin-arm64.tar.gz"
13+
tar xf "node-v$NODE_VERSION-darwin-arm64.tar.xz"
14+
mv "yarn-$YARN_VERSION.js" "node-v$NODE_VERSION-darwin-arm64/bin/yarn"
15+
chmod a+x "node-v$NODE_VERSION-darwin-arm64/bin/yarn"
16+
export PATH="$PWD/go/bin:$PWD/node-v$NODE_VERSION-darwin-arm64/bin:$PATH"
1717

1818
# Apply patch to fix golang/go#53000
1919
pushd go/src
2020
patch -p2 <"$SOURCE_DIR/.github/workflows/e66f895667cd51d0d28c42d369a803c12db8bb35.patch"
2121
go build cmd/cgo
2222
popd
23-
mv go/src/cgo go/pkg/tool/darwin_amd64/cgo
23+
mv go/src/cgo go/pkg/tool/darwin_arm64/cgo
2424

2525
popd

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,9 @@ endif
617617
GEOS_NATIVE_LIB_DIR = $(GEOS_DIR)/$(if $(target-is-windows),bin,lib)
618618
ifdef geos_require_install_name_tool
619619
$(LIBGEOS): libgeos_inner .ALWAYS_REBUILD
620-
$(TARGET_TRIPLE)-install_name_tool -id @rpath/libgeos.3.8.1.dylib lib/libgeos.dylib
621-
$(TARGET_TRIPLE)-install_name_tool -id @rpath/libgeos_c.1.dylib lib/libgeos_c.dylib
622-
$(TARGET_TRIPLE)-install_name_tool -change "$(GEOS_NATIVE_LIB_DIR)/libgeos.3.8.1.dylib" "@rpath/libgeos.3.8.1.dylib" lib.docker_amd64/libgeos_c.dylib
620+
install_name_tool -id @rpath/libgeos.3.8.1.dylib lib/libgeos.dylib
621+
install_name_tool -id @rpath/libgeos_c.1.dylib lib/libgeos_c.dylib
622+
install_name_tool -change "$(GEOS_NATIVE_LIB_DIR)/libgeos.3.8.1.dylib" "@rpath/libgeos.3.8.1.dylib" lib/libgeos_c.dylib
623623
else ifdef geos_require_patchelf
624624
# We apply a similar fix for linux, allowing one to dlopen libgeos_c.so without
625625
# dlopening libgeos.so. Setting the rpath in the CMakeLists.txt does not work

0 commit comments

Comments
 (0)