Skip to content

Commit 4ea5d0d

Browse files
committed
Add x64 MacOS build of OpenOCD and Risc-V toolchain
1 parent 4c49895 commit 4ea5d0d

File tree

7 files changed

+110
-106
lines changed

7 files changed

+110
-106
lines changed

.github/workflows/build.yml

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

@@ -75,7 +75,7 @@ jobs:
7575
- name: Upload Artifact
7676
uses: actions/upload-artifact@v4
7777
with:
78-
name: tools-mac
78+
name: tools-mac-arm64
7979
path: |
8080
bin/picotool-*-mac.zip
8181
bin/pico-sdk-tools-*-mac.zip
@@ -90,6 +90,37 @@ jobs:
9090
bin/pico-sdk-tools-*-mac.zip
9191
bin/openocd-*-mac.zip
9292
bin/riscv-toolchain-*.zip
93+
94+
build_macos_x64:
95+
name: Build MacOS x64
96+
runs-on: 'macos-13'
97+
env:
98+
# Universal picotool is built on arm64
99+
SKIP_PICOTOOL: 1
100+
101+
steps:
102+
- name: Checkout
103+
uses: actions/checkout@v4
104+
- name: Set up Homebrew
105+
if: runner.environment == 'github-hosted'
106+
id: set-up-homebrew
107+
uses: Homebrew/actions/setup-homebrew@master
108+
- name: Build
109+
run: ./build_macos.sh
110+
- name: Upload Artifact
111+
uses: actions/upload-artifact@v4
112+
with:
113+
name: tools-mac-x64
114+
path: |
115+
bin/openocd-*-mac.zip
116+
bin/riscv-toolchain-*.zip
117+
- name: Add Release Asset
118+
uses: softprops/action-gh-release@v2
119+
if: startsWith(github.ref, 'refs/tags/')
120+
with:
121+
files: |
122+
bin/openocd-*-mac.zip
123+
bin/riscv-toolchain-*.zip
93124
94125
build_linux:
95126
name: Build Linux

build_macos.sh

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ set -euo pipefail
55
# Defaults
66
SKIP_RISCV=${SKIP_RISCV-0}
77
SKIP_OPENOCD=${SKIP_OPENOCD-0}
8+
SKIP_PICOTOOL=${SKIP_PICOTOOL-0}
89

910
# Install prerequisites
1011
arch -x86_64 /usr/local/bin/brew install jq libtool libusb automake hidapi jimtcl --quiet
11-
arch -arm64 /opt/homebrew/bin/brew install jq libtool libusb automake hidapi jimtcl --quiet
12+
if [[ $(uname -m) == 'arm64' ]]; then
13+
arch -arm64 /opt/homebrew/bin/brew install jq libtool libusb automake hidapi jimtcl --quiet
14+
fi
1215
# RISC-V prerequisites
1316
echo "Listing local"
1417
ls /usr/local/bin
@@ -17,7 +20,9 @@ rm /usr/local/bin/idle3* || true
1720
rm /usr/local/bin/pip* || true
1821
rm /usr/local/bin/py* || true
1922
arch -x86_64 /usr/local/bin/brew install python3 gawk gnu-sed make gmp mpfr libmpc isl zlib expat texinfo flock libslirp --quiet
20-
arch -arm64 /opt/homebrew/bin/brew install python3 gawk gnu-sed make gmp mpfr libmpc isl zlib expat texinfo flock libslirp --quiet
23+
if [[ $(uname -m) == 'arm64' ]]; then
24+
arch -arm64 /opt/homebrew/bin/brew install python3 gawk gnu-sed make gmp mpfr libmpc isl zlib expat texinfo flock libslirp --quiet
25+
fi
2126

2227
repos=$(cat config/repositories.json | jq -c '.repositories.[]')
2328
export version=$(cat ./version.txt)
@@ -51,83 +56,89 @@ done < <(echo "$repos")
5156

5257

