Skip to content

Commit

Permalink
build universal macOS binaries on arm64 runners
Browse files Browse the repository at this point in the history
  • Loading branch information
iliana committed Oct 30, 2024
1 parent 76e176e commit 78e7a67
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
41 changes: 38 additions & 3 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ on:
pull_request:

jobs:
build:
runs-on: macos-13
build-arch:
strategy:
matrix:
arch:
- arch: amd64
makeargs: >-
XGOOS=darwin XGOARCH=amd64 TARGET_TRIPLE=x86_64-apple-darwin19 XCC=cc XCXX=c++
EXTRA_XCMAKE_FLAGS=-DCMAKE_OSX_ARCHITECTURES=x86_64
EXTRA_XCONFIGURE_FLAGS="CFLAGS='-arch x86_64'"
- arch: arm64
runs-on: macos-14
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
Expand All @@ -18,9 +27,35 @@ jobs:
source .github/workflows/macos-setup.sh
echo "PATH=$PATH" >>"$GITHUB_ENV"
- name: Build
run: gmake -j`sysctl -n hw.ncpu` cockroach.tgz BUILDTYPE=release
run: gmake -j`sysctl -n hw.ncpu` cockroachoss BUILDTYPE=release ${{ matrix.arch.makeargs }}
env:
BROWSERSLIST_IGNORE_OLD_DATA: 1
CGO_ENABLED: 1
MACOSX_DEPLOYMENT_TARGET: 13
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: ${{ matrix.arch.arch }}
path: |
cockroachoss
lib/libgeos.dylib
lib/libgeos_c.dylib
if-no-files-found: error
compression-level: 0

build:
needs: build-arch
runs-on: macos-14
steps:
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
- name: Create universal binaries
run: |
mkdir -p artifacts/cockroach/lib
lipo -create -output artifacts/cockroach/cockroach {amd64,arm64}/cockroachoss
for lib in libgeos.dylib libgeos_c.dylib; do
lipo -create -output artifacts/cockroach/lib/$lib {amd64,arm64}/lib/$lib
done
tar -cvf - -C artifacts cockroach | gzip -9 > cockroach.tgz
sha256sum cockroach.tgz | awk '{ print $1 }' > cockroach.tgz.sha256
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: build
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/macos-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ brew install coreutils make

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

# Apply patch to fix golang/go#53000
pushd go/src
patch -p2 <"$SOURCE_DIR/.github/workflows/e66f895667cd51d0d28c42d369a803c12db8bb35.patch"
go build cmd/cgo
popd
mv go/src/cgo go/pkg/tool/darwin_amd64/cgo
mv go/src/cgo go/pkg/tool/darwin_arm64/cgo

popd
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,9 @@ endif
GEOS_NATIVE_LIB_DIR = $(GEOS_DIR)/$(if $(target-is-windows),bin,lib)
ifdef geos_require_install_name_tool
$(LIBGEOS): libgeos_inner .ALWAYS_REBUILD
$(TARGET_TRIPLE)-install_name_tool -id @rpath/libgeos.3.8.1.dylib lib/libgeos.dylib
$(TARGET_TRIPLE)-install_name_tool -id @rpath/libgeos_c.1.dylib lib/libgeos_c.dylib
$(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
install_name_tool -id @rpath/libgeos.3.8.1.dylib lib/libgeos.dylib
install_name_tool -id @rpath/libgeos_c.1.dylib lib/libgeos_c.dylib
install_name_tool -change "$(GEOS_NATIVE_LIB_DIR)/libgeos.3.8.1.dylib" "@rpath/libgeos.3.8.1.dylib" lib/libgeos_c.dylib
else ifdef geos_require_patchelf
# We apply a similar fix for linux, allowing one to dlopen libgeos_c.so without
# dlopening libgeos.so. Setting the rpath in the CMakeLists.txt does not work
Expand Down

0 comments on commit 78e7a67

Please sign in to comment.