From 641a92ee1900a0bd4f6764b9ae4db5f7c794f1f2 Mon Sep 17 00:00:00 2001 From: William Vinnicombe Date: Tue, 26 Nov 2024 12:33:48 +0000 Subject: [PATCH] Build MacOS Intel OpenOCD and Toolchain --- .github/workflows/build.yml | 34 ++++++++++++++ build_macos_intel.sh | 89 +++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100755 build_macos_intel.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c78927f..0f5b5fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -81,6 +81,40 @@ jobs: bin/openocd-*-mac.zip bin/riscv-toolchain-*.zip + build_macos_intel: + name: Build Intel MacOS + # runs-on: [self-hosted, macOS] + runs-on: 'macos-13' + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Homebrew + if: runner.environment == 'github-hosted' + id: set-up-homebrew + uses: Homebrew/actions/setup-homebrew@master + - name: Setup SSH Auth + if: runner.environment == 'github-hosted' + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.SSH_KEY }} + - name: Build + run: ./build_macos_intel.sh + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: tools-mac-x64 + path: | + bin/openocd-*-mac.zip + bin/riscv-toolchain-*.zip + - name: Add Release Asset + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + bin/openocd-*-mac.zip + bin/riscv-toolchain-*.zip + build_linux: name: Build Linux # strategy: diff --git a/build_macos_intel.sh b/build_macos_intel.sh new file mode 100755 index 0000000..a1cf9d3 --- /dev/null +++ b/build_macos_intel.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +set -euo pipefail + +# Defaults +SKIP_RISCV=${SKIP_RISCV-0} +SKIP_OPENOCD=${SKIP_OPENOCD-0} + +# Install prerequisites +/usr/local/bin/brew install jq libtool libusb automake hidapi --quiet +# RISC-V prerequisites +echo "Listing local" +ls /usr/local/bin +rm /usr/local/bin/2to3* +rm /usr/local/bin/idle3* +rm /usr/local/bin/pip* +rm /usr/local/bin/py* +/usr/local/bin/brew install python3 gawk gnu-sed gmp mpfr libmpc isl zlib expat texinfo flock libslirp --quiet + +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" + +while read -r repo +do + tree=$(echo "$repo" | jq -r .tree) + href=$(echo "$repo" | jq -r .href) + filename=$(basename -- "$href") + extension="${filename##*.}" + filename="${filename%.*}" + filename=${filename%"-rp2350"} + repodir="$builddir/${filename}" + + 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_OPENOCD" != 1 ]] && [[ $(uname -m) == 'arm64' ]]; then + if ! ../packages/macos/openocd/build-openocd.sh; then + echo "OpenOCD Build failed" + SKIP_OPENOCD=1 + fi +fi +if [[ "$SKIP_RISCV" != 1 ]]; then + # Takes ages to build + ../packages/macos/riscv/build-riscv-gcc.sh +fi + +topd=$PWD +if [[ "$SKIP_OPENOCD" != 1 ]]; then + # Package OpenOCD separately as well + + version=($("./$builddir/openocd-install/usr/local/bin/openocd" --version 2>&1)) + version=${version[0]} + version=${version[3]} + version=$(echo $version | cut -d "-" -f 1) + + echo "OpenOCD version $version" + + filename="openocd-${version}-x64-${suffix}.zip" + + echo "Saving OpenOCD package to $filename" + pushd "$builddir/openocd-install/usr/local/bin" + 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}-x64-${suffix}.zip" + + echo "Saving RISC-V Toolchain package to $filename" + pushd "$builddir/riscv-install/" + tar -a -cf "$topd/bin/$filename" * + popd +fi