Skip to content

Commit

Permalink
Build MacOS Intel OpenOCD and Toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
will-v-pi committed Nov 26, 2024
1 parent 178ced3 commit 641a92e
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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:
Expand Down
89 changes: 89 additions & 0 deletions build_macos_intel.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 641a92e

Please sign in to comment.