Skip to content

Building the toolchain with PGO #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
07c6640
build-all: Merge handling of trivial options passed to build-llvm.sh
mstorsjo May 8, 2025
5f28a08
build-llvm: Change the (unused) --stage2 option into --with-clang
mstorsjo May 8, 2025
efb8b34
build-llvm: Support using --with-clang in a --host cross build
mstorsjo May 8, 2025
f5d8121
build-llvm: Use llvm-libtool-darwin if doing LTO macOS builds with a …
mstorsjo May 9, 2025
19f1c90
build-llvm: Add a --macos-native-tools option
mstorsjo Jun 2, 2025
4549621
build-compiler-rt: Add an option for compiling runtimes for the nativ…
mstorsjo May 9, 2025
6d31f35
build-llvm: Add options for doing PGO builds
mstorsjo May 9, 2025
839b372
pgo-training: Add a script for doing PGO training of a toolchain
mstorsjo May 10, 2025
d69ccd3
build-lldb-mi: Fix finding the build directory
mstorsjo May 8, 2025
9e628b0
build-lldb-mi: Disallow detecting LLVM outside of $LLVM_DIR
mstorsjo Jun 4, 2025
c6001d3
build-cross-tools: Allow passing LTO and PGO options to build-llvm.sh
mstorsjo May 8, 2025
37daec7
build-all: Allow passing more options through to build-llvm.sh
mstorsjo May 8, 2025
d3c7a1b
build-all: Add an --llvm-only option
mstorsjo Jun 2, 2025
7dcff8f
build-all: Add support for PGO builds
mstorsjo Jun 2, 2025
eb3cb9c
github: Build macOS and Linux toolchains with a stage1 Clang
mstorsjo May 8, 2025
bc8eea6
github: Build all second stage toolchains with thinlto
mstorsjo May 8, 2025
05625ea
github: Build the linux full toolchain already in stage1
mstorsjo May 23, 2025
80fad73
github: Build with PGO
mstorsjo May 9, 2025
ca34a15
github: Build the msvcrt toolchains with LTO and PGO
mstorsjo May 30, 2025
04bc2bc
github: Build the whole multiplatform docker image with Dockerfile.to…
mstorsjo Feb 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 142 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ jobs:
parameters.txt
retention-days: 7

# Build a cross compiler for Linux, targeting Windows.
linux:
linux-stage1:
if: (github.event_name != 'schedule') || (github.repository == 'mstorsjo/llvm-mingw')
needs: [prepare]
runs-on: ubuntu-22.04
Expand All @@ -82,7 +81,82 @@ jobs:
# Skip dynamic library dependencies that might make it harder to
# run the binaries on other distros (and that have little use within
# llvm-mingw).
LLVM_CMAKEFLAGS="-DLLVM_ENABLE_LIBXML2=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw
LLVM_CMAKEFLAGS="-DLLVM_ENABLE_LIBXML2=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw --stage1
.github/workflows/store-version.sh install/llvm-mingw/versions.txt
./test-libcxx-module.sh $(pwd)/install/llvm-mingw
./run-tests.sh $(pwd)/install/llvm-mingw
cd install
DISTRO=ubuntu-$(grep DISTRIB_RELEASE /etc/lsb-release | cut -f 2 -d =)-$(uname -m)
NAME=llvm-mingw-stage1-$TAG-ucrt-$DISTRO
mv llvm-mingw $NAME
tar -Jcf ../$NAME.tar.xz --format=ustar --numeric-owner --owner=0 --group=0 --sort=name --mtime="$BUILD_DATE" $NAME
- uses: actions/upload-artifact@v4
with:
name: linux-stage1-ucrt-x86_64-toolchain
path: |
llvm-mingw-*.tar.xz
retention-days: 7

