Skip to content

Commit

Permalink
Merge pull request #18 from ckormanyos/msys2_depfree_build
Browse files Browse the repository at this point in the history
Fix #17 via msys2 dependency-free avr-gcc build
  • Loading branch information
ckormanyos authored Dec 29, 2023
2 parents 7876a1c + 1314a94 commit d6b756c
Show file tree
Hide file tree
Showing 6 changed files with 356 additions and 24 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/avr-gcc-build-msys2-gcc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
##############################################################################
# Copyright Christopher Kormanyos 2023.
# Distributed under The Unlicense.

name: avr-gcc-build-msys2-gcc
on:
push:
branches:
- '**'
pull_request:
jobs:
avr-gcc-build-msys2:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
strategy:
fail-fast: false
matrix:
gccversion: [ 12.3.0 ]
steps:
- uses: actions/checkout@v3
- name: unpack-repo-nuwen-mingw-subset
shell: cmd
run: |
start /b /wait ./mingw.exe -y -gm2 -InstallPath="D:\\a\\avr-gcc-build\\avr-gcc-build\\mingw"
- uses: msys2/setup-msys2@v2
with:
msystem: mingw64
update: true
install: autoconf automake bzip2 cmake git make ninja patch python texinfo wget
- name: avr-gcc-100-12.3.0_x86_64-w64-mingw32
shell: msys2 {0}
run: |
echo 'avr-gcc-100-12.3.0_x86_64-w64-mingw32.sh'
./avr-gcc-100-12.3.0_x86_64-w64-mingw32.sh
- name: avr-gcc-partially-verify-result
shell: msys2 {0}
run: |
echo 'avr-gcc partial verify result'
ls -la /d/a/avr-gcc-build/avr-gcc-build/local/gcc-12.3.0-avr/bin
ls -la /d/a/avr-gcc-build/avr-gcc-build/local/gcc-12.3.0-avr/bin/avr-gcc.exe
ls -la /d/a/avr-gcc-build/avr-gcc-build/local/gcc-12.3.0-avr/bin/avr-g++.exe
- uses: actions/upload-artifact@v4
with:
name: gcc-12.3.0-avr
path: d:/a/avr-gcc-build/avr-gcc-build/local/gcc-12.3.0-avr
7 changes: 6 additions & 1 deletion .github/workflows/avr-gcc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ jobs:
cd ${{ runner.workspace }}/avr-gcc-build/real-time-cpp/ref_app
PATH=${{ runner.workspace }}/avr-gcc-build/local/gcc-${{ matrix.branchname }}-avr/bin:"$PATH"
./target/build/build.sh avr rebuild
ls -la bin/ref_app.elf bin/ref_app.hex bin/ref_app.map bin/ref_app.s19 bin/ref_app_cppfilt.txt bin/ref_app_nm.txt bin/ref_app_readelf.txt bin/ref_app_size.txt
ls -la bin/ref_app.elf bin/ref_app.hex
ls -la bin/ref_app.map bin/ref_app.s19
ls -la bin/ref_app_cppfilt.txt
ls -la bin/ref_app_nm.txt
ls -la bin/ref_app_readelf.txt
ls -la bin/ref_app_size.txt
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ directly from the Workflow-Run(s) on GHA.