5358
cd $builddir
54-
if [[ "$SKIP_OPENOCD" != 1 ]] && [[ $(uname -m) == 'arm64' ]]; then
59+
if [[ "$SKIP_OPENOCD" != 1 ]]; then
5560
if ! ../packages/macos/openocd/build-openocd.sh; then
5661
echo "::error title=openocd-fail-macos::OpenOCD Build Failed on macOS"
5762
SKIP_OPENOCD=1
5863
fi
64+
echo "OpenOCD Build Complete"
5965
fi
6066
if [[ "$SKIP_RISCV" != 1 ]]; then
6167
# Takes ages to build
6268
../packages/macos/riscv/build-riscv-gcc.sh
69+
echo "RISC-V Build Complete"
70+
fi
71+
if [[ "$SKIP_PICOTOOL" != 1 ]]; then
72+
arch -x86_64 ../packages/macos/picotool/build-picotool.sh
73+
if [[ $(uname -m) == 'arm64' ]]; then
74+
arch -arm64 ../packages/macos/picotool/build-picotool.sh
75+
fi
76+
echo "Picotool Build Complete"
77+
78+
../packages/macos/make-universal.sh "pico-sdk-tools" "pioasm" "pioasm"
79+
echo "Pioasm Universal Merge Complete"
80+
../packages/macos/make-universal.sh "picotool-install" "picotool" "picotool"
81+
echo "Picotool Universal Merge Complete"
6382
fi
64-
arch -x86_64 ../packages/macos/picotool/build-picotool.sh
65-
arch -arm64 ../packages/macos/picotool/build-picotool.sh
66-
../packages/macos/picotool/merge-picotool.sh
6783
cd ..
6884

6985
topd=$PWD
70-
if [ ${version:0:1} -ge 2 ]; then
71-
# Package pico-sdk-tools separately as well
7286

73-
filename="pico-sdk-tools-${version}-${suffix}.zip"
87+
if [[ "$SKIP_PICOTOOL" != 1 ]]; then
88+
echo "Packaging picotool"
89+
if [ ${version:0:1} -ge 2 ]; then
90+
# Package pico-sdk-tools separately as well
7491

75-
echo "Saving pico-sdk-tools package to $filename"
76-
pushd "$builddir/pico-sdk-tools/"
77-
tar -a -cf "$topd/bin/$filename" * .keep
78-
popd
79-
fi
92+
filename="pico-sdk-tools-${version}-${suffix}.zip"
8093

81-
# Package picotool separately as well
82-
version=$("./$builddir/picotool-install/picotool/picotool" version -s)
83-
echo "Picotool version $version"
94+
echo "Saving pico-sdk-tools package to $filename"
95+
pushd "$builddir/pico-sdk-tools/"
96+
tar -a -cf "$topd/bin/$filename" * .keep
97+
popd
98+
fi
8499

85-
filename="picotool-${version}-${suffix}.zip"
100+
# Package picotool separately as well
101+
version=$("./$builddir/picotool-install/picotool/picotool" version -s)
102+
echo "Picotool version $version"
86103

87-
echo "Saving picotool package to $filename"
88-
pushd "$builddir/picotool-install/"
89-
tar -a -cf "$topd/bin/$filename" * .keep
90-
popd
104+
filename="picotool-${version}-${suffix}.zip"
91105

92-
if [[ "$SKIP_OPENOCD" != 1 ]] && [[ $(uname -m) == 'arm64' ]]; then
106+
echo "Saving picotool package to $filename"
107+
pushd "$builddir/picotool-install/"
108+
tar -a -cf "$topd/bin/$filename" * .keep
109+
popd
110+
fi
111+
112+
if [[ "$SKIP_OPENOCD" != 1 ]]; then
113+
echo "Packaging OpenOCD"
93114
# Package OpenOCD separately as well
94115

95-
version=($("./$builddir/openocd-install/usr/local/bin/openocd" --version 2>&1))
116+
version=($("./$builddir/openocd-install-$(uname -m)/usr/local/bin/openocd" --version 2>&1))
96117
version=${version[0]}
97118
version=${version[3]}
98119
version=$(echo $version | cut -d "-" -f 1)
99120

100121
echo "OpenOCD version $version"
101122

102-
filename="openocd-${version}-arm64-${suffix}.zip"
123+
filename="openocd-${version}-$(uname -m)-${suffix}.zip"
103124