linux-profile:
if: (github.event_name != 'schedule') || (github.repository == 'mstorsjo/llvm-mingw')
needs: [prepare, linux-stage1]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: linux-stage1-ucrt-x86_64-toolchain
- name: Unpack stage1 Clang
run: |
tar -Jxf llvm-mingw-*.tar.xz
rm llvm-mingw-*.tar.xz
mv llvm-mingw* llvm-mingw-stage1
- name: Build
env:
LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}}
TAG: ${{needs.prepare.outputs.TAG}}
SOURCE_DATE_EPOCH: ${{needs.prepare.outputs.COMMIT_DATE_UNIX}}
BUILD_DATE: ${{needs.prepare.outputs.BUILD_DATE}}
run: |
# Build LLVM in mostly the same way as it is going to be built in the
# final form.
LLVM_CMAKEFLAGS="-DLLVM_ENABLE_LIBXML2=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh --profile $(pwd)/llvm-mingw-stage1
- uses: actions/upload-artifact@v4
with:
name: profile
path: |
profile.profdata
retention-days: 7

# Build a cross compiler for Linux, targeting Windows.
linux:
if: (github.event_name != 'schedule') || (github.repository == 'mstorsjo/llvm-mingw')
needs: [prepare, linux-stage1, linux-profile]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: linux-stage1-ucrt-x86_64-toolchain
- name: Unpack stage1 Clang
run: |
tar -Jxf llvm-mingw-*.tar.xz
rm llvm-mingw-*.tar.xz
sudo mv llvm-mingw* /opt/llvm-mingw
- uses: actions/download-artifact@v4
with:
name: profile
- name: Build
env:
LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}}
TAG: ${{needs.prepare.outputs.TAG}}
SOURCE_DATE_EPOCH: ${{needs.prepare.outputs.COMMIT_DATE_UNIX}}
BUILD_DATE: ${{needs.prepare.outputs.BUILD_DATE}}
run: |
# Skip dynamic library dependencies that might make it harder to
# run the binaries on other distros (and that have little use within
# llvm-mingw).
LLVM_CMAKEFLAGS="-DLLVM_ENABLE_LIBXML2=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh /opt/llvm-mingw $(pwd)/install/llvm-mingw --thinlto --pgo --llvm-only
.github/workflows/store-version.sh install/llvm-mingw/versions.txt
./test-libcxx-module.sh $(pwd)/install/llvm-mingw
./run-tests.sh $(pwd)/install/llvm-mingw
Expand All @@ -102,30 +176,33 @@ jobs:
# libraries that were built in the 'linux' step above.
linux-cross-aarch64:
if: (github.event_name != 'schedule') || (github.repository == 'mstorsjo/llvm-mingw')
needs: [linux, prepare]
needs: [linux-stage1, linux-profile, prepare]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: linux-stage1-ucrt-x86_64-toolchain
- name: Unpack stage1 Clang
run: |
tar -Jxf llvm-mingw-*.tar.xz
rm llvm-mingw-*.tar.xz
sudo mv llvm-mingw* /opt/llvm-mingw
- uses: actions/download-artifact@v4
with:
name: profile
- name: Build
env:
LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}}
MINGW_W64_VERSION: ${{needs.prepare.outputs.MINGW_W64_VERSION}}
SOURCE_DATE_EPOCH: ${{needs.prepare.outputs.COMMIT_DATE_UNIX}}
run: |
sudo apt-get update && sudo apt-get install g++-aarch64-linux-gnu
./build-all.sh $(pwd)/install/llvm-mingw --no-runtimes --host=aarch64-linux-gnu
./build-all.sh /opt/llvm-mingw $(pwd)/install/llvm-mingw --no-runtimes --host=aarch64-linux-gnu --thinlto --pgo
.github/workflows/store-version.sh install/llvm-mingw/versions.txt
- uses: actions/download-artifact@v4
with:
name: linux-ucrt-x86_64-toolchain
- name: Unpack native toolchain
run: |
tar -Jxf llvm-mingw-*.tar.xz
rm llvm-mingw-*.tar.xz
mv llvm-mingw* llvm-mingw-native
- name: Assemble the cross-built toolchain
run: |
./prepare-cross-toolchain-unix.sh $(pwd)/llvm-mingw-native $(pwd)/install/llvm-mingw
./prepare-cross-toolchain-unix.sh /opt/llvm-mingw $(pwd)/install/llvm-mingw
- name: Test using the cross-built assembled toolchain
run: |
sudo apt-get update && sudo apt-get install qemu-user-static libc6-arm64-cross libstdc++6-arm64-cross
Expand Down Expand Up @@ -183,13 +260,53 @@ jobs:
llvm-mingw-linux.tar.xz
retention-days: 7

