Skip to content

Commit 5ee3df8

Browse files
committed
Attempt MacOS universal build
1 parent bd0fd01 commit 5ee3df8

File tree

4 files changed

+115
-110
lines changed

4 files changed

+115
-110
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,55 +49,20 @@ jobs:
4949
bin/openocd-*-x64-win.zip
5050
bin/riscv-toolchain-*-x64-win.zip
5151
52-
build_macos_arm64:
53-
name: Build MacOS Arm64
52+
build_macos:
53+
name: Build MacOS
5454
# runs-on: [self-hosted, macOS]
5555
runs-on: 'macos-14'
5656

5757
steps:
5858
- name: Checkout
5959
uses: actions/checkout@v4
60-
- name: Set up Homebrew
60+
- name: Set up arm64 Homebrew
6161
if: runner.environment == 'github-hosted'
6262
id: set-up-homebrew
6363
uses: Homebrew/actions/setup-homebrew@master
64-
- name: Set up x86_64 Homebrew
65-
if: runner.environment == 'github-hosted'
66-
run: |
67-
NONINTERACTIVE=1 arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
68-
# - name: Setup SSH Auth
69-
# if: runner.environment == 'github-hosted'
70-
# uses: webfactory/[email protected]
71-
# with:
72-
# ssh-private-key: ${{ secrets.SSH_KEY }}
7364
- name: Build
7465
run: ./build_macos.sh
75-
- name: Upload Artifact
76-
uses: actions/upload-artifact@v4
77-
with:
78-
name: tools-mac-${{ runner.arch }}
79-
path: |
80-
bin/picotool-*-mac.zip
81-
bin/pico-sdk-tools-*-mac.zip
82-
bin/openocd-*-mac.zip
83-
bin/riscv-toolchain-*.zip
84-
- name: Add Release Asset
85-
uses: softprops/action-gh-release@v2
86-
if: startsWith(github.ref, 'refs/tags/')
87-
with:
88-
files: |
89-
bin/picotool-*-mac.zip
90-
bin/pico-sdk-tools-*-mac.zip
91-
bin/openocd-*-mac.zip
92-
bin/riscv-toolchain-*.zip
93-
94-
build_macos_x64:
95-
name: Build MacOS x64 on arm64
96-
runs-on: 'macos-14'
97-
98-
steps:
99-
- name: Checkout
100-
uses: actions/checkout@v4
10166
- name: Uninstall arm64 Homebrew
10267
if: runner.environment == 'github-hosted'
10368
run: |
@@ -113,15 +78,17 @@ jobs:
11378
arch -x86_64 /usr/local/bin/brew install pkg-config cmake
11479
- name: Build
11580
run: arch -x86_64 ./build_macos.sh
81+
- name: Merge Universal Binaries
82+
run: ./merge_macos.sh
11683
- name: Upload Artifact
11784
uses: actions/upload-artifact@v4
11885
with:
119-
name: tools-mac-X64
86+
name: tools-mac-universal
12087
path: |
12188
bin/picotool-*-mac.zip
12289
bin/pico-sdk-tools-*-mac.zip
12390
bin/openocd-*-mac.zip
124-
bin/riscv-toolchain-*.zip
91+
bin/riscv-toolchain-*-mac.zip
12592
- name: Add Release Asset
12693
uses: softprops/action-gh-release@v2
12794
if: startsWith(github.ref, 'refs/tags/')
@@ -130,7 +97,7 @@ jobs:
13097
bin/picotool-*-mac.zip
13198
bin/pico-sdk-tools-*-mac.zip
13299
bin/openocd-*-mac.zip
133-
bin/riscv-toolchain-*.zip
100+
bin/riscv-toolchain-*-mac.zip
134101
135102
build_linux:
136103
name: Build Linux