Design goals:
- Use shell and YAML scripts to build modern `avr-gcc` on-the-fly.
- Build `avr-gcc` from up-to-date branches such as `trunk` and `releases/gcc-13` found in [`gcc-mirror/gcc`](https://github.com/gcc-mirror/gcc).
- Build `avr-gcc` from up-to-date releases such as 12.3.0 or modern branches like `trunk` and `releases/gcc-13` found in [`gcc-mirror/gcc`](https://github.com/gcc-mirror/gcc).
- Provide a non-trivial test of the newly-built toolchain(s) based on a real-world project.
- Support cyclic monthly build of modern, evolving GCC branch(es) and trunk.
- Publish the build artifacts directly from the Workflow-Run(s) on GHA.
- Provide a [shell script recipe](./avr-gcc-100-12.3.0_x86_64-w64-mingw32.sh) for local build of `avr-gcc` on `x86_64-w64-mingw32` host. This does not run on GHA at the moment, but can be executed locally.

## Workflow-Run

Expand All @@ -41,10 +40,9 @@ is used for archiving build artifacts.

## Additional Details

This project is distributed under [The Unlicense](./UNLICENSE).

Limitations:
- At the moment, the Workflow-Run builds `avr-gcc` for the _host_ `x86_64-linux-gnu` only. Cross-host compilation for `x86_64-w64-mingw32` does not work.
- A [shell script recipe](./avr-gcc-100-12.3.0_x86_64-w64-mingw32.sh) for local build of `avr-gcc` on `x86_64-w64-mingw32` host. It does not run on GHA at the moment, but can be executed locally.
Details:
- This project is distributed under [The Unlicense](./UNLICENSE).
- The Workflow-Run [avr-gcc-build.yml](./.github/workflows/avr-gcc-build.yml) and associated shell scripts (`avr-gcc-010*.sh`, `avr-gcc-020*.sh`, and `avr-gcc-030*.sh`) build `avr-gcc` for the _host_ `x86_64-linux-gnu`. These run on GHA using `ubuntu-latest` runners.
- The Workflow-Run [avr-gcc-build-msys2-gcc.yml](./.github/workflows/avr-gcc-build-msys2-gcc.yml) and shell script [avr-gcc-100-12.3.0_x86_64-w64-mingw32.sh](./avr-gcc-100-12.3.0_x86_64-w64-mingw32.sh) build `avr-gcc` for the _host_ `x86_64-w64-mingw32`. These run on GHA within `msys2` using `windows-latest` runners.

This work has been inspired by a similar project: [`ZakKemble/avr-gcc-build`](https://github.com/ZakKemble/avr-gcc-build).
203 changes: 203 additions & 0 deletions _reference_avr-gcc-100-12.3.0_x86_64-w64-mingw32.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
#!/usr/bin/env bash
#
# Copyright Christopher Kormanyos 2023.
# Distributed under The Unlicense.
#

SCRIPT_PATH=$(readlink -f "$BASH_SOURCE")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")


# echo 'install necessary packages and build tools'
# pacman -S --needed --noconfirm wget git make cmake ninja patch texinfo bzip2 xz autoconf automake python

# Get standalone msys2 from nuwen (contains standalone gcc-x86_64-w64-mingw32).
# The page describing this is: https://nuwen.net/mingw.html
# The exact download link is: https://nuwen.net/files/mingw/mingw-18.0.exe

# For detailed background information, see also the detailed instructions
# at GitHub from Stephan T. Lavavej's repositiony.
# These can be found here: https://github.com/StephanTLavavej/mingw-distro


echo 'clean gcc_build directory'
rm -rf gcc_build | true


echo 'make and enter gcc_build directory'
mkdir -p $SCRIPT_DIR/gcc_build
echo


echo 'copy gcc 12.3.0 patch file'
cd $SCRIPT_DIR/gcc_build
cp ../avr-gcc-100-12.3.0_x86_64-w64-mingw32.patch .
echo


echo 'append standalone gcc-x86_64-w64-mingw32 path'
export X_DISTRO_ROOT=/c/mingw
export X_DISTRO_BIN=$X_DISTRO_ROOT/bin
export X_DISTRO_INC=$X_DISTRO_ROOT/include
export X_DISTRO_LIB=$X_DISTRO_ROOT/lib
export PATH=$PATH:$X_DISTRO_BIN
export C_INCLUDE_PATH=$X_DISTRO_INC
export CPLUS_INCLUDE_PATH=$X_DISTRO_INC
echo


echo 'query version pre-installed standalone gcc-x86_64-w64-mingw32'
g++ -v
echo


cd $SCRIPT_DIR/gcc_build
echo 'get tar-balls'
wget --no-check-certificate https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz
wget --no-check-certificate https://ftp.gnu.org/gnu/libiconv/libiconv-1.17.tar.gz
wget --no-check-certificate https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz
wget --no-check-certificate https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz
wget --no-check-certificate https://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz
wget --no-check-certificate https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.15.tar.bz2
wget --no-check-certificate https://gcc.gnu.org/pub/gcc/infrastructure/cloog-0.18.1.tar.gz
wget --no-check-certificate https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.xz
wget --no-check-certificate https://ftp.gnu.org/gnu/gcc/gcc-12.3.0/gcc-12.3.0.tar.xz
echo


cd $SCRIPT_DIR/gcc_build
echo 'build zstd'
tar -xf zstd-1.5.5.tar.gz
mkdir objdir-zstd-1.5.5
cd objdir-zstd-1.5.5
cmake "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_C_FLAGS=-s -O3" "-DCMAKE_INSTALL_PREFIX=/usr/local/zstd-1.5.5" "-DZSTD_BUILD_SHARED=OFF" -G Ninja $SCRIPT_DIR/gcc_build/zstd-1.5.5/build/cmake
ninja
ninja install
echo


cd $SCRIPT_DIR/gcc_build
echo 'build libiconv'
tar -xf libiconv-1.17.tar.gz
mkdir objdir-libiconv-1.17
cd objdir-libiconv-1.17
../libiconv-1.17/configure --prefix=/usr/local/libiconv-1.17 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-static --disable-shared
make --jobs=6
make install
echo


cd $SCRIPT_DIR/gcc_build
echo 'build gmp'
tar -xf gmp-6.3.0.tar.xz
mkdir objdir-gmp-6.3.0
cd objdir-gmp-6.3.0
../gmp-6.3.0/configure --prefix=/usr/local/gmp-6.3.0 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-static --disable-shared
make --jobs=6
make install
echo


cd $SCRIPT_DIR/gcc_build
echo 'build mpfr'
tar -xf mpfr-4.2.1.tar.xz
mkdir objdir-mpfr-4.2.1
cd objdir-mpfr-4.2.1
../mpfr-4.2.1/configure --prefix=/usr/local/mpfr-4.2.1 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-static --disable-shared --with-gmp=/usr/local/gmp-6.3.0
make --jobs=6
make install
echo


cd $SCRIPT_DIR/gcc_build
echo 'build mpc'
tar -xf mpc-1.3.1.tar.gz
mkdir objdir-mpc-1.3.1
cd objdir-mpc-1.3.1
../mpc-1.3.1/configure --prefix=/usr/local/mpc-1.3.1 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-static --disable-shared --with-gmp=/usr/local/gmp-6.3.0 --with-mpfr=/usr/local/mpfr-4.2.1
make --jobs=6
make install
echo


cd $SCRIPT_DIR/gcc_build
echo 'build isl'
tar -xjf isl-0.15.tar.bz2
mkdir objdir-isl-0.15
cd objdir-isl-0.15
../isl-0.15/configure --prefix=/usr/local/isl-0.15 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-static --disable-shared --with-gmp-prefix=/usr/local/gmp-6.3.0
make --jobs=6
make install
echo


cd $SCRIPT_DIR/gcc_build
echo 'build cloog'
tar -xf cloog-0.18.1.tar.gz
mkdir objdir-cloog-0.18.1
cd objdir-cloog-0.18.1
../cloog-0.18.1/configure --prefix=/usr/local/cloog-0.18.1 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --enable-static --disable-shared --with-isl=/usr/local/isl-0.15 --with-gmp=/usr/local/gmp-6.3.0
make --jobs=6
make install
echo


cd $SCRIPT_DIR/gcc_build
echo 'build binutils'
tar -xf binutils-2.41.tar.xz
mkdir objdir-binutils-2.41-avr-gcc-12.3.0
cd objdir-binutils-2.41-avr-gcc-12.3.0
../binutils-2.41/configure --prefix=/usr/local/gcc-12.3.0-avr --target=avr --enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --with-pkgversion='Built by ckormanyos/real-time-cpp' --enable-static --disable-shared --disable-libada --disable-libssp --disable-nls --enable-mingw-wildcard --with-gnu-as --with-dwarf2 --with-isl=/usr/local/isl-0.15 --with-cloog=/usr/local/cloog-0.18.1 --with-gmp=/usr/local/gmp-6.3.0 --with-mpfr=/usr/local/mpfr-4.2.1 --with-mpc=/usr/local/mpc-1.3.1 --with-libiconv-prefix=/usr/local/libiconv-1.17 --with-zstd=/usr/local/zstd-1.5.5/lib --disable-werror
make --jobs=6
make install
echo


#
# Notes on patch of GCC-12.3.0
#

# How do you make the patch?
# diff -ru gcc-12.3.0/ gcc-12.3.0_new/ > avr-gcc-100-12.3.0_x86_64-w64-mingw32.patch

# How do you apply the patch?
# patch -p0 < avr-gcc-100-12.3.0_x86_64-w64-mingw32.patch


cd $SCRIPT_DIR/gcc_build
echo 'build gcc'
tar -xf gcc-12.3.0.tar.xz
patch -p0 < avr-gcc-100-12.3.0_x86_64-w64-mingw32.patch
mkdir objdir-gcc-12.3.0-avr
cd objdir-gcc-12.3.0-avr
../gcc-12.3.0/configure --prefix=/usr/local/gcc-12.3.0-avr --target=avr --enable-languages=c,c++ --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --with-pkgversion='Built by ckormanyos/real-time-cpp' --enable-static --disable-shared --disable-libada --disable-libssp --disable-nls --enable-mingw-wildcard --with-gnu-as --with-dwarf2 --with-isl=/usr/local/isl-0.15 --with-cloog=/usr/local/cloog-0.18.1 --with-gmp=/usr/local/gmp-6.3.0 --with-mpfr=/usr/local/mpfr-4.2.1 --with-mpc=/usr/local/mpc-1.3.1 --with-libiconv-prefix=/usr/local/libiconv-1.17 --with-zstd=/usr/local/zstd-1.5.5/lib
make --jobs=6
make install
echo


cd $SCRIPT_DIR/gcc_build
echo 'clone and bootstrap avr-libc'
git clone -b main --depth 1 https://github.com/avrdudes/avr-libc.git ./avr-libc
rm -f avr-libc/tests/simulate/time/aux.c
cd avr-libc
./bootstrap
echo


cd $SCRIPT_DIR/gcc_build
echo 'add avr-gcc path'
PATH=/usr/local/gcc-12.3.0-avr/bin:"$PATH"
export PATH
CC=""
export CC
echo


cd $SCRIPT_DIR/gcc_build
echo 'build avr-libc'
cd objdir-gcc-12.3.0-avr
../avr-libc/configure --prefix=/usr/local/gcc-12.3.0-avr --build=x86_64-w64-mingw32 --host=avr --enable-static --disable-shared
make --jobs=6
make install
echo
Loading

0 comments on commit d6b756c

Please sign in to comment.