Skip to content

Commit

Permalink
Merge pull request #8 from tttapa/gcc-14
Browse files Browse the repository at this point in the history
GCC 14.1 support
  • Loading branch information
tttapa committed May 19, 2024
2 parents 66278d4 + 1cfabf2 commit 8020eff
Show file tree
Hide file tree
Showing 22 changed files with 324 additions and 3,649 deletions.
109 changes: 54 additions & 55 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
name: Docker

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Build and publish Docker

on:
release:
Expand All @@ -18,31 +13,36 @@ env:
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
triple: ['aarch64-rpi3-linux-gnu', 'armv6-rpi-linux-gnueabihf', 'armv8-rpi3-linux-gnueabihf', 'arm-pico-eabi']

permissions:
contents: write
packages: write

strategy:
matrix:
triple:
- 'aarch64-rpi3-linux-gnu'
- 'armv6-rpi-linux-gnueabihf'
- 'armv8-rpi3-linux-gnueabihf'
- 'arm-pico-eabi'
gcc-version:
- '12'
- '13'
- '14'
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand All @@ -52,42 +52,39 @@ jobs:
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
prefix=${{ matrix.triple }}-
prefix=${{ matrix.triple }}-gcc${{ matrix.gcc-version }}-
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=${{ matrix.triple }},prefix=
type=ref,event=branch,prefix=${{ matrix.triple }}-,enable=${{ matrix.gcc-version == '14' }}
type=ref,event=tag,prefix=${{ matrix.triple }}-,enable=${{ matrix.gcc-version == '14' }}
type=ref,event=pr,prefix=${{ matrix.triple }}-,enable=${{ matrix.gcc-version == '14' }}
type=raw,value=${{ matrix.triple }},prefix=,enable=${{ matrix.gcc-version == '14' }}
type=raw,value=${{ matrix.triple }}-gcc${{ matrix.gcc-version }},prefix=
# Build and load Docker image
# Build and load Docker image with Buildx
# https://github.com/docker/build-push-action
- name: Build Docker image
if: matrix.triple != 'arm-pico-eabi'
- name: Build and load Docker image
id: build
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0
with:
context: .
target: gcc-build
build-args: |
"HOST_TRIPLE=${{ matrix.triple }}"
load: true
tags: ${{ env.TEMPORARY_TAG }}

# Build and load Docker image
# https://github.com/docker/build-push-action
- name: Build Docker image
if: matrix.triple == 'arm-pico-eabi'
id: build-pico
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: pico
HOST_TRIPLE=${{ matrix.triple }}
GCC_VERSION=${{ matrix.gcc-version }}
load: true
tags: ${{ env.TEMPORARY_TAG }}
cache-from: type=gha,scope=${{ matrix.triple }}-gcc${{ matrix.gcc-version }}
cache-to: type=gha,mode=max,scope=${{ matrix.triple }}-gcc${{ matrix.gcc-version }}

