diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c0af34..4773541 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,24 +14,27 @@ jobs: matrix: include: - name: x86_64 - platform: linux/amd64 + gnu: x86_64-linux-musl + zig: x86_64-linux-musl - name: i686 - platform: linux/386 + gnu: i686-linux-musl + zig: x86-linux-musl - name: armv7l - platform: linux/arm/v7 + gnu: arm-linux-musleabihf + zig: arm-linux-musleabihf - name: aarch64 - platform: linux/arm64/v8 + gnu: aarch64-linux-musl + zig: aarch64-linux-musl fail-fast: false runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: actions/checkout@v4 - name: Build - run: docker build --target export --output build . --platform ${{ matrix.platform }} + run: > + docker build --target export --output build . + --build-arg GNU_TRIPLE=${{ matrix.gnu }} + --build-arg ZIG_TRIPLE=${{ matrix.zig }} - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -43,7 +46,7 @@ jobs: runs-on: macos-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build run: ./build-macos.sh - name: Upload artifacts @@ -65,7 +68,7 @@ jobs: runs-on: windows-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: msys2/setup-msys2@v2 with: msystem: ${{ matrix.sys }} @@ -96,6 +99,6 @@ jobs: working-directory: artifacts run: for f in *; do zip -jr $f.zip $f; done - name: Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@4634c16 with: files: artifacts/*.zip diff --git a/.gitignore b/.gitignore index 5682bd5..059f8bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ binutils-* build +source diff --git a/Dockerfile b/Dockerfile index 30ab24f..66e69d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,41 @@ # Build stage -FROM alpine:3.19.1 AS build +ARG ALPINE_VERSION=3.19.1 +FROM alpine:${ALPINE_VERSION} AS build # Install dependencies -RUN apk add --no-cache gcc musl-dev make +RUN apk add --no-cache binutils file gcc make musl-dev -# Download and extract source -RUN wget -qO- https://ftp.gnu.org/gnu/binutils/binutils-2.42.tar.xz | tar -xJ +# Install zig +ARG ZIG_VERSION=0.11.0 +RUN mkdir /zig && \ + wget -qO- "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-`uname -m`-${ZIG_VERSION}.tar.xz" | \ + tar -xJ -C /zig --strip-components=1 +ENV PATH="/zig:$PATH" -# Build binutils -WORKDIR /binutils-2.42 -RUN ./configure --target=powerpc-eabi --prefix=/target --disable-nls --disable-shared \ - && make -j$(nproc) configure-host \ - && make -j$(nproc) LDFLAGS=-all-static \ - && make install-strip +# Download binutils +ARG BINUTILS_VERSION=2.42 +RUN wget -q https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.xz + +# Build host binutils +ARG GNU_TRIPLE +RUN mkdir /binutils-host && \ + tar -xf /binutils-${BINUTILS_VERSION}.tar.xz -C /binutils-host --strip-components=1 && \ + cd /binutils-host && \ + ./configure --target=${GNU_TRIPLE} --prefix=/usr/local \ + --disable-nls --disable-shared --disable-gprofng --disable-ld --disable-gold && \ + make -j$(nproc) && \ + make install-strip + +# Build target binutils +ARG ZIG_TRIPLE +RUN mkdir /binutils && \ + tar -xf /binutils-${BINUTILS_VERSION}.tar.xz -C /binutils --strip-components=1 && \ + cd /binutils && \ + CC="zig cc -target ${ZIG_TRIPLE}" \ + ./configure --host=${GNU_TRIPLE} --target=powerpc-eabi --prefix=/target \ + --disable-nls --disable-shared --disable-gprof --without-zstd && \ + make -j$(nproc) && \ + make install-strip # Export binary (usage: docker build --target export --output build .) FROM scratch AS export diff --git a/build-macos.sh b/build-macos.sh index ddcf32a..b26607f 100755 --- a/build-macos.sh +++ b/build-macos.sh @@ -1,9 +1,10 @@ #!/bin/bash -ex PREFIX="$(pwd)/build" -wget -qO- https://ftp.gnu.org/gnu/binutils/binutils-2.42.tar.xz | tar -xJ -cd binutils-2.42 +mkdir source +wget -qO- https://ftp.gnu.org/gnu/binutils/binutils-2.42.tar.xz | tar -xJ -C source --strip-components=1 +cd source export CFLAGS="-arch arm64 -arch x86_64 -mmacosx-version-min=10.11" -./configure --target=powerpc-eabi --prefix="$PREFIX" --disable-nls --disable-shared --without-zstd +./configure --target=powerpc-eabi --prefix="$PREFIX" --disable-nls --disable-shared --disable-gprof --without-zstd make -j$(nproc) configure-host make -j$(nproc) make install-strip diff --git a/build-windows.sh b/build-windows.sh index 36bfac4..713bdd6 100644 --- a/build-windows.sh +++ b/build-windows.sh @@ -1,8 +1,9 @@ #!/bin/bash -ex PREFIX="$(pwd)/build" -wget -qO- https://ftp.gnu.org/gnu/binutils/binutils-2.42.tar.xz | tar -xJ -cd binutils-2.42 -./configure --target=powerpc-eabi --prefix="$PREFIX" --disable-nls --disable-shared +mkdir source +wget -qO- https://ftp.gnu.org/gnu/binutils/binutils-2.42.tar.xz | tar -xJ -C source --strip-components=1 +cd source +./configure --target=powerpc-eabi --prefix="$PREFIX" --disable-nls --disable-shared --disable-gprof --without-zstd make -j$(nproc) configure-host make -j$(nproc) make install-strip