From 421d98b248c3b8eedd804d25c081a88907bc1c6a Mon Sep 17 00:00:00 2001 From: deadprogram Date: Sat, 29 Aug 2026 10:58:49 +0200 Subject: [PATCH] ci: stop the LLVM caches from being evicted The Actions cache of the repository was at 10.24 GB against a quota of 10 GB, so GitHub removed entries by least recent use. The LLVM entries were among the first to go, and CI then built LLVM again although the LLVM version did not change. The Docker buildx layer blobs held 6.0 GB of the quota. All LLVM caches together held 1.97 GB. Move the Docker layer cache to a registry cache in GHCR, which does not use the Actions quota. Both jobs have the necessary permission and login already. Pin the LLVM commit in llvm-version.txt and fetch that commit, in place of a clone of the branch tip tinygo_22.x. Add a hash of that file to each LLVM cache key, so a change of the LLVM version invalidates the caches and no other change does. Also rename the LLVM image tags from llvm-20 to llvm-22. --- .dockerignore | 2 +- .github/workflows/build-macos.yml | 4 ++-- .github/workflows/compat.yml | 2 +- .github/workflows/docker.yml | 4 ++-- .github/workflows/linux.yml | 12 ++++++------ .github/workflows/llvm.yml | 8 ++++---- .github/workflows/nix.yml | 2 +- .github/workflows/sizediff.yml | 2 +- .github/workflows/windows.yml | 4 ++-- BUILDING.md | 4 ++++ Dockerfile | 1 + llvm-version.txt | 1 + make/llvm.mk | 9 ++++++++- 13 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 llvm-version.txt diff --git a/.dockerignore b/.dockerignore index 3b4255b9d..78ff006bf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,4 @@ build/ llvm-*/ +!llvm-version.txt .github - diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index c1a263c47..999b05342 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -46,7 +46,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-source with: - key: llvm-source-22-${{ matrix.os }}-v1 + key: llvm-source-22-${{ matrix.os }}-v1-${{ hashFiles('llvm-version.txt') }} path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -71,7 +71,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-build with: - key: llvm-build-22-${{ matrix.os }}-v1 + key: llvm-build-22-${{ matrix.os }}-v1-${{ hashFiles('llvm-version.txt') }} path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' diff --git a/.github/workflows/compat.yml b/.github/workflows/compat.yml index 2c658c45b..cc53fae05 100644 --- a/.github/workflows/compat.yml +++ b/.github/workflows/compat.yml @@ -46,7 +46,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-source with: - key: llvm-source-22-linux-compat + key: llvm-source-22-linux-compat-${{ hashFiles('llvm-version.txt') }} path: llvm-project/compiler-rt - name: Download LLVM source if: steps.cache-llvm-source.outputs.cache-hit != 'true' diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index f1e8be695..8d05a4047 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -64,5 +64,5 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/tinygo-dev:buildcache + cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/tinygo-dev:buildcache,mode=max diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 662d6180e..01a417dbd 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -66,7 +66,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-source with: - key: llvm-source-22-linux-alpine-v1 + key: llvm-source-22-linux-alpine-v1-${{ hashFiles('llvm-version.txt') }} path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -91,7 +91,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-build with: - key: llvm-build-22-linux-alpine-v1 + key: llvm-build-22-linux-alpine-v1-${{ hashFiles('llvm-version.txt') }} path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' @@ -268,7 +268,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-source with: - key: llvm-source-22-linux-asserts-v1 + key: llvm-source-22-linux-asserts-v1-${{ hashFiles('llvm-version.txt') }} path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -293,7 +293,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-build with: - key: llvm-build-22-linux-asserts-v1 + key: llvm-build-22-linux-asserts-v1-${{ hashFiles('llvm-version.txt') }} path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' @@ -377,7 +377,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-source with: - key: llvm-source-22-linux-v1 + key: llvm-source-22-linux-v1-${{ hashFiles('llvm-version.txt') }} path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -402,7 +402,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-build with: - key: llvm-build-22-linux-${{ matrix.goarch }}-v1 + key: llvm-build-22-linux-${{ matrix.goarch }}-v1-${{ hashFiles('llvm-version.txt') }} path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' diff --git a/.github/workflows/llvm.yml b/.github/workflows/llvm.yml index fac80561e..015ffa1d0 100644 --- a/.github/workflows/llvm.yml +++ b/.github/workflows/llvm.yml @@ -35,8 +35,8 @@ jobs: uses: docker/metadata-action@v6 with: images: | - tinygo/llvm-20 - ghcr.io/${{ github.repository_owner }}/llvm-20 + tinygo/llvm-22 + ghcr.io/${{ github.repository_owner }}/llvm-22 tags: | type=sha,format=long type=raw,value=latest @@ -59,5 +59,5 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/llvm-22:buildcache + cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/llvm-22:buildcache,mode=max diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 8772d6890..e5b3d3562 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -29,7 +29,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-source with: - key: llvm-source-22-linux-nix-v1 + key: llvm-source-22-linux-nix-v1-${{ hashFiles('llvm-version.txt') }} path: | llvm-project/compiler-rt - name: Download LLVM source diff --git a/.github/workflows/sizediff.yml b/.github/workflows/sizediff.yml index cbd0aaf8f..984e8370c 100644 --- a/.github/workflows/sizediff.yml +++ b/.github/workflows/sizediff.yml @@ -34,7 +34,7 @@ jobs: uses: actions/cache@v5 id: cache-llvm-source with: - key: llvm-source-22-sizediff-v1 + key: llvm-source-22-sizediff-v1-${{ hashFiles('llvm-version.txt') }} path: | llvm-project/compiler-rt - name: Download LLVM source diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 62f518b37..8e87537ce 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -40,7 +40,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-source with: - key: llvm-source-22-windows-v3 + key: llvm-source-22-windows-v3-${{ hashFiles('llvm-version.txt') }} path: | llvm-project/clang/lib/Headers llvm-project/clang/include @@ -65,7 +65,7 @@ jobs: uses: actions/cache/restore@v5 id: cache-llvm-build with: - key: llvm-build-22-windows-v1 + key: llvm-build-22-windows-v1-${{ hashFiles('llvm-version.txt') }} path: llvm-build - name: Build LLVM if: steps.cache-llvm-build.outputs.cache-hit != 'true' diff --git a/BUILDING.md b/BUILDING.md index 3b55e27bb..18ace1369 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -53,6 +53,10 @@ the git repository). Then, inside the directory, download the LLVM source: make llvm-source +The LLVM commit to use is pinned in `llvm-version.txt`. A change to that file +makes CI build LLVM again, because the file is part of the LLVM cache key. All +other changes reuse the cached LLVM build. + You can also store LLVM outside of the TinyGo root directory by setting the `LLVM_BUILDDIR`, `CLANG_SRC` and `LLD_SRC` make variables, but that is not covered by this guide. diff --git a/Dockerfile b/Dockerfile index 226a3b0da..c6d6ac0ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ RUN apt-get update && \ COPY ./GNUmakefile /tinygo/GNUmakefile COPY ./make /tinygo/make +COPY ./llvm-version.txt /tinygo/llvm-version.txt RUN cd /tinygo/ && \ make llvm-source diff --git a/llvm-version.txt b/llvm-version.txt new file mode 100644 index 000000000..28a7b8af8 --- /dev/null +++ b/llvm-version.txt @@ -0,0 +1 @@ +2be7242b6a4d59fe89fb43f7d1e7333dc9b307a2 diff --git a/make/llvm.mk b/make/llvm.mk index 94c7fb895..44ed0df4c 100644 --- a/make/llvm.mk +++ b/make/llvm.mk @@ -75,8 +75,15 @@ endif CGO_LDFLAGS+=-L$(abspath $(LLVM_BUILDDIR)/lib) -lclang $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_CONFIG_PREFIX) $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA) endif +# Pinned in llvm-version.txt. Branch tinygo_22.x of tinygo-org/llvm-project. +LLVM_REVISION = $(shell cat llvm-version.txt) + $(LLVM_PROJECTDIR)/llvm: - git clone -b tinygo_22.x --depth=1 https://github.com/tinygo-org/llvm-project $(LLVM_PROJECTDIR) + git init $(LLVM_PROJECTDIR) + cd $(LLVM_PROJECTDIR) && \ + git remote add origin https://github.com/tinygo-org/llvm-project && \ + git fetch --depth=1 origin $(LLVM_REVISION) && \ + git checkout FETCH_HEAD llvm-source: $(LLVM_PROJECTDIR)/llvm ## Get LLVM sources # Configure LLVM.