macos-stage1:
if: (github.event_name != 'schedule') || (github.repository == 'mstorsjo/llvm-mingw')
needs: [prepare]
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Build
env:
LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}}
TAG: ${{needs.prepare.outputs.TAG}}
SOURCE_DATE_EPOCH: ${{needs.prepare.outputs.COMMIT_DATE_UNIX}}
BUILD_DATE: ${{needs.prepare.outputs.BUILD_DATE}}
run: |
# Disable zstd and python. Both are available on the runners, but
# installed with homebrew, and only available in the native (arm64)
# form.
LLVM_CMAKEFLAGS="-DLLVM_ENABLE_ZSTD=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm --stage1 --llvm-only
.github/workflows/store-version.sh install/llvm/versions.txt
cd install
NAME=llvm-$TAG-macos-$(uname -m)
mv llvm $NAME
gtar -Jcf ../$NAME.tar.xz --format=ustar --numeric-owner --owner=0 --group=0 --sort=name --mtime="$BUILD_DATE" $NAME
- uses: actions/upload-artifact@v4
with:
name: macos-llvm
path: |
llvm-*.tar.xz
retention-days: 7

# Build a cross compiler for macOS, targeting Windows.
macos:
if: (github.event_name != 'schedule') || (github.repository == 'mstorsjo/llvm-mingw')
needs: [prepare]
needs: [prepare, macos-stage1, linux-profile]
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: macos-llvm
- name: Unpack stage1 Clang
run: |
tar -Jxf llvm-*.tar.xz
rm llvm-*.tar.xz
mv llvm* $HOME/llvm
- uses: actions/download-artifact@v4
with:
name: profile
- name: Build
env:
LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}}
Expand All @@ -203,7 +320,7 @@ jobs:
# form. Therefore, autodetection will pick them up, but linking
# universal binaries fails as those libraries are unavailable in the
# other (x86_64) architecture form.
MACOS_REDIST=1 LLVM_CMAKEFLAGS="-DLLVM_ENABLE_ZSTD=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw
MACOS_REDIST=1 LLVM_CMAKEFLAGS="-DLLVM_ENABLE_ZSTD=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $HOME/llvm $(pwd)/install/llvm-mingw --thinlto --pgo
.github/workflows/store-version.sh install/llvm-mingw/versions.txt
./test-libcxx-module.sh $(pwd)/install/llvm-mingw
./run-tests.sh $(pwd)/install/llvm-mingw
Expand Down Expand Up @@ -280,7 +397,7 @@ jobs:
# architectures). The binaries built here match actual releases quite closely.
linux-cross-windows:
if: (github.event_name != 'schedule') || (github.repository == 'mstorsjo/llvm-mingw')
needs: [linux, prepare]
needs: [linux-stage1, linux-profile, prepare]
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -293,14 +410,17 @@ jobs:
steps:
- uses: actions/download-artifact@v4
with:
name: linux-${{matrix.crt}}-x86_64-toolchain
name: linux-stage1-${{matrix.crt}}-x86_64-toolchain
- name: Unpack cross toolchain
run: |
tar -Jxf llvm-mingw-*.tar.xz
rm llvm-mingw-*.tar.xz
sudo mv llvm-mingw* /opt/llvm-mingw
echo /opt/llvm-mingw/bin >> $GITHUB_PATH
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: profile
- name: Build
env:
LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}}
Expand All @@ -311,7 +431,7 @@ jobs:
BUILD_DATE: ${{needs.prepare.outputs.BUILD_DATE}}
run: |
sudo apt-get update && sudo apt-get install libltdl-dev swig autoconf-archive
./build-cross-tools.sh /opt/llvm-mingw $(pwd)/install/llvm-mingw ${{matrix.arch}} --with-python
./build-cross-tools.sh /opt/llvm-mingw $(pwd)/install/llvm-mingw ${{matrix.arch}} --with-python --thinlto --pgo
.github/workflows/store-version.sh install/llvm-mingw/versions.txt
cd install
NAME=llvm-mingw-$TAG-${{matrix.crt}}-${{matrix.arch}}
Expand Down Expand Up @@ -689,6 +809,9 @@ jobs:
run: |
rm -rf linux-asserts*
rm -rf msys2*
rm -rf linux-stage1-*
rm -rf macos-llvm*
rm -rf profile*
mv *-toolchain/*.zip *-toolchain/*.tar.xz .
- name: Upload binaries
env:
Expand Down
49 changes: 5 additions & 44 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,11 @@ jobs:
docker-build:
needs: [prepare]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- { file: Dockerfile, key: amd64 }
- { file: Dockerfile.toolchain, platforms: linux/arm64, key: arm64 }
steps:
- uses: actions/checkout@v4
with:
ref: ${{inputs.ref}}
- name: Download toolchain
if: ${{matrix.file == 'Dockerfile.toolchain'}}
uses: dawidd6/action-download-artifact@v10
with:
workflow: build.yml
Expand All @@ -86,7 +79,6 @@ jobs:
name_is_regexp: true
path: toolchain
- name: Set up QEMU
if: ${{matrix.file == 'Dockerfile.toolchain'}}
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -98,42 +90,11 @@ jobs:
password: ${{secrets.DOCKER_PASSWORD}}
- name: Build Docker images
uses: docker/build-push-action@v5
id: build
with:
context: .
platforms: ${{matrix.platforms}}
platforms: linux/amd64,linux/arm64
push: ${{inputs.push}}
file: ./${{matrix.file}}
outputs: |
type=image,name=mstorsjo/llvm-mingw,push-by-digest=true,name-canonical=true
- name: Write outputs for later steps
uses: cloudposse/github-action-matrix-outputs-write@main
id: out
with:
matrix-step-name: ${{github.job}}
matrix-key: ${{matrix.key}}
outputs: |-
digest: ${{steps.build.outputs.digest}}

docker-create:
needs: [docker-build, prepare]
runs-on: ubuntu-latest
if: ${{inputs.push}}
steps:
- uses: cloudposse/github-action-matrix-outputs-read@main
id: read
with:
matrix-step-name: docker-build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{vars.DOCKER_USERNAME}}
password: ${{secrets.DOCKER_PASSWORD}}
- name: Create final image
run: |
set -x
for tag in latest ${{needs.prepare.outputs.TAG}}; do
docker buildx imagetools create -t mstorsjo/llvm-mingw:$tag mstorsjo/llvm-mingw@${{fromJson(steps.read.outputs.result).digest.amd64}} mstorsjo/llvm-mingw@${{fromJson(steps.read.outputs.result).digest.arm64}}
done
file: ./Dockerfile.toolchain
tags: |
mstorsjo/llvm-mingw:latest
mstorsjo/llvm-mingw:${{needs.prepare.outputs.TAG}}
10 changes: 9 additions & 1 deletion .github/workflows/msvcrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{inputs.ref}}
- name: Download profile
uses: dawidd6/action-download-artifact@v6
with:
workflow: build.yml
workflow_conclusion: success
ref: ${{inputs.ref}}
event: push
name: profile
- name: Build
env:
LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}}
Expand All @@ -114,7 +122,7 @@ jobs:
TAG: ${{needs.prepare.outputs.TAG}}
run: |
sudo apt-get update && sudo apt-get install libltdl-dev swig autoconf-archive
./build-cross-tools.sh /opt/llvm-mingw $(pwd)/install/llvm-mingw ${{matrix.arch}} --with-python
./build-cross-tools.sh /opt/llvm-mingw $(pwd)/install/llvm-mingw ${{matrix.arch}} --with-python --thinlto --pgo
.github/workflows/store-version.sh install/llvm-mingw/versions.txt
cd install
NAME=llvm-mingw-$TAG-${{matrix.crt}}-${{matrix.arch}}
Expand Down
Loading