104125
echo "Saving OpenOCD package to $filename"
105-
pushd "$builddir/openocd-install/usr/local/bin"
126+
pushd "$builddir/openocd-install-$(uname -m)/usr/local/bin"
106127
tar -a -cf "$topd/bin/$filename" * -C "../share/openocd" "scripts"
107128
popd
108129
fi
109130

110131
if [[ "$SKIP_RISCV" != 1 ]]; then
132+
echo "Packaging RISC-V Toolchain"
111133
# Package riscv toolchain separately as well
112-
version=$("./$builddir/riscv-install/bin/riscv32-unknown-elf-gcc" -dumpversion)
134+
version=$("./$builddir/riscv-install-$(uname -m)/bin/riscv32-unknown-elf-gcc" -dumpversion)
113135
version=$(echo $version | cut -d "." -f 1)
114136
echo "Risc-V Toolchain version $version"
115137

116-
filename="riscv-toolchain-${version}-arm64-${suffix}.zip"
117-
118-
echo "Saving RISC-V Toolchain package to $filename"
119-
pushd "$builddir/riscv-install/"
120-
tar -a -cf "$topd/bin/$filename" *
121-
popd
122-
123-
# Package x64-mac riscv toolchain separately as well
124-
version="14"
125-
echo "RISC-V Toolchain version $version"
126-
127-
filename="riscv-toolchain-${version}-x64-mac.zip"
138+
filename="riscv-toolchain-${version}-$(uname -m)-${suffix}.zip"
128139

129140
echo "Saving RISC-V Toolchain package to $filename"
130-
pushd "$builddir/riscv-install-x64-mac/"
141+
pushd "$builddir/riscv-install-$(uname -m)/"
131142
tar -a -cf "$topd/bin/$filename" *
132143
popd
133144
fi

packages/macos/make-universal.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
INSTALLDIR=$1
6+
BINDIR=$2
7+
BINNAME=$3
8+
9+
rm -rf $INSTALLDIR
10+
mkdir -p $INSTALLDIR
11+
12+
cp -r $INSTALLDIR-arm64/* $INSTALLDIR
13+
touch $INSTALLDIR/.keep
14+
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)
20+
fi
21+
done

packages/macos/openocd/build-openocd.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ cd openocd
1010
./configure --disable-werror
1111
make clean
1212
make
13-
INSTALLDIR="$PWD/../openocd-install/usr/local/bin"
14-
rm -rf "$PWD/../openocd-install"
15-
DESTDIR="$PWD/../openocd-install" make install
13+
INSTALLDIR="$PWD/../openocd-install-$(uname -m)/usr/local/bin"
14+
rm -rf "$PWD/../openocd-install-$(uname -m)"
15+
DESTDIR="$PWD/../openocd-install-$(uname -m)" make install
1616

1717
libusbpath=($(otool -L $INSTALLDIR/openocd | grep libusb))
1818
echo ${libusbpath[0]}

packages/macos/picotool/merge-picotool.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/macos/riscv/build-riscv-gcc-other.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/macos/riscv/build-riscv-gcc.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
set -euo pipefail
44

5-
# INSTALLDIR="riscv-install-$(uname -m)"
6-
INSTALLDIR="riscv-install"
5+
INSTALLDIR="riscv-install-$(uname -m)"
76
rm -rf $INSTALLDIR
87
mkdir -p $INSTALLDIR
98

@@ -16,9 +15,3 @@ cd riscv-gnu-toolchain
1615
./configure --prefix=$BUILDDIR/$INSTALLDIR --with-arch=rv32ima_zicsr_zifencei_zba_zbb_zbs_zbkb_zca_zcb --with-abi=ilp32 --with-multilib-generator="rv32ima_zicsr_zifencei_zba_zbb_zbs_zbkb_zca_zcb-ilp32--;rv32imac_zicsr_zifencei_zba_zbb_zbs_zbkb-ilp32--"
1716
# 4 threads, as 8 threads runs out of memory
1817
gmake -j4
19-
20-
# Make x64 and Windows toolchains, by copying multilib into existing toolchains
21-
cd ..
22-
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
23-
24-
$SCRIPT_DIR/build-riscv-gcc-other.sh "https://buildbot.embecosm.com/job/riscv32-gcc-macos-release/21/artifact/riscv32-embecosm-macos-gcc13.3.0.zip" "x64-mac"

0 commit comments

Comments
 (0)