diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b435d4..f1fdf76 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,8 @@ permissions: contents: write env: - SKIP_RISCV: 1 + SKIP_RISCV: 0 + SKIP_OPENOCD: 0 jobs: build_windows: @@ -17,13 +18,18 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup SSH Auth - if: runner.environment == 'github-hosted' - uses: webfactory/ssh-agent@v0.7.0 - with: - ssh-private-key: ${{ secrets.SSH_KEY }} + # - name: Setup SSH Auth + # if: runner.environment == 'github-hosted' + # uses: webfactory/ssh-agent@v0.7.0 + # 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: @@ -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/') @@ -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 @@ -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/ssh-agent@v0.9.0 - with: - ssh-private-key: ${{ secrets.SSH_KEY }} + # - 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.sh - name: Upload Artifact @@ -96,11 +104,11 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup SSH Auth - if: runner.environment == 'github-hosted' - uses: webfactory/ssh-agent@v0.9.0 - with: - ssh-private-key: ${{ secrets.SSH_KEY }} + # - 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_linux.sh - name: Upload Artifact diff --git a/build.ps1 b/build.ps1 index 49dbddc..652c3b1 100644 --- a/build.ps1 +++ b/build.ps1 @@ -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) @@ -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 @@ -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" @@ -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") @@ -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 @@ -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 @@ -270,11 +248,11 @@ $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 @@ -282,11 +260,11 @@ $filename = 'picotool-{0}-{1}.zip' -f $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 (?[a-zA-Z0-9\.\-+]+) \((?[0-9\-:]+)\)')) { Write-Error 'Could not determine openocd version' } @@ -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" '*' } diff --git a/config/tools.json b/config/tools.json index 2a66dea..c8ad37c 100644 --- a/config/tools.json +++ b/config/tools.json @@ -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" } ] } diff --git a/config/x64-win.json b/config/x64-win.json index 830ab59..0b7cfc7 100644 --- a/config/x64-win.json +++ b/config/x64-win.json @@ -1,6 +1,5 @@ { - "bitness": 64, - "mingwArch": "x86_64", + "msysEnv": "MINGW64", "downloads": [ { "name": "CMake", diff --git a/packages/macos/riscv/build-riscv-gcc.sh b/packages/macos/riscv/build-riscv-gcc.sh index ca4f9a0..ad10c91 100755 --- a/packages/macos/riscv/build-riscv-gcc.sh +++ b/packages/macos/riscv/build-riscv-gcc.sh @@ -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" diff --git a/packages/windows/copy-deps.sh b/packages/windows/copy-deps.sh new file mode 100755 index 0000000..b44f498 --- /dev/null +++ b/packages/windows/copy-deps.sh @@ -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 diff --git a/packages/windows/openocd/build-openocd.sh b/packages/windows/openocd/build-openocd.sh index e5a5018..af8c96c 100755 --- a/packages/windows/openocd/build-openocd.sh +++ b/packages/windows/openocd/build-openocd.sh @@ -2,8 +2,8 @@ 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 @@ -11,6 +11,7 @@ sed -i -e 's/uint /unsigned int /g' ./src/flash/nor/rp2040.c ./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" diff --git a/packages/windows/picotool/build-picotool.sh b/packages/windows/picotool/build-picotool.sh index a0ec667..511ba99 100755 --- a/packages/windows/picotool/build-picotool.sh +++ b/packages/windows/picotool/build-picotool.sh @@ -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++" @@ -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 @@ -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 @@ -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" diff --git a/packages/windows/riscv/build-riscv-gcc.sh b/packages/windows/riscv/build-riscv-gcc.sh new file mode 100755 index 0000000..cecbdfc --- /dev/null +++ b/packages/windows/riscv/build-riscv-gcc.sh @@ -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"