build_macos.sh

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -87,64 +87,3 @@ if [[ "$SKIP_PICOTOOL" != 1 ]]; then
8787
echo "Picotool dylibs copied"
8888
fi
8989
cd ..
90-
91-
topd=$PWD
92-
93-
if [[ "$SKIP_PICOTOOL" != 1 ]]; then
94-
echo "Packaging picotool"
95-
if [ ${version:0:1} -ge 2 ]; then
96-
# Package pico-sdk-tools separately as well
97-
98-
filename="pico-sdk-tools-${version}-${suffix}.zip"
99-
100-
echo "Saving pico-sdk-tools package to $filename"
101-
pushd "$builddir/pico-sdk-tools-$(uname -m)/"
102-
tar -a -cf "$topd/bin/$filename" * .keep
103-
popd
104-
fi
105-
106-
# Package picotool separately as well
107-
version=$("./$builddir/picotool-install-$(uname -m)/picotool/picotool" version -s)
108-
echo "Picotool version $version"
109-
110-
filename="picotool-${version}-${suffix}.zip"
111-
112-
echo "Saving picotool package to $filename"
113-
pushd "$builddir/picotool-install-$(uname -m)/"
114-
tar -a -cf "$topd/bin/$filename" * .keep
115-
popd
116-
fi
117-
118-
if [[ "$SKIP_OPENOCD" != 1 ]]; then
119-
echo "Packaging OpenOCD"
120-
# Package OpenOCD separately as well
121-
122-
version=($("./$builddir/openocd-install-$(uname -m)/usr/local/bin/openocd" --version 2>&1))
123-
version=${version[0]}
124-
version=${version[3]}
125-
version=$(echo $version | cut -d "-" -f 1)
126-
127-
echo "OpenOCD version $version"
128-
129-
filename="openocd-${version}-$(uname -m)-${suffix}.zip"
130-
131-
echo "Saving OpenOCD package to $filename"
132-
pushd "$builddir/openocd-install-$(uname -m)/usr/local/bin"
133-
tar -a -cf "$topd/bin/$filename" * -C "../share/openocd" "scripts"
134-
popd
135-
fi
136-
137-
if [[ "$SKIP_RISCV" != 1 ]]; then
138-
echo "Packaging RISC-V Toolchain"
139-
# Package riscv toolchain separately as well
140-
version=$("./$builddir/riscv-install-$(uname -m)/bin/riscv32-unknown-elf-gcc" -dumpversion)
141-
version=$(echo $version | cut -d "." -f 1)
142-
echo "Risc-V Toolchain version $version"
143-
144-
filename="riscv-toolchain-${version}-$(uname -m)-${suffix}.zip"
145-
146-
echo "Saving RISC-V Toolchain package to $filename"
147-
pushd "$builddir/riscv-install-$(uname -m)/"
148-
tar -a -cf "$topd/bin/$filename" *
149-
popd
150-
fi

