From 38dd429def759d92d4c5b4d22ae8d884abc4fc12 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Fri, 13 Nov 2026 13:20:37 +0800 Subject: [PATCH] Fix the Arm64 image build Stable Alpine (3.21 to 3.23) packages Verilator for x86-64 only, so the multi-platform push on dev failed with "verilator (no such package)" on linux/arm64. Take verilator and verilator-dev from edge/community on both architectures through an @edge-tagged repository, which keeps every other package on 3.22 and gives both images Verilator 5.050. apk del now uses --no-cache, since without an index it cannot resolve the @edge tag and refuses to commit. Install qemu-x86_64 for firtool once in the base stage instead of in both later stages, and build every platform on pull requests as well, publishing only on push, so a platform-specific break fails before merge. --- .github/workflows/docker.yml | 7 ++++--- Dockerfile | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5b7fd55..11cffa7 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -53,13 +53,14 @@ jobs: python3 runtest.py 0_demo.ipynb 2.1_first_module.ipynb 2.6_chiselsim.ipynb 4.1_firrtl_ast.ipynb docker run --rm --network none chisel-bootcamp:test python3 tests/test_visualizer.py - - name: Build and push - if: github.event_name == 'push' + # Build every platform on pull requests too, so a platform-specific break (such as a + # package missing for Arm64) fails before merge; only a push to dev publishes. + - name: Build all platforms (push only on push) uses: docker/build-push-action@v7 with: context: . platforms: linux/amd64,linux/arm64 - push: true + push: ${{ github.event_name == 'push' }} tags: sysprog21/chisel-bootcamp:latest cache-from: type=gha,scope=build cache-to: type=gha,mode=max,scope=build diff --git a/Dockerfile b/Dockerfile index 4cab347..a068584 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,18 @@ # First stage : setup the system and environment FROM alpine:3.22 AS base +ARG TARGETARCH + # Install OpenJDK 17 and runtime dependencies. # Chisel 7 simulates with ChiselSim, which drives Verilator, so a C++ toolchain # (g++, make, musl-dev) and Perl (Verilator is a Perl script) are runtime dependencies. +# Stable Alpine ships Verilator for x86-64 only, so both architectures take it from the +# edge/community repository; the @edge tag keeps every other package on 3.22. Later apk +# calls need --no-cache (or a fresh index) so that the @edge tag still resolves. +# On Arm64, firtool (an x86-64 executable, see the intermediate-builder stage) runs +# through qemu-user. RUN \ + echo "@edge https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \ apk add --no-cache \ openjdk17-jre-headless \ graphviz \ @@ -12,13 +20,14 @@ RUN \ py3-pip \ bash \ libstdc++ \ - verilator \ - verilator-dev \ + verilator@edge \ + verilator-dev@edge \ g++ \ make \ musl-dev \ perl \ && \ + if [ "$TARGETARCH" = "arm64" ]; then apk add --no-cache qemu-x86_64; fi && \ apk add --no-cache --virtual .build-deps \ gcc \ linux-headers \ @@ -32,7 +41,7 @@ RUN \ find /usr/lib/python3.12/site-packages -type d -name tests -exec rm -rf {} + 2>/dev/null || true && \ find /usr/lib/python3.12/site-packages -type d -name testing -exec rm -rf {} + 2>/dev/null || true && \ rm -rf /usr/lib/python3.12/site-packages/pip /usr/lib/python3.12/site-packages/setuptools && \ - apk del .build-deps + apk del --no-cache .build-deps ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk ENV PATH=$JAVA_HOME/bin:$PATH @@ -98,7 +107,7 @@ RUN \ # Chisel 7 emits SystemVerilog by running CIRCT's `firtool`, a self-contained static x86-64 # executable (Maven Central ships it inside the llvm-firtool jar). Install it once here so # the bootcamp works offline. There is no native Linux/Arm64 build of firtool: on Arm64 it -# runs through qemu-user (the rest of the toolchain, including Verilator, is native). +# runs through qemu-user, installed in the base stage (the rest of the toolchain is native). RUN \ mkdir -p /opt/firtool/bin && \ curl -fL --retry 3 -o firtool.jar \ @@ -107,7 +116,6 @@ RUN \ rm firtool.jar && \ chmod +x /opt/firtool/bin/firtool.x86_64 && \ if [ "$TARGETARCH" = "arm64" ]; then \ - apk add --no-cache qemu-x86_64 && \ printf '#!/bin/sh\nexec qemu-x86_64 /opt/firtool/bin/firtool.x86_64 "$@"\n' > /opt/firtool/bin/firtool && \ chmod +x /opt/firtool/bin/firtool; \ else \ @@ -117,12 +125,6 @@ RUN \ # Last stage FROM base AS final -ARG TARGETARCH - -# On Arm64 firtool (an x86-64 executable) runs through qemu-user, see above -RUN if [ "$TARGETARCH" = "arm64" ]; then apk add --no-cache qemu-x86_64; fi - - # Tell Chisel where to find the preinstalled firtool instead of downloading one ENV CHISEL_FIRTOOL_PATH=/opt/firtool/bin