Skip to content

Commit

Permalink
Windows RISC-V toolchain build (#9)
Browse files Browse the repository at this point in the history
* Clean up Windows builds and re-add RISC-V

* Fix GCC version detection

* Comment out SSH auth as not necessary anymore
  • Loading branch information
ndabas authored Dec 19, 2024
1 parent 9c51150 commit fa2d797
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 87 deletions.
42 changes: 25 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ permissions:
contents: write

env:
SKIP_RISCV: 1
SKIP_RISCV: 0
SKIP_OPENOCD: 0

jobs:
build_windows:
Expand All @@ -17,13 +18,18 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup SSH Auth
if: runner.environment == 'github-hosted'
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
# - name: Setup SSH Auth
# if: runner.environment == 'github-hosted'
# uses: webfactory/[email protected]
# with:
# ssh-private-key: ${{ secrets.SSH_KEY }}
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
- name: Build
run: ./build.ps1 ./config/x64-win.json -SkipSigning
run: |
subst P: .
P:
./build.ps1 ./config/x64-win.json -SkipSigning -MSYS2Path (msys2 -c 'cygpath -m /').TrimEnd('\/')
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
Expand All @@ -32,6 +38,7 @@ jobs:
bin/picotool-*-x64-win.zip
bin/pico-sdk-tools-*-x64-win.zip
bin/openocd-*-x64-win.zip
bin/riscv-toolchain-*-x64-win.zip
- name: Add Release Asset
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -40,6 +47,7 @@ jobs:
bin/picotool-*-x64-win.zip
bin/pico-sdk-tools-*-x64-win.zip
bin/openocd-*-x64-win.zip
bin/riscv-toolchain-*-x64-win.zip
build_macos:
name: Build MacOS
Expand All @@ -57,11 +65,11 @@ jobs:
if: runner.environment == 'github-hosted'
run: |
NONINTERACTIVE=1 arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- name: Setup SSH Auth
if: runner.environment == 'github-hosted'
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
# - 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.sh
- name: Upload Artifact
Expand Down Expand Up @@ -96,11 +104,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup SSH Auth
if: runner.environment == 'github-hosted'
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
# - name: Setup SSH Auth
# if: runner.environment == 'github-hosted'
# uses: webfactory/[email protected]
# with:
# ssh-private-key: ${{ secrets.SSH_KEY }}
- name: Build
run: ./build_linux.sh
- name: Upload Artifact
Expand Down
97 changes: 43 additions & 54 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,10 @@ param (
$SkipDownload,

[switch]
$SkipSigning,

[ValidateSet('zlib', 'bzip2', 'lzma')]
[string]
$Compression = 'lzma',

[ValidateSet('system', 'user')]
[string]
$BuildType = 'system'
$SkipSigning
)

#Requires -Version 7.2

function crawl {
param ([string]$url)

(Invoke-WebRequest $url -UseBasicParsing).Links |
Where-Object {
($_ | Get-Member href) -and
[uri]::IsWellFormedUriString($_.href, [System.UriKind]::RelativeOrAbsolute)
} |
ForEach-Object {
$href = [System.Net.WebUtility]::HtmlDecode($_.href)

try {
(New-Object System.Uri([uri]$url, $href)).AbsoluteUri
}
catch {
$href
}
}
}

function mkdirp {
param ([string] $dir, [switch] $clean)
Expand Down Expand Up @@ -86,7 +58,7 @@ $ProgressPreference = 'SilentlyContinue'

Write-Host "Building from $ConfigFile"

$suffix = [io.path]::GetFileNameWithoutExtension($ConfigFile) + ($BuildType -eq 'user' ? '-user' : '' )
$suffix = [io.path]::GetFileNameWithoutExtension($ConfigFile)

$tools = (Get-Content '.\config\tools.json' | ConvertFrom-Json).tools
$repositories = (Get-Content '.\config\repositories.json' | ConvertFrom-Json).repositories
Expand All @@ -97,8 +69,8 @@ if ("" -ne $Version) {
$version = (Get-Content "$PSScriptRoot\version.txt").Trim()
}
$config = Get-Content $ConfigFile | ConvertFrom-Json
$bitness = $config.bitness
$mingw_arch = $config.mingwArch
$env:MSYSTEM = $config.msysEnv
$msysEnv = $config.msysEnv.ToLowerInvariant()
$downloads = $config.downloads

mkdirp "build"
Expand Down Expand Up @@ -158,6 +130,8 @@ if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
$env:PATH = $env:PATH + ';' + (Resolve-Path .\build\git\cmd).Path
}

exec { git config --global core.autocrlf false }

$repositories | ForEach-Object {
$repodir = Join-Path 'build' ([IO.Path]::GetFileNameWithoutExtension($_.href))
$repodir = $repodir.TrimEnd("-rp2350")
Expand Down Expand Up @@ -223,8 +197,8 @@ function msys {

# Preserve the current working directory
$env:CHERE_INVOKING = 'yes'
# Start MINGW32/64 environment
$env:MSYSTEM = "MINGW$bitness"
# Use real symlinks
$env:MSYS = "winsymlinks:nativestrict"

if (-not $SkipDownload) {
# First run setup
Expand All @@ -234,33 +208,37 @@ if (-not $SkipDownload) {
# Normal update
msys 'pacman --noconfirm -Suu'

msys "pacman -S --noconfirm --needed autoconf automake git libtool make pactoys pkg-config wget"
msys "pacman -S --noconfirm --needed autoconf automake base-devel expat git libtool pactoys patchutils pkg-config"
# pacboy adds MINGW_PACKAGE_PREFIX to package names suffixed with :p
msys "pacboy -S --noconfirm --needed cmake:p ninja:p toolchain:p libusb:p hidapi:p"
msys "pacboy -S --noconfirm --needed cmake:p ninja:p toolchain:p libusb:p hidapi:p libslirp:p"
}

if (-not (Test-Path ".\build\openocd-install\mingw$bitness")) {
msys "cd build && ../packages/windows/openocd/build-openocd.sh $bitness $mingw_arch"
if (-not (Test-Path ".\build\riscv-install\$msysEnv") -and ($env:SKIP_RISCV -ne '1')) {
msys "cd build && ../packages/windows/riscv/build-riscv-gcc.sh"
}

if (-not (Test-Path ".\build\picotool-install\mingw$bitness")) {
msys "cd build && ../packages/windows/picotool/build-picotool.sh $bitness $mingw_arch $version"
if (-not (Test-Path ".\build\openocd-install\$msysEnv") -and ($env:SKIP_OPENOCD -ne '1')) {
msys "cd build && ../packages/windows/openocd/build-openocd.sh"
}

if (-not (Test-Path ".\build\picotool-install\$msysEnv")) {
msys "cd build && ../packages/windows/picotool/build-picotool.sh $version"
}

if ($version.Substring(0, 1) -ge 2) {
# Sign files before packaging up the installer
sign "build\openocd-install\mingw$bitness\bin\openocd.exe",
"build\pico-sdk-tools\mingw$bitness\pioasm\pioasm.exe",
"build\picotool-install\mingw$bitness\picotool\picotool.exe"
sign "build\openocd-install\$msysEnv\bin\openocd.exe",
"build\pico-sdk-tools\$msysEnv\pioasm\pioasm.exe",
"build\picotool-install\$msysEnv\picotool\picotool.exe"
} else {
$template = Get-Content ".\packages\windows\pico-sdk-tools\pico-sdk-tools-config-version.cmake" -Raw
$ExecutionContext.InvokeCommand.ExpandString($template) | Set-Content ".\build\pico-sdk-tools\mingw$bitness\pico-sdk-tools-config-version.cmake"
$ExecutionContext.InvokeCommand.ExpandString($template) | Set-Content ".\build\pico-sdk-tools\$msysEnv\pico-sdk-tools-config-version.cmake"

# Sign files before packaging up the installer
sign "build\openocd-install\mingw$bitness\bin\openocd.exe",
"build\pico-sdk-tools\mingw$bitness\elf2uf2.exe",
"build\pico-sdk-tools\mingw$bitness\pioasm.exe",
"build\picotool-install\mingw$bitness\picotool.exe"
sign "build\openocd-install\$msysEnv\bin\openocd.exe",
"build\pico-sdk-tools\$msysEnv\elf2uf2.exe",
"build\pico-sdk-tools\$msysEnv\pioasm.exe",
"build\picotool-install\$msysEnv\picotool.exe"
}

# Package pico-sdk-tools separately as well
Expand All @@ -270,23 +248,23 @@ $filename = 'pico-sdk-tools-{0}-{1}.zip' -f
$suffix

Write-Host "Saving pico-sdk-tools package to $filename"
exec { tar -a -cf "bin\$filename" -C "build\pico-sdk-tools\mingw$bitness\" * }
exec { tar -a -cf "bin\$filename" -C "build\pico-sdk-tools\$msysEnv" '*' }

# Package picotool separately as well

$version = (cmd /c ".\build\picotool-install\mingw$bitness\picotool\picotool.exe" version -s '2>&1')
$version = (cmd /c ".\build\picotool-install\$msysEnv\picotool\picotool.exe" version -s '2>&1')
Write-Host "Picotool version $version"

$filename = 'picotool-{0}-{1}.zip' -f
$version,
$suffix

Write-Host "Saving picotool package to $filename"
exec { tar -a -cf "bin\$filename" -C "build\picotool-install\mingw$bitness\" * }
exec { tar -a -cf "bin\$filename" -C "build\picotool-install\$msysEnv" '*' }

# Package OpenOCD separately as well

$version = (cmd /c ".\build\openocd-install\mingw$bitness\bin\openocd.exe" --version '2>&1')[0]
$version = (cmd /c ".\build\openocd-install\$msysEnv\bin\openocd.exe" --version '2>&1')[0]
if (-not ($version -match 'Open On-Chip Debugger (?<version>[a-zA-Z0-9\.\-+]+) \((?<timestamp>[0-9\-:]+)\)')) {
Write-Error 'Could not determine openocd version'
}
Expand All @@ -297,7 +275,18 @@ $filename = 'openocd-{0}-{1}.zip' -f

# Removing files with special char in their names
# they cause issues with some decompression libraries
exec { Remove-Item "build\openocd-install\mingw$bitness\share\openocd\scripts\target\1986*.cfg" }
Remove-Item "build\openocd-install\$msysEnv\share\openocd\scripts\target\1986*.cfg"

Write-Host "Saving OpenOCD package to $filename"
exec { tar -a -cf "bin\$filename" -C "build\openocd-install\mingw$bitness\bin" * -C "..\share\openocd" "scripts" }
exec { tar -a -cf "bin\$filename" -C "build\openocd-install\$msysEnv\bin" '*' -C "..\share\openocd" "scripts" }

# Package Risc-V separately as well

$version = ((. ".\build\riscv-install\$msysEnv\bin\riscv32-unknown-elf-gcc.exe" -dumpversion) -split '\.')[0]

$filename = 'riscv-toolchain-{0}-{1}.zip' -f
$version,
$suffix

Write-Host "Saving Risc-V toolchain package to $filename"
exec { tar -a -cf "bin\$filename" -C "build\riscv-install\$msysEnv" '*' }
2 changes: 1 addition & 1 deletion config/tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"name": "MSYS2",
"file": "msys2.exe",
"href": "https://github.com/msys2/msys2-installer/releases/download/2023-01-27/msys2-base-x86_64-20230127.sfx.exe"
"href": "https://github.com/msys2/msys2-installer/releases/download/2024-12-08/msys2-base-x86_64-20241208.sfx.exe"
}
]
}
3 changes: 1 addition & 2 deletions config/x64-win.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"bitness": 64,
"mingwArch": "x86_64",
"msysEnv": "MINGW64",
"downloads": [
{
"name": "CMake",
Expand Down
1 change: 0 additions & 1 deletion packages/macos/riscv/build-riscv-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ cd ..
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

$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"
$SCRIPT_DIR/build-riscv-gcc-other.sh "https://buildbot.embecosm.com/job/riscv32-gcc-win64-release/24/artifact/riscv32-embecosm-win64-gcc13.2.0.zip" "x64-win"
17 changes: 17 additions & 0 deletions packages/windows/copy-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -euo pipefail

# Find all directories with exe files
find . -name '*.exe' -printf '%h\n' | sort -u | while read i
do
echo "Copying DLLs to $i"
pushd "$i" > /dev/null

# We need to match just the DLL names, if they are from the MSYS2 libraries.
# (?<=...) is a positive lookbehind assertion, because we are looking for something like
# "libusb-1.0.dll => /mingw64/.../libusb-1.0.dll"
find . -maxdepth 1 -name '*.exe' -exec ldd {} ';' | (grep -Po "(?<==> )/${MSYSTEM,,}[^ ]+" || true) | sort -u | xargs -I{} cp -v {} .

popd > /dev/null
done
11 changes: 6 additions & 5 deletions packages/windows/openocd/build-openocd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

set -euo pipefail

BITNESS=$1
ARCH=$2
BUILDDIR=$(pwd)
INSTALLDIR="openocd-install"

cd openocd
sed -i -e 's/uint /unsigned int /g' ./src/flash/nor/rp2040.c
./bootstrap
./configure --disable-werror
make clean
make -j$(nproc)
DESTDIR="$PWD/../openocd-install" make install
cp "/mingw$BITNESS/bin/libhidapi-0.dll" "$PWD/../openocd-install/mingw$BITNESS/bin"
cp "/mingw$BITNESS/bin/libusb-1.0.dll" "$PWD/../openocd-install/mingw$BITNESS/bin"
DESTDIR="$BUILDDIR/$INSTALLDIR" make install

cd "$BUILDDIR/$INSTALLDIR/${MSYSTEM,,}/bin"
"$BUILDDIR/../packages/windows/copy-deps.sh"
15 changes: 8 additions & 7 deletions packages/windows/picotool/build-picotool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

set -euo pipefail

BITNESS=$1
ARCH=$2
sdkVersion=$3
BUILDDIR=$(pwd)

sdkVersion=$1

export PICO_SDK_PATH="$PWD/pico-sdk"
export LDFLAGS="-static -static-libgcc -static-libstdc++"
Expand All @@ -21,7 +21,7 @@ if [ ${sdkVersion:0:1} -ge 2 ]; then
cmake --build .

cd ../../../..
INSTALLDIR="pico-sdk-tools/mingw$BITNESS"
INSTALLDIR="pico-sdk-tools/${MSYSTEM,,}"
mkdir -p $INSTALLDIR
cmake --install pico-sdk/tools/pioasm/build/ --prefix $INSTALLDIR
touch $INSTALLDIR/.keep
Expand All @@ -45,7 +45,7 @@ else
cmake --build .

cd ../../../..
INSTALLDIR="pico-sdk-tools/mingw$BITNESS"
INSTALLDIR="pico-sdk-tools/${MSYSTEM,,}"
mkdir -p $INSTALLDIR
cp pico-sdk-$sdkVersion/tools/elf2uf2/build/elf2uf2.exe $INSTALLDIR
cp pico-sdk-$sdkVersion/tools/pioasm/build/pioasm.exe $INSTALLDIR
Expand All @@ -59,8 +59,9 @@ cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release -DPICOTOOL_FLAT_INSTALL=1
cmake --build .

cd ../..
INSTALLDIR="picotool-install/mingw$BITNESS"
INSTALLDIR="picotool-install/${MSYSTEM,,}"
mkdir -p $INSTALLDIR
cmake --install picotool/build/ --prefix $INSTALLDIR
touch $INSTALLDIR/.keep
cp "/mingw$BITNESS/bin/libusb-1.0.dll" $INSTALLDIR/picotool
cd $INSTALLDIR/picotool
"$BUILDDIR/../packages/windows/copy-deps.sh"
16 changes: 16 additions & 0 deletions packages/windows/riscv/build-riscv-gcc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -euo pipefail

INSTALLDIR="riscv-install/${MSYSTEM,,}"
rm -rf $INSTALLDIR
mkdir -p $INSTALLDIR

BUILDDIR=$(pwd)

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--"
make -j$(nproc)

cd "$BUILDDIR/$INSTALLDIR"
"$BUILDDIR/../packages/windows/copy-deps.sh"

0 comments on commit fa2d797

Please sign in to comment.