merge_macos.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Defaults
6+
SKIP_RISCV=${SKIP_RISCV-0}
7+
SKIP_OPENOCD=${SKIP_OPENOCD-0}
8+
SKIP_PICOTOOL=${SKIP_PICOTOOL-0}
9+
10+
echo "Running on $(uname -m)"
11+
12+
export version=$(cat ./version.txt)
13+
suffix="mac"
14+
builddir="build"
15+
16+
cd $builddir
17+
if [[ "$SKIP_OPENOCD" != 1 ]]; then
18+
../packages/macos/make-universal.sh "openocd-install"
19+
echo "OpenOCD Merge Complete"
20+
fi
21+
if [[ "$SKIP_RISCV" != 1 ]]; then
22+
../packages/macos/make-universal.sh "riscv-install"
23+
echo "RISC-V Merge Complete"
24+
fi
25+
if [[ "$SKIP_PICOTOOL" != 1 ]]; then
26+
../packages/macos/make-universal.sh "picotool-install"
27+
echo "Picotool Merge Complete"
28+
29+
if [ ${version:0:1} -ge 2 ]; then
30+
../packages/macos/make-universal.sh "pico-sdk-tools"
31+
echo "Pico SDK Tools Merge Complete"
32+
fi
33+
fi
34+
cd ..
35+
36+
topd=$PWD
37+
38+
if [[ "$SKIP_PICOTOOL" != 1 ]]; then
39+
echo "Packaging picotool"
40+
if [ ${version:0:1} -ge 2 ]; then
41+
# Package pico-sdk-tools separately as well
42+
43+
filename="pico-sdk-tools-${version}-${suffix}.zip"
44+
45+
echo "Saving pico-sdk-tools package to $filename"
46+
pushd "$builddir/pico-sdk-tools/"
47+
tar -a -cf "$topd/bin/$filename" * .keep
48+
popd
49+
fi
50+
51+
# Package picotool separately as well
52+
version=$("./$builddir/picotool-install/picotool/picotool" version -s)
53+
echo "Picotool version $version"
54+
55+
filename="picotool-${version}-${suffix}.zip"
56+
57+
echo "Saving picotool package to $filename"
58+
pushd "$builddir/picotool-install/"
59+
tar -a -cf "$topd/bin/$filename" * .keep
60+
popd
61+
fi
62+
63+
if [[ "$SKIP_OPENOCD" != 1 ]]; then
64+
echo "Packaging OpenOCD"
65+
# Package OpenOCD separately as well
66+
67+
version=($("./$builddir/openocd-install/usr/local/bin/openocd" --version 2>&1))
68+
version=${version[0]}
69+
version=${version[3]}
70+
version=$(echo $version | cut -d "-" -f 1)
71+
72+
echo "OpenOCD version $version"
73+
74+
filename="openocd-${version}-${suffix}.zip"
75+
76+
echo "Saving OpenOCD package to $filename"
77+
pushd "$builddir/openocd-install/usr/local/bin"
78+
tar -a -cf "$topd/bin/$filename" * -C "../share/openocd" "scripts"
79+
popd
80+
fi
81+
82+
if [[ "$SKIP_RISCV" != 1 ]]; then
83+
echo "Packaging RISC-V Toolchain"
84+
# Package riscv toolchain separately as well
85+
version=$("./$builddir/riscv-install/bin/riscv32-unknown-elf-gcc" -dumpversion)
86+
version=$(echo $version | cut -d "." -f 1)
87+
echo "Risc-V Toolchain version $version"
88+
89+
filename="riscv-toolchain-${version}-${suffix}.zip"
90+
91+
echo "Saving RISC-V Toolchain package to $filename"
92+
pushd "$builddir/riscv-install/"
93+
tar -a -cf "$topd/bin/$filename" *
94+
popd
95+
fi

packages/macos/make-universal.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
set -euo pipefail
44

55
INSTALLDIR=$1
6-
BINDIR=$2
7-
BINNAME=$3
86

97
rm -rf $INSTALLDIR
108
mkdir -p $INSTALLDIR
119

1210
cp -r $INSTALLDIR-arm64/* $INSTALLDIR
1311
touch $INSTALLDIR/.keep
1412

15-
lipo -create -output $INSTALLDIR/$BINDIR/$BINNAME $INSTALLDIR-x86_64/$BINDIR/$BINNAME $INSTALLDIR-arm64/$BINDIR/$BINNAME
16-
17-
for f in $INSTALLDIR-arm64/$BINDIR/*.dylib; do
18-
if [ -f $INSTALLDIR-arm64/$BINDIR/$(basename $f) ]; then
19-
lipo -create -output $INSTALLDIR/$BINDIR/$(basename $f) $INSTALLDIR-x86_64/$BINDIR/$(basename $f) $INSTALLDIR-arm64/$BINDIR/$(basename $f)
13+
FILES=$(find $INSTALLDIR -type f)
14+
echo "Files: $FILES"
15+
while IFS= read -r file; do
16+
file_arm64=$(sed "s|$INSTALLDIR|$INSTALLDIR-arm64|" <<< $file)
17+
file_x86_64=$(sed "s|$INSTALLDIR|$INSTALLDIR-x86_64|" <<< $file)
18+
if file $file | grep "Mach-O 64-bit executable" > /dev/null; then
19+
echo "Processing executable: $file $file_x86_64 $file_arm64"
20+
lipo -create -output $file $file_x86_64 $file_arm64
21+
elif file $file | grep "Mach-O 64-bit dynamic library" > /dev/null; then
22+
echo "Processing dynamic library: $file $file_x86_64 $file_arm64"
23+
lipo -create -output $file $file_x86_64 $file_arm64
2024
fi
21-
done
25+
done <<< "$FILES"

0 commit comments

Comments
 (0)