Skip to content

Commit

Permalink
No longer need cross compilation
Browse files Browse the repository at this point in the history
We have access to M1 runners
  • Loading branch information
topjohnwu committed Feb 1, 2024
1 parent 1662100 commit fdb6b9d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 19 deletions.
48 changes: 39 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ jobs:
env:
SKIP_DIST: 1
run: |
./build.sh x86_64
./build.sh
mkdir tmp
tar c rust/build | xz --x86 --lzma2 > tmp/build.tar.xz
tar c out | xz --x86 --lzma2 > tmp/out.tar.xz
tar c out | xz --x86 --lzma2 > tmp/out.x64.tar.xz
- name: Upload build artifact
uses: actions/upload-artifact@v3
Expand All @@ -108,8 +107,7 @@ jobs:

macos-arm64:
name: Build for macOS (arm64)
runs-on: macos-13
needs: macos-x64
runs-on: macos-14

steps:
- name: Check out
Expand All @@ -122,16 +120,42 @@ jobs:
with:
python-version: "3.x"

- name: Build toolchain
env:
SKIP_DIST: 1
run: |
./build.sh
mkdir tmp
tar c out | xz > tmp/out.arm64.tar.xz
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: macos-arm64
path: tmp/*.tar.xz

macos:
name: Build for macOS (Universal)
runs-on: macos-14
needs: [macos-x64, macos-arm64]

steps:
- name: Check out
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Download x64 artifacts
uses: actions/download-artifact@v3
with:
name: macos-x64
path: tmp

- name: Build toolchain
env:
SKIP_DIST: 1
run: ./build.sh aarch64
- name: Download arm64 artifacts
uses: actions/download-artifact@v3
with:
name: macos-arm64
path: tmp

- name: Build ONDK
run: ./dist-macos.sh
Expand All @@ -154,3 +178,9 @@ jobs:
with:
name: macos-x64
failOnError: false

- name: Remove arm64 artifact
uses: geekyeggo/delete-artifact@v2
with:
name: macos-arm64
failOnError: false
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if [ $OS = "darwin" ]; then
DYN_EXT='dylib'

# Hardcode to 16k page to support both x64 and arm64
export JEMALLOC_SYS_WITH_LG_PAGE=14
# export JEMALLOC_SYS_WITH_LG_PAGE=14

command -v ninja >/dev/null || brew install ninja
else
Expand Down
17 changes: 8 additions & 9 deletions dist-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
# SPDX-License-Identifier: Apache-2.0

# This script is for generating universal binaries
# The x86_64 output should be archived to "tmp/out.tar.xz"
# The arm64 output should be placed in the folder "out"

set -e

mv out out.arm
xz -d < tmp/out.tar.xz | tar x
mv out out.x86
xz -d < tmp/out.x64.tar.xz | tar x
mv out out.x64
xz -d < tmp/out.arm64.tar.xz | tar x
mv out out.arm64

cp -af out.x86 out
cp -an out.arm/. out/. || true
cp -af out.x64 out
cp -an out.arm64/. out/. || true

# Merge all Mach-O files as universal binary and adhoc codesign
find out -type f -exec sh -c "file {} | grep -q Mach-O" \; -print0 | \
while IFS= read -r -d '' o; do
a="${o/out/out.x86}"
b="${o/out/out.arm}"
a="${o/out/out.x64}"
b="${o/out/out.arm64}"
if [ -f "$a" -a -f "$b" ]; then
lipo -create -output "$o" "$a" "$b"
fi
Expand Down

0 comments on commit fdb6b9d

Please sign in to comment.