Skip to content

Commit 5066396

Browse files
authored
Merge pull request #1891 from JasonGross/mac-universal
Build universal (x86_64+arm64) binaries for MacOS
2 parents 1368f5f + 5cc3bf6 commit 5066396

File tree

2 files changed

+106
-22
lines changed

2 files changed

+106
-22
lines changed

.github/workflows/coq-macos.yml

+74-16
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ on:
1414
jobs:
1515
build:
1616

17-
runs-on: macOS-11
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
# macOS 11, 12, 13 are x86_64; macOS 14 is arm64
21+
include:
22+
- os: { name: 'macOS 11', arch: 'x86_64', runs-on: 'macos-11' } # move to macOS-12 when 11 is removed
23+
ocaml-compiler: '4.11.1'
24+
- os: { name: 'macOS 14', arch: 'arm64' , runs-on: 'macos-14' }
25+
ocaml-compiler: '4.14.2'
26+
27+
runs-on: ${{ matrix.os.runs-on }}
1828

1929
concurrency:
20-
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
30+
group: ${{ github.workflow }}-${{ matrix.os.runs-on }}-${{ matrix.ocaml-compiler }}-${{ github.head_ref || github.run_id }}
2131
cancel-in-progress: true
2232

2333
env:
@@ -28,7 +38,7 @@ jobs:
2838
OPAMYES: "true"
2939
OPAMCONFIRMLEVEL: "unsafe-yes"
3040

31-
name: macos
41+
name: ${{ matrix.os.name }} (${{ matrix.os.arch }})
3242

3343
steps:
3444
- uses: actions/checkout@v4
@@ -37,7 +47,7 @@ jobs:
3747
- name: Set up OCaml
3848
uses: ocaml/setup-ocaml@v2
3949
with:
40-
ocaml-compiler: 4.11.1
50+
ocaml-compiler: ${{ matrix.ocaml-compiler }}
4151

4252
- name: Install system dependencies
4353
run: brew install gnu-time gnu-sed coreutils grep
@@ -48,34 +58,41 @@ jobs:
4858
run: etc/ci/describe-system-config-macos.sh
4959
- name: deps
5060
run: opam exec -- etc/ci/github-actions-make.sh -j2 deps
61+
- name: all-except-js-of-ocaml
62+
run: opam exec -- etc/ci/github-actions-make.sh -j2 all-except-js-of-ocaml
63+
- name: pre-standalone-extracted
64+
run: opam exec -- etc/ci/github-actions-make.sh -j2 pre-standalone-extracted
5165
- name: all
5266
run: opam exec -- etc/ci/github-actions-make.sh -j2 all
67+
if: ${{ matrix.os.arch != 'arm64' }}
68+
# js_of_ocaml is too heavy for M1 GH Action runners which have only 7GB RAM, cf https://github.com/ocsigen/js_of_ocaml/issues/1612, https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
5369
- name: install-standalone-unified-ocaml
5470
run: opam exec -- etc/ci/github-actions-make.sh install-standalone-unified-ocaml BINDIR=dist
5571
- name: install-standalone-js-of-ocaml
5672
run: opam exec -- etc/ci/github-actions-make.sh install-standalone-js-of-ocaml
73+
if: ${{ matrix.os.arch != 'arm64' }}
5774
- name: only-test-amd64-files-lite
5875
run: opam exec -- etc/ci/github-actions-make.sh -j2 only-test-amd64-files-lite SLOWEST_FIRST=1
5976

6077
- name: upload OCaml files
6178
uses: actions/upload-artifact@v3
6279
with:
63-
name: ExtractionOCaml
80+
name: ExtractionOCaml-${{ matrix.os.arch }}
6481
path: src/ExtractionOCaml
6582
- name: upload js_of_ocaml files
6683
uses: actions/upload-artifact@v3
6784
with:
68-
name: ExtractionJsOfOCaml
85+
name: ExtractionJsOfOCaml-${{ matrix.os.arch }}
6986
path: src/ExtractionJsOfOCaml
7087
- name: upload standalone files
7188
uses: actions/upload-artifact@v3
7289
with:
73-
name: standalone-macos
90+
name: standalone-macos-${{ matrix.os.arch }}
7491
path: dist/fiat_crypto
7592
- name: upload standalone js files
7693
uses: actions/upload-artifact@v3
7794
with:
78-
name: standalone-html-macos
95+
name: standalone-html-macos-${{ matrix.os.arch }}
7996
path: fiat-html
8097
- name: install
8198
run: opam exec -- etc/ci/github-actions-make.sh EXTERNAL_DEPENDENCIES=1 SKIP_COQSCRIPTS_INCLUDE=1 install install-standalone-ocaml
@@ -90,7 +107,7 @@ jobs:
90107
# - name: upload timing and .vo info
91108
# uses: actions/upload-artifact@v3
92109
# with:
93-
# name: build-outputs
110+
# name: build-outputs-${{ matrix.os.arch }}
94111
# path: .
95112
# if: always ()
96113
# - name: validate
@@ -99,20 +116,57 @@ jobs:
99116
# make TIMED=1 validate COQCHKFLAGS="-o ${COQCHKEXTRAFLAGS}"
100117
# if: github.event_name != 'pull_request'
101118

