Skip to content

Commit

Permalink
Add MacOS toolchain build
Browse files Browse the repository at this point in the history
  • Loading branch information
will-v-pi committed Aug 29, 2024
1 parent d847edd commit bbf8740
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
- name: Build
run: ./build_macos.sh
run: SKIP_RISCV=0 ./build_macos.sh
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
Expand Down
29 changes: 23 additions & 6 deletions build_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ set -euo pipefail
# Install prerequisites
arch -x86_64 /usr/local/bin/brew install jq libtool libusb automake hidapi
arch -arm64 /opt/homebrew/bin/brew install jq libtool libusb automake hidapi
# Risc-V prerequisites
arch -x86_64 /usr/local/bin/brew install python3 gawk gnu-sed gmp mpfr libmpc isl zlib expat texinfo flock libslirp
arch -arm64 /opt/homebrew/bin/brew install python3 gawk gnu-sed gmp mpfr libmpc isl zlib expat texinfo flock libslirp

repos=$(cat config/repositories.json | jq -c '.repositories.[]')
export version=$(cat ./version.txt)
suffix="mac"
builddir="build"

# nproc alias
alias nproc="sysctl -n hw.logicalcpu"

mkdir -p $builddir
mkdir -p "bin"

Expand All @@ -24,19 +30,17 @@ do
filename=${filename%"-rp2350"}
repodir="$builddir/${filename}"

pi_only=$(echo "$repo" | jq -r .pi_only)
if [[ "$pi_only" == "true" ]]; then
echo "Skipping Pi only $repodir"
continue
fi

echo "${href} ${tree} ${filename} ${extension} ${repodir}"
rm -rf "${repodir}"
git clone -b "${tree}" --depth=1 -c advice.detachedHead=false "${href}" "${repodir}"
done < <(echo "$repos")


cd $builddir
if [[ "$SKIP_RISCV" != 1 ]]; then
# Takes ages to build
../packages/macos/riscv/build-riscv-gcc.sh
fi
if [[ $(uname -m) == 'arm64' ]]; then
../packages/macos/openocd/build-openocd.sh
fi
Expand Down Expand Up @@ -85,3 +89,16 @@ if [[ $(uname -m) == 'arm64' ]]; then
tar -a -cf "$topd/bin/$filename" * -C "../share/openocd" "scripts"
popd
fi

if [[ "$SKIP_RISCV" != 1 ]]; then
# Package riscv toolchain separately as well
version="14"
echo "Risc-V Toolchain version $version"

filename="riscv-toolchain-${version}-arm64-${suffix}.zip"

echo "Saving Risc-V Toolchain package to $filename"
pushd "$builddir/riscv-install/"
tar -a -cf "$topd/bin/$filename" *
popd
fi
18 changes: 18 additions & 0 deletions packages/macos/riscv/build-riscv-gcc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -euo pipefail

# INSTALLDIR="riscv-install-$(uname -m)"
INSTALLDIR="riscv-install"
rm -rf $INSTALLDIR
mkdir -p $INSTALLDIR

BUILDDIR=$(pwd)

GDB_TARGET_FLAGS_EXTRA="--with-gmp=/opt/homebrew --with-mpfr=/opt/homebrew"
export GDB_TARGET_FLAGS_EXTRA

cd riscv-gnu-toolchain
./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--" --with-gcc-src=$BUILDDIR/gcc
# 4 threads, as 8 threads runs out of memory
make -j4

0 comments on commit bbf8740

Please sign in to comment.