# Archive the toolchain in the Docker container and copy it to the build environment
- name: Export toolchain
run: |
container=$(docker run -d ${{ env.TEMPORARY_TAG }} \
Expand All @@ -98,43 +95,45 @@ jobs:
exit 1
fi
echo "Copying toolchain from Docker container to host"
docker cp $container:/home/develop/x-tools.tar.xz x-tools-${{ matrix.triple }}.tar.xz
docker cp $container:/home/develop/x-tools.tar.xz x-tools-${{ matrix.triple }}-gcc${{ matrix.gcc-version }}.tar.xz
docker rm $container
- name: Upload toolchain
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: x-tools-${{ matrix.triple }}
path: x-tools-${{ matrix.triple }}.tar.xz
name: x-tools-${{ matrix.triple }}-gcc${{ matrix.gcc-version }}
path: x-tools-${{ matrix.triple }}-gcc${{ matrix.gcc-version }}.tar.xz

- name: Extract toolchain
run: tar xf x-tools-${{ matrix.triple }}-gcc${{ matrix.gcc-version }}.tar.xz
- name: Install pico-sdk
if: ${{ matrix.triple == 'arm-pico-eabi' }}
run: |
git clone --single-branch --depth=1 --shallow-submodules https://github.com/raspberrypi/pico-sdk.git
echo "PICO_SDK_PATH=$PWD/pico-sdk" >> "$GITHUB_ENV"
- name: Configure test project
run: cmake -B build -S . --toolchain ../x-tools/${{ matrix.triple }}/${{ matrix.triple }}.toolchain.cmake
working-directory: test
- name: Build test project
run: cmake --build build -j
working-directory: test

- name: Release toolchain
if: ${{ github.event.action == 'released' || github.event.action == 'prereleased' }}
uses: softprops/action-gh-release@17cd0d34deddf848fc0e7d9be5202c148c270a0a
with:
files: x-tools-${{ matrix.triple }}.tar.xz
files: x-tools-${{ matrix.triple }}-gcc${{ matrix.gcc-version }}.tar.xz

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Push Docker image
if: matrix.triple != 'arm-pico-eabi'
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0
with:
context: .
build-args: |
"HOST_TRIPLE=${{ matrix.triple }}"
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Push Docker image
if: matrix.triple == 'arm-pico-eabi'
id: build-and-push-pico
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: pico
HOST_TRIPLE=${{ matrix.triple }}
GCC_VERSION=${{ matrix.gcc-version }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
98 changes: 87 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,99 @@
FROM ghcr.io/tttapa/docker-crosstool-ng-multiarch:master
# Crosstool-NG -----------------------------------------------------------------

ARG HOST_TRIPLE
FROM centos:7 as ct-ng

# Install dependencies to build crosstool-ng and the toolchain
RUN yum -y update && \
yum install -y epel-release && \
yum install -y autoconf gperf bison file flex texinfo help2man gcc-c++ \
libtool make patch ncurses-devel python36-devel perl-Thread-Queue bzip2 \
git wget which xz unzip rsync && \
yum clean all

# Add a user called `develop` and add him to the sudo group
RUN useradd -m develop && echo "develop:develop" | chpasswd && \
usermod -aG wheel develop

USER develop
WORKDIR /home/develop

# Install autoconf
RUN wget https://ftp.gnu.org/gnu/autoconf/autoconf-2.72.tar.gz -O- | tar xz && \
cd autoconf-2.72 && \
./configure --prefix=/home/develop/.local && \
make -j$(nproc) && \
make install && \
cd .. && \
rm -rf autoconf-2.72
ENV PATH=/home/develop/.local/bin:$PATH

# Build crosstool-ng
RUN git clone -b master --single-branch --depth 1 \
https://github.com/crosstool-ng/crosstool-ng.git
WORKDIR /home/develop/crosstool-ng
RUN git show --summary && \
./bootstrap && \
mkdir build && cd build && \
../configure --prefix=/home/develop/.local && \
make -j$(($(nproc) * 2)) && \
make install && \
cd .. && rm -rf build
WORKDIR /home/develop
RUN mkdir /home/develop/src
COPY ${HOST_TRIPLE}.defconfig defconfig
COPY ${HOST_TRIPLE}.env .env
RUN ls -lah

RUN ct-ng defconfig
# Patches
# https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=280707&p=1700861#p1700861
RUN . ./.env; export DEB_TARGET_MULTIARCH="${HOST_TRIPLE_LIB_DIR}"; \
V=1 ct-ng build || { cat build.log && false; } && rm -rf .build
RUN wget https://ftp.debian.org/debian/pool/main/b/binutils/binutils_2.41-6.debian.tar.xz -O- | \
tar xJ debian/patches/129_multiarch_libpath.patch && \
mkdir -p patches/binutils/2.41 && \
mv debian/patches/129_multiarch_libpath.patch patches/binutils/2.41 && \
rm -rf debian

# Toolchain --------------------------------------------------------------------

FROM ct-ng as gcc-build

ARG HOST_TRIPLE
ARG GCC_VERSION

# Build the toolchain
COPY --chown=develop:develop ${HOST_TRIPLE}.defconfig .
COPY --chown=develop:develop ${HOST_TRIPLE}.env .
RUN [ -n "${GCC_VERSION}" ] && { echo "CT_GCC_V_${GCC_VERSION}=y" >> ${HOST_TRIPLE}.defconfig; }
RUN cp ${HOST_TRIPLE}.defconfig defconfig && ct-ng defconfig
RUN . ./${HOST_TRIPLE}.env && \
ct-ng build || { cat build.log && false; } && rm -rf .build

RUN chmod +w /home/develop/x-tools/${HOST_TRIPLE}
COPY cmake/Common.toolchain.cmake /home/develop/x-tools/${HOST_TRIPLE}/
COPY cmake/${HOST_TRIPLE}/* /home/develop/x-tools/${HOST_TRIPLE}/
RUN chmod -w /home/develop/x-tools/${HOST_TRIPLE}

ENV TOOLCHAIN_PATH=/home/develop/x-tools/${HOST_TRIPLE}
ENV PATH=${TOOLCHAIN_PATH}/bin:$PATH
# Build container --------------------------------------------------------------

FROM ubuntu:jammy

ARG HOST_TRIPLE

RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update -y && \
apt-get install --no-install-recommends -y \
ninja-build cmake make bison flex \
tar xz-utils gzip zip unzip bzip2 zstd \
ca-certificates wget git sudo && \
apt-get clean autoclean && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/*

# Add a user called `develop` and add him to the sudo group
RUN useradd -m develop && \
echo "develop:develop" | chpasswd && \
adduser develop sudo

USER develop
WORKDIR /home/develop

ENV TOOLCHAIN_PATH=/home/develop/opt/x-tools/${HOST_TRIPLE}
ENV PATH=${TOOLCHAIN_PATH}/bin:$PATH

# Copy the toolchain
COPY --chown=develop:develop --from=gcc-build /home/develop/x-tools /home/develop/opt/x-tools
Loading

0 comments on commit 8020eff

Please sign in to comment.