102-
test-standalone:
119+
combine-standalone:
103120
runs-on: macos-latest
104121
needs: build
105122
steps:
106123
- uses: actions/checkout@v4
107-
- name: Download standalone MacOS
124+
- name: Download standalone MacOS x86_64
125+
uses: actions/download-artifact@v3
126+
with:
127+
name: standalone-macos-x86_64
128+
path: dist-x86_64/
129+
- name: Download standalone MacOS arm64
108130
uses: actions/download-artifact@v3
131+
with:
132+
name: standalone-macos-arm64
133+
path: dist-arm64/
134+
- name: Create universal binary
135+
run: |
136+
mkdir -p dist
137+
lipo -create -output dist/fiat_crypto dist-x86_64/fiat_crypto dist-arm64/fiat_crypto
138+
- name: upload universal binary
139+
uses: actions/upload-artifact@v3
109140
with:
110141
name: standalone-macos
142+
path: dist/fiat_crypto
143+
144+
test-standalone:
145+
strategy:
146+
fail-fast: false
147+
matrix:
148+
arch: ['', '-x86_64', '-arm64']
149+
os: ['macos-11', 'macos-12', 'macos-13', 'macos-14', 'macos-latest']
150+
exclude:
151+
- os: 'macos-11'
152+
arch: '-arm64'
153+
- os: 'macos-12'
154+
arch: '-arm64'
155+
- os: 'macos-13'
156+
arch: '-arm64'
157+
runs-on: ${{ matrix.os }}
158+
needs: [build, combine-standalone]
159+
steps:
160+
- uses: actions/checkout@v4
161+
- name: Download standalone MacOS${{ matrix.arch }}
162+
uses: actions/download-artifact@v3
163+
with:
164+
name: standalone-macos${{ matrix.arch }}
111165
path: dist/
112166
- name: List files
113167
run: find dist
114168
- run: chmod +x dist/fiat_crypto
115-
- name: Test files
169+
- name: Test files (${{ matrix.arch }} on ${{ matrix.os }})
116170
run: |
117171
echo "::group::file fiat_crypto"
118172
file dist/fiat_crypto
@@ -126,19 +180,23 @@ jobs:
126180
etc/ci/test-run-fiat-crypto.sh dist/fiat_crypto
127181
128182
publish-standalone:
183+
strategy:
184+
fail-fast: false
185+
matrix:
186+
arch: ['', '-x86_64', '-arm64']
129187
runs-on: ubuntu-latest
130-
needs: build
188+
needs: [build, combine-standalone]
131189
permissions:
132190
contents: write # IMPORTANT: mandatory for making GitHub Releases
133191
steps:
134192
- uses: actions/checkout@v4
135193
with:
136194
fetch-depth: 0 # Fetch all history for all tags and branches
137195
tags: true # Fetch all tags as well, `fetch-depth: 0` might be sufficient depending on Git version
138-
- name: Download standalone MacOS
196+
- name: Download standalone MacOS${{ matrix.arch }}
139197
uses: actions/download-artifact@v3
140198
with:
141-
name: standalone-macos
199+
name: standalone-macos${{ matrix.arch }}
142200
path: dist/
143201
- name: List files
144202
run: find dist
@@ -150,7 +208,7 @@ jobs:
150208
echo "$fname"
151209
mv dist/fiat_crypto "dist/$fname"
152210
find dist
153-
- name: Upload artifacts to GitHub Release
211+
- name: Upload macOS-${{ matrix.arch }} artifacts to GitHub Release
154212
env:
155213
GITHUB_TOKEN: ${{ github.token }}
156214
# Upload to GitHub Release using the `gh` CLI.

etc/ci/find-arch.sh

+32-6
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,47 @@ else
3333
group() { run "$@"; }
3434
fi
3535

36+
default_arch() {
37+
if [ -z "$default" ]; then
38+
printf "%s\n" "$1" | awk '{print $NF}'
39+
else
40+
printf "%s\n" "$default"
41+
fi
42+
>&2 echo "::warning::Unknown architecture ${file_info} (using ${arch})"
43+
}
44+
45+
3646
>&2 group file "$fname"
3747
>&2 group otool -L "$fname" || true
3848
>&2 group lipo -info "$fname" || true
3949
file_info="$(file "$fname" 2>&1)"
50+
4051
case "${file_info}" in
52+
*"Mach-O universal"*)
53+
arches=($(printf '%s' "${file_info}" | grep -o 'Mach-O universal.*' | grep -o '\[[^]:]*' | sed 's/^\[//g'))
54+
if [ "${#arches[@]}" -eq 1 ]; then
55+
arch="${arches[0]}"
56+
elif [ "${#arches[@]}" -gt 1 ]; then
57+
arch="universal"
58+
if [[ " ${arches[*]} " =~ " arm64 " ]] && [[ " ${arches[*]} " =~ " x86_64 " ]]; then
59+
:
60+
else
61+
for cur_arch in "${arches[@]}"; do
62+
arch="${arch}_${cur_arch}"
63+
done
64+
fi
65+
else
66+
arch="$(default_arch "${file_info}")"
67+
fi
68+
;;
4169
*x86_64*|*x86-64*)
4270
arch=x86_64
4371
;;
72+
*arm64*)
73+
arch=arm64
74+
;;
4475
*)
45-
if [ -z "$default" ]; then
46-
arch="$(printf "%s\n" "${file_info}" | awk '{print $NF}')"
47-
else
48-
arch="$default"
49-
fi
50-
>&2 echo "::warning::Unknown architecture ${file_info} (using ${arch})"
76+
arch="$(default_arch "${file_info}")"
5177
;;
5278
esac
5379

0 commit comments

Comments
 (0)