Skip to content

Commit fa2d797

Browse files
authored
Windows RISC-V toolchain build (#9)
* Clean up Windows builds and re-add RISC-V * Fix GCC version detection * Comment out SSH auth as not necessary anymore
1 parent 9c51150 commit fa2d797

File tree

9 files changed

+117
-87
lines changed

9 files changed

+117
-87
lines changed

.github/workflows/build.yml

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ permissions:
66
contents: write
77

88
env:
9-
SKIP_RISCV: 1
9+
SKIP_RISCV: 0
10+
SKIP_OPENOCD: 0
1011

1112
jobs:
1213
build_windows:
@@ -17,13 +18,18 @@ jobs:
1718
steps:
1819
- name: Checkout
1920
uses: actions/checkout@v4
20-
- name: Setup SSH Auth
21-
if: runner.environment == 'github-hosted'
22-
uses: webfactory/[email protected]
23-
with:
24-
ssh-private-key: ${{ secrets.SSH_KEY }}
21+
# - name: Setup SSH Auth
22+
# if: runner.environment == 'github-hosted'
23+
# uses: webfactory/[email protected]
24+
# with:
25+
# ssh-private-key: ${{ secrets.SSH_KEY }}
26+
- name: Setup MSYS2
27+
uses: msys2/setup-msys2@v2
2528
- name: Build
26-
run: ./build.ps1 ./config/x64-win.json -SkipSigning
29+
run: |
30+
subst P: .
31+
P:
32+
./build.ps1 ./config/x64-win.json -SkipSigning -MSYS2Path (msys2 -c 'cygpath -m /').TrimEnd('\/')
2733
- name: Upload Artifact
2834
uses: actions/upload-artifact@v4
2935
with:
@@ -32,6 +38,7 @@ jobs:
3238
bin/picotool-*-x64-win.zip
3339
bin/pico-sdk-tools-*-x64-win.zip
3440
bin/openocd-*-x64-win.zip
41+
bin/riscv-toolchain-*-x64-win.zip
3542
- name: Add Release Asset
3643
uses: softprops/action-gh-release@v2
3744
if: startsWith(github.ref, 'refs/tags/')
@@ -40,6 +47,7 @@ jobs:
4047
bin/picotool-*-x64-win.zip
4148
bin/pico-sdk-tools-*-x64-win.zip
4249
bin/openocd-*-x64-win.zip
50+
bin/riscv-toolchain-*-x64-win.zip
4351
4452
build_macos:
4553
name: Build MacOS
@@ -57,11 +65,11 @@ jobs:
5765
if: runner.environment == 'github-hosted'
5866
run: |
5967
NONINTERACTIVE=1 arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
60-
- name: Setup SSH Auth
61-
if: runner.environment == 'github-hosted'
62-
uses: webfactory/[email protected]
63-
with:
64-
ssh-private-key: ${{ secrets.SSH_KEY }}
68+
# - name: Setup SSH Auth
69+
# if: runner.environment == 'github-hosted'
70+
# uses: webfactory/[email protected]
71+
# with:
72+
# ssh-private-key: ${{ secrets.SSH_KEY }}
6573
- name: Build
6674
run: ./build_macos.sh
6775
- name: Upload Artifact
@@ -96,11 +104,11 @@ jobs:
96104
steps:
97105
- name: Checkout
98106
uses: actions/checkout@v4
99-
- name: Setup SSH Auth
100-
if: runner.environment == 'github-hosted'
101-
uses: webfactory/[email protected]
102-
with:
103-
ssh-private-key: ${{ secrets.SSH_KEY }}
107+
# - name: Setup SSH Auth
108+
# if: runner.environment == 'github-hosted'
109+
# uses: webfactory/[email protected]
110+
# with:
111+
# ssh-private-key: ${{ secrets.SSH_KEY }}
104112
- name: Build
105113
run: ./build_linux.sh
106114
- name: Upload Artifact

build.ps1

Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,10 @@ param (
2424
$SkipDownload,
2525

2626
[switch]
27-
$SkipSigning,
28-
29-
[ValidateSet('zlib', 'bzip2', 'lzma')]
30-
[string]
31-
$Compression = 'lzma',
32-
33-
[ValidateSet('system', 'user')]
34-
[string]
35-
$BuildType = 'system'
27+
$SkipSigning
3628
)
3729

3830
#Requires -Version 7.2
39-
40-
function crawl {
41-
param ([string]$url)
42-
43-
(Invoke-WebRequest $url -UseBasicParsing).Links |
44-
Where-Object {
45-
($_ | Get-Member href) -and
46-
[uri]::IsWellFormedUriString($_.href, [System.UriKind]::RelativeOrAbsolute)
47-
} |
48-
ForEach-Object {
49-
$href = [System.Net.WebUtility]::HtmlDecode($_.href)
50-
51-
try {
52-
(New-Object System.Uri([uri]$url, $href)).AbsoluteUri
53-
}
54-
catch {
55-
$href
56-
}
57-
}
58-
}
5931

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

8759
Write-Host "Building from $ConfigFile"
8860

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

9163
$tools = (Get-Content '.\config\tools.json' | ConvertFrom-Json).tools
9264
$repositories = (Get-Content '.\config\repositories.json' | ConvertFrom-Json).repositories
@@ -97,8 +69,8 @@ if ("" -ne $Version) {
9769
$version = (Get-Content "$PSScriptRoot\version.txt").Trim()
9870
}
9971
$config = Get-Content $ConfigFile | ConvertFrom-Json
100-
$bitness = $config.bitness
101-
$mingw_arch = $config.mingwArch
72+
$env:MSYSTEM = $config.msysEnv
73+
$msysEnv = $config.msysEnv.ToLowerInvariant()
10274
$downloads = $config.downloads
10375

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

133+
exec { git config --global core.autocrlf false }
134+
161135
$repositories | ForEach-Object {
162136
$repodir = Join-Path 'build' ([IO.Path]::GetFileNameWithoutExtension($_.href))
163137
$repodir = $repodir.TrimEnd("-rp2350")
@@ -223,8 +197,8 @@ function msys {
223197

224198
# Preserve the current working directory
225199
$env:CHERE_INVOKING = 'yes'
226-
# Start MINGW32/64 environment
227-
$env:MSYSTEM = "MINGW$bitness"
200+
# Use real symlinks
201+
$env:MSYS = "winsymlinks:nativestrict"
228202

229203
if (-not $SkipDownload) {
230204
# First run setup
@@ -234,33 +208,37 @@ if (-not $SkipDownload) {
234208
# Normal update
235209
msys 'pacman --noconfirm -Suu'
236210

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

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

246-
if (-not (Test-Path ".\build\picotool-install\mingw$bitness")) {
247-
msys "cd build && ../packages/windows/picotool/build-picotool.sh $bitness $mingw_arch $version"
220+
if (-not (Test-Path ".\build\openocd-install\$msysEnv") -and ($env:SKIP_OPENOCD -ne '1')) {
221+
msys "cd build && ../packages/windows/openocd/build-openocd.sh"
222+
}
223+
224+
if (-not (Test-Path ".\build\picotool-install\$msysEnv")) {
225+
msys "cd build && ../packages/windows/picotool/build-picotool.sh $version"
248226
}
249227

250228
if ($version.Substring(0, 1) -ge 2) {
251229
# Sign files before packaging up the installer
252-
sign "build\openocd-install\mingw$bitness\bin\openocd.exe",
253-
"build\pico-sdk-tools\mingw$bitness\pioasm\pioasm.exe",
254-
"build\picotool-install\mingw$bitness\picotool\picotool.exe"
230+
sign "build\openocd-install\$msysEnv\bin\openocd.exe",
231+
"build\pico-sdk-tools\$msysEnv\pioasm\pioasm.exe",
232+
"build\picotool-install\$msysEnv\picotool\picotool.exe"
255233
} else {
256234
$template = Get-Content ".\packages\windows\pico-sdk-tools\pico-sdk-tools-config-version.cmake" -Raw
257-
$ExecutionContext.InvokeCommand.ExpandString($template) | Set-Content ".\build\pico-sdk-tools\mingw$bitness\pico-sdk-tools-config-version.cmake"
235+
$ExecutionContext.InvokeCommand.ExpandString($template) | Set-Content ".\build\pico-sdk-tools\$msysEnv\pico-sdk-tools-config-version.cmake"
258236

259237
# Sign files before packaging up the installer
260-
sign "build\openocd-install\mingw$bitness\bin\openocd.exe",
261-
"build\pico-sdk-tools\mingw$bitness\elf2uf2.exe",
262-
"build\pico-sdk-tools\mingw$bitness\pioasm.exe",
263-
"build\picotool-install\mingw$bitness\picotool.exe"
238+
sign "build\openocd-install\$msysEnv\bin\openocd.exe",
239+
"build\pico-sdk-tools\$msysEnv\elf2uf2.exe",
240+
"build\pico-sdk-tools\$msysEnv\pioasm.exe",
241+
"build\picotool-install\$msysEnv\picotool.exe"
264242
}
265243

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

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

275253
# Package picotool separately as well
276254

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

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

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

287265
# Package OpenOCD separately as well
288266

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

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

302280
Write-Host "Saving OpenOCD package to $filename"
303-
exec { tar -a -cf "bin\$filename" -C "build\openocd-install\mingw$bitness\bin" * -C "..\share\openocd" "scripts" }
281+
exec { tar -a -cf "bin\$filename" -C "build\openocd-install\$msysEnv\bin" '*' -C "..\share\openocd" "scripts" }
282+
283+
# Package Risc-V separately as well
284+
285+
$version = ((. ".\build\riscv-install\$msysEnv\bin\riscv32-unknown-elf-gcc.exe" -dumpversion) -split '\.')[0]
286+
287+
$filename = 'riscv-toolchain-{0}-{1}.zip' -f
288+
$version,
289+
$suffix
290+
291+
Write-Host "Saving Risc-V toolchain package to $filename"
292+
exec { tar -a -cf "bin\$filename" -C "build\riscv-install\$msysEnv" '*' }

config/tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{
1111
"name": "MSYS2",
1212
"file": "msys2.exe",
13-
"href": "https://github.com/msys2/msys2-installer/releases/download/2023-01-27/msys2-base-x86_64-20230127.sfx.exe"
13+
"href": "https://github.com/msys2/msys2-installer/releases/download/2024-12-08/msys2-base-x86_64-20241208.sfx.exe"
1414
}
1515
]
1616
}

config/x64-win.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"bitness": 64,
3-
"mingwArch": "x86_64",
2+
"msysEnv": "MINGW64",
43
"downloads": [
54
{
65
"name": "CMake",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ cd ..
2222
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
2323

2424
$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"
25-
$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"

packages/windows/copy-deps.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Find all directories with exe files
6+
find . -name '*.exe' -printf '%h\n' | sort -u | while read i
7+
do
8+
echo "Copying DLLs to $i"
9+
pushd "$i" > /dev/null
10+
11+
# We need to match just the DLL names, if they are from the MSYS2 libraries.
12+
# (?<=...) is a positive lookbehind assertion, because we are looking for something like
13+
# "libusb-1.0.dll => /mingw64/.../libusb-1.0.dll"
14+
find . -maxdepth 1 -name '*.exe' -exec ldd {} ';' | (grep -Po "(?<==> )/${MSYSTEM,,}[^ ]+" || true) | sort -u | xargs -I{} cp -v {} .
15+
16+
popd > /dev/null
17+
done

packages/windows/openocd/build-openocd.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
set -euo pipefail
44

5-
BITNESS=$1
6-
ARCH=$2
5+
BUILDDIR=$(pwd)
6+
INSTALLDIR="openocd-install"
77

88
cd openocd
99
sed -i -e 's/uint /unsigned int /g' ./src/flash/nor/rp2040.c
1010
./bootstrap
1111
./configure --disable-werror
1212
make clean
1313
make -j$(nproc)
14-
DESTDIR="$PWD/../openocd-install" make install
15-
cp "/mingw$BITNESS/bin/libhidapi-0.dll" "$PWD/../openocd-install/mingw$BITNESS/bin"
16-
cp "/mingw$BITNESS/bin/libusb-1.0.dll" "$PWD/../openocd-install/mingw$BITNESS/bin"
14+
DESTDIR="$BUILDDIR/$INSTALLDIR" make install
15+
16+
cd "$BUILDDIR/$INSTALLDIR/${MSYSTEM,,}/bin"
17+
"$BUILDDIR/../packages/windows/copy-deps.sh"

packages/windows/picotool/build-picotool.sh

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

33
set -euo pipefail
44

5-
BITNESS=$1
6-
ARCH=$2
7-
sdkVersion=$3
5+
BUILDDIR=$(pwd)
6+
7+
sdkVersion=$1
88

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

2323
cd ../../../..
24-
INSTALLDIR="pico-sdk-tools/mingw$BITNESS"
24+
INSTALLDIR="pico-sdk-tools/${MSYSTEM,,}"
2525
mkdir -p $INSTALLDIR
2626
cmake --install pico-sdk/tools/pioasm/build/ --prefix $INSTALLDIR
2727
touch $INSTALLDIR/.keep
@@ -45,7 +45,7 @@ else
4545
cmake --build .
4646

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

6161
cd ../..
62-
INSTALLDIR="picotool-install/mingw$BITNESS"
62+
INSTALLDIR="picotool-install/${MSYSTEM,,}"
6363
mkdir -p $INSTALLDIR
6464
cmake --install picotool/build/ --prefix $INSTALLDIR
6565
touch $INSTALLDIR/.keep
66-
cp "/mingw$BITNESS/bin/libusb-1.0.dll" $INSTALLDIR/picotool
66+
cd $INSTALLDIR/picotool
67+
"$BUILDDIR/../packages/windows/copy-deps.sh"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
INSTALLDIR="riscv-install/${MSYSTEM,,}"
6+
rm -rf $INSTALLDIR
7+
mkdir -p $INSTALLDIR
8+
9+
BUILDDIR=$(pwd)
10+
11+
cd riscv-gnu-toolchain
12+
./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--"
13+
make -j$(nproc)
14+
15+
cd "$BUILDDIR/$INSTALLDIR"
16+
"$BUILDDIR/../packages/windows/copy-deps.sh"

0 commit comments

Comments
 (0)