From 07c6640a172ae61e36fc161c9a9b86a09e09f941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 8 May 2025 16:35:55 +0300 Subject: [PATCH 01/20] build-all: Merge handling of trivial options passed to build-llvm.sh --- build-all.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/build-all.sh b/build-all.sh index 42c21e04..9d38b33b 100755 --- a/build-all.sh +++ b/build-all.sh @@ -24,7 +24,7 @@ HOST_ARGS="" while [ $# -gt 0 ]; do case "$1" in - --enable-asserts) + --enable-asserts|--disable-dylib) LLVM_ARGS="$LLVM_ARGS $1" ;; --host-clang|--host-clang=*) @@ -36,9 +36,6 @@ while [ $# -gt 0 ]; do LLVM_ARGS="$LLVM_ARGS $1" FULL_LLVM=1 ;; - --disable-dylib) - LLVM_ARGS="$LLVM_ARGS $1" - ;; --disable-lldb) LLVM_ARGS="$LLVM_ARGS $1" NO_LLDB=1 From 5f28a085f514d2e85210dc3e2ef868e26e2d6a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 8 May 2025 16:33:54 +0300 Subject: [PATCH 02/20] build-llvm: Change the (unused) --stage2 option into --with-clang Don't use tools from $PREFIX/bin automatically; this can be confusing and problematic. If running with $PREFIX/bin in path, the build at this stage gets reconfigured if rebuilding after installing clang. For multistage builds, install into separate toolchain directories and add the right one to $PATH before invoking build-llvm.sh. If one really wants to use the tools from $PREFIX for a new build into the same directory, one has to add that directory to the path manually. --- build-llvm.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/build-llvm.sh b/build-llvm.sh index de2c4a43..7e6fe42d 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -35,9 +35,9 @@ while [ $# -gt 0 ]; do ASSERTS=ON ASSERTSSUFFIX="-asserts" ;; - --stage2) - STAGE2=1 - BUILDDIR="$BUILDDIR-stage2" + --with-clang) + WITH_CLANG=1 + BUILDDIR="$BUILDDIR-withclang" ;; --thinlto) LTO="thin" @@ -77,7 +77,7 @@ done BUILDDIR="$BUILDDIR$ASSERTSSUFFIX" if [ -z "$CHECKOUT_ONLY" ]; then if [ -z "$PREFIX" ]; then - echo $0 [--enable-asserts] [--stage2] [--thinlto] [--lto] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] dest + echo $0 [--enable-asserts] [--with-clang] [--thinlto] [--lto] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] dest exit 1 fi @@ -220,9 +220,9 @@ if [ -n "$HOST" ]; then CMAKEFLAGS="$CMAKEFLAGS -DPython3_INCLUDE_DIRS=$PYTHON_INCLUDE_DIR" CMAKEFLAGS="$CMAKEFLAGS -DPython3_LIBRARIES=$PYTHON_LIB" fi -elif [ -n "$STAGE2" ]; then - # Build using an earlier built and installed clang in the target directory - export PATH="$PREFIX/bin:$PATH" +elif [ -n "$WITH_CLANG" ]; then + # Build using clang and lld (from $PATH), rather than the system default + # tools. CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=clang" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=clang++" CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=lld" From efb8b34932e088251e4ec21a528680d6829aa3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 8 May 2025 23:38:36 +0300 Subject: [PATCH 03/20] build-llvm: Support using --with-clang in a --host cross build When cross compiling with llvm-mingw, we already implicitly use clang and lld, but we don't need to specify these options as they are set implicitly via the llvm-mingw wrappers. --- build-llvm.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/build-llvm.sh b/build-llvm.sh index 7e6fe42d..6a229bbe 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -157,9 +157,18 @@ CMAKEFLAGS="$LLVM_CMAKEFLAGS" if [ -n "$HOST" ]; then ARCH="${HOST%%-*}" - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=$HOST-gcc" - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=$HOST-g++" - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_PROCESSOR=$ARCH" + + if [ -n "$WITH_CLANG" ]; then + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=clang" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=clang++" + CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=lld" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER_TARGET=$HOST" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER_TARGET=$HOST" + else + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=$HOST-gcc" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=$HOST-g++" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_PROCESSOR=$ARCH" + fi case $HOST in *-mingw32) CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows" From f5d8121ea2900d55de2b5b43d221856213b185aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 9 May 2025 17:44:34 +0300 Subject: [PATCH 04/20] build-llvm: Use llvm-libtool-darwin if doing LTO macOS builds with a custom clang --- build-llvm.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build-llvm.sh b/build-llvm.sh index 6a229bbe..b5786fc1 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -298,6 +298,19 @@ if [ -z "$HOST" ] && [ "$(uname)" = "Darwin" ]; then # This silences a cmake warning. CMAKEFLAGS="$CMAKEFLAGS -DLLDB_USE_SYSTEM_DEBUGSERVER=ON" fi + if [ -n "$WITH_CLANG" ] && [ -n "$LTO" ]; then + # If doing LTO, we need to make sure other related tools are used. + # CMAKE_LIBTOOL is not a standard cmake tool, but an LLVM specific + # thing. It defaults to looking up the tool with xcrun rather than + # looking in paths first. + # If building for multiple architectures at once + # (CMAKE_OSX_ARCHITECTURES), we also need to provide a tool named + # "lipo" in the PATH (this is invoked by Clang directly, so we can't + # specify it here unless we pass in the option "-fuse-lipo="). If + # the LLVM CMake build wasn't using libtool, we would also need to + # specify LLVM_AR and LLVM_RANLIB. + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_LIBTOOL=$(command -v llvm-libtool-darwin)" + fi fi TOOLCHAIN_ONLY=ON From 19f1c90a15e710194960dd21d46b924e6b173978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 3 Jun 2025 00:00:17 +0300 Subject: [PATCH 05/20] build-llvm: Add a --macos-native-tools option This augments the result of an earlier build, with tools required for building for macOS with the tools built with build-llvm.sh. --- build-llvm.sh | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/build-llvm.sh b/build-llvm.sh index b5786fc1..3f2bcd72 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -68,6 +68,9 @@ while [ $# -gt 0 ]; do --no-llvm-tool-reuse) NO_LLVM_TOOL_REUSE=1 ;; + --macos-native-tools) + MACOS_NATIVE_TOOLS=1 + ;; *) PREFIX="$1" ;; @@ -77,7 +80,7 @@ done BUILDDIR="$BUILDDIR$ASSERTSSUFFIX" if [ -z "$CHECKOUT_ONLY" ]; then if [ -z "$PREFIX" ]; then - echo $0 [--enable-asserts] [--with-clang] [--thinlto] [--lto] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] dest + echo $0 [--enable-asserts] [--with-clang] [--thinlto] [--lto] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] [--macos-native-tools] dest exit 1 fi @@ -331,6 +334,24 @@ fi [ -z "$CLEAN" ] || rm -rf $BUILDDIR mkdir -p $BUILDDIR cd $BUILDDIR + +if [ -n "$MACOS_NATIVE_TOOLS" ]; then + # Build tools needed for targeting macOS with LTO. + # + # The install-(-stripped) targets are unavailable for + # tools that are excluded due to LLVM_INSTALL_TOOLCHAIN_ONLY=ON and + # LLVM_TOOLCHAIN_TOOLS, so install those manually. + cmake --build . --target llvm-lipo --target llvm-libtool-darwin + # Install ld64.lld, required for -fuse-ld=lld + cmake --install . --strip --component lld + # Install llvm-libtool-darwin and lipo, needed for building with LTO. + # See the comment further above for more details about this. + cp bin/llvm-lipo bin/llvm-libtool-darwin $PREFIX/bin + strip $PREFIX/bin/llvm-lipo $PREFIX/bin/llvm-libtool-darwin + ln -sf llvm-lipo $PREFIX/bin/lipo + exit 0 +fi + [ -n "$NO_RECONF" ] || rm -rf CMake* cmake \ ${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \ From 454962132a8a972c66c0e7b57e280ed8d3feaffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 9 May 2025 14:21:54 +0300 Subject: [PATCH 06/20] build-compiler-rt: Add an option for compiling runtimes for the native OS --- build-compiler-rt.sh | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/build-compiler-rt.sh b/build-compiler-rt.sh index d7f3e3d7..89c8d722 100755 --- a/build-compiler-rt.sh +++ b/build-compiler-rt.sh @@ -40,13 +40,16 @@ while [ $# -gt 0 ]; do elif [ "$1" = "--disable-cfguard" ]; then CFGUARD_CFLAGS= ENABLE_CFGUARD= + elif [ "$1" = "--native" ]; then + NATIVE=1 + SRC_DIR=.. else PREFIX="$1" fi shift done if [ -z "$PREFIX" ]; then - echo "$0 [--build-sanitizers] [--enable-cfguard|--disable-cfguard] dest" + echo "$0 [--build-sanitizers] [--enable-cfguard|--disable-cfguard] [--native] dest" exit 1 fi if [ -n "$SANITIZERS" ] && [ -n "$ENABLE_CFGUARD" ]; then @@ -59,8 +62,7 @@ export PATH="$PREFIX/bin:$PATH" : ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}} -ANY_ARCH=$(echo $ARCHS | awk '{print $1}') -CLANG_RESOURCE_DIR="$("$PREFIX/bin/$ANY_ARCH-w64-mingw32-clang" --print-resource-dir)" +CLANG_RESOURCE_DIR="$("$PREFIX/bin/clang" --print-resource-dir)" if [ ! -d llvm-project/compiler-rt ] || [ -n "$SYNC" ]; then CHECKOUT_ONLY=1 ./build-llvm.sh @@ -91,6 +93,34 @@ if [ -h "$CLANG_RESOURCE_DIR/include" ]; then INSTALL_PREFIX="$WORKDIR/install" fi +if [ -n "$NATIVE" ]; then + [ -z "$CLEAN" ] || rm -rf build-native + mkdir -p build-native + cd build-native + [ -n "$NO_RECONF" ] || rm -rf CMake* + cmake \ + ${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$CLANG_RESOURCE_DIR" \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DLLVM_CONFIG_PATH="" \ + -DCMAKE_FIND_ROOT_PATH=$PREFIX \ + -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ + -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \ + -DCOMPILER_RT_USE_LIBCXX=OFF \ + $SRC_DIR + cmake --build . ${CORES:+-j${CORES}} + cmake --install . --prefix "$INSTALL_PREFIX" + + if [ "$INSTALL_PREFIX" != "$CLANG_RESOURCE_DIR" ]; then + # symlink to system headers - skip copy + rm -rf "$INSTALL_PREFIX/include" + + cp -r "$INSTALL_PREFIX/." $CLANG_RESOURCE_DIR + fi + exit 0 +fi for arch in $ARCHS; do [ -z "$CLEAN" ] || rm -rf build-$arch$BUILD_SUFFIX From 6d31f358d8c8bf5732e5d02aed8baf8bb9653d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 9 May 2025 15:01:06 +0300 Subject: [PATCH 07/20] build-llvm: Add options for doing PGO builds Passing --instrumented=IR or --instrumented=Frontend builds instrumented tool binaries. After running them and merging the output profile files, run build-llvm.sh with --profile=profile.profdata. --- build-llvm.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/build-llvm.sh b/build-llvm.sh index 3f2bcd72..9f21b713 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -24,6 +24,7 @@ LINK_DYLIB=ON ASSERTSSUFFIX="" LLDB=ON CLANG_TOOLS_EXTRA=ON +INSTRUMENTED=OFF while [ $# -gt 0 ]; do case "$1" in @@ -71,6 +72,28 @@ while [ $# -gt 0 ]; do --macos-native-tools) MACOS_NATIVE_TOOLS=1 ;; + --instrumented|--instrumented=*) + INSTRUMENTED="${1#--instrumented}" + INSTRUMENTED="${INSTRUMENTED#=}" + INSTRUMENTED="${INSTRUMENTED:-Frontend}" + : ${LLVM_PROFILE_DATA_DIR:=/tmp/llvm-profile} + # A fixed BUILDDIR is set at the end for this case. + ;; + --pgo|--pgo=*) + case "$1" in + --pgo=*) + LLVM_PROFDATA_FILE="${1#--pgo}" + LLVM_PROFDATA_FILE="${LLVM_PROFDATA_FILE#=}" + ;; + esac + LLVM_PROFDATA_FILE="${LLVM_PROFDATA_FILE:-profile.profdata}" + if [ ! -e "$LLVM_PROFDATA_FILE" ]; then + echo Profile \"$LLVM_PROFDATA_FILE\" not found + exit 1 + fi + LLVM_PROFDATA_FILE="$(cd "$(dirname "$LLVM_PROFDATA_FILE")" && pwd)/$(basename "$LLVM_PROFDATA_FILE")" + BUILDDIR="$BUILDDIR-pgo" + ;; *) PREFIX="$1" ;; @@ -80,12 +103,14 @@ done BUILDDIR="$BUILDDIR$ASSERTSSUFFIX" if [ -z "$CHECKOUT_ONLY" ]; then if [ -z "$PREFIX" ]; then - echo $0 [--enable-asserts] [--with-clang] [--thinlto] [--lto] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] [--macos-native-tools] dest + echo $0 [--enable-asserts] [--with-clang] [--thinlto] [--lto] [--instrumented[=type]] [--pgo[=profile]] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] [--macos-native-tools] dest exit 1 fi - mkdir -p "$PREFIX" - PREFIX="$(cd "$PREFIX" && pwd)" + if [ -z "$INSTRUMENTED" ]; then + mkdir -p "$PREFIX" + PREFIX="$(cd "$PREFIX" && pwd)" + fi fi if [ ! -d llvm-project ]; then @@ -316,6 +341,12 @@ if [ -z "$HOST" ] && [ "$(uname)" = "Darwin" ]; then fi fi +if [ "$INSTRUMENTED" != "OFF" ]; then + # For instrumented build, use a hardcoded builddir that we can + # locate, and don't install the built files. + BUILDDIR="build-instrumented" +fi + TOOLCHAIN_ONLY=ON if [ -n "$FULL_LLVM" ]; then TOOLCHAIN_ONLY=OFF @@ -364,10 +395,19 @@ cmake \ -DLLVM_LINK_LLVM_DYLIB=$LINK_DYLIB \ -DLLVM_TOOLCHAIN_TOOLS="llvm-ar;llvm-ranlib;llvm-objdump;llvm-rc;llvm-cvtres;llvm-nm;llvm-strings;llvm-readobj;llvm-dlltool;llvm-pdbutil;llvm-objcopy;llvm-strip;llvm-cov;llvm-profdata;llvm-addr2line;llvm-symbolizer;llvm-windres;llvm-ml;llvm-readelf;llvm-size;llvm-cxxfilt;llvm-lib" \ ${HOST+-DLLVM_HOST_TRIPLE=$HOST} \ + -DLLVM_BUILD_INSTRUMENTED=$INSTRUMENTED \ + ${LLVM_PROFILE_DATA_DIR+-DLLVM_PROFILE_DATA_DIR=$LLVM_PROFILE_DATA_DIR} \ + ${LLVM_PROFDATA_FILE+-DLLVM_PROFDATA_FILE=$LLVM_PROFDATA_FILE} \ $CMAKEFLAGS \ .. -cmake --build . ${CORES:+-j${CORES}} -cmake --install . --strip +if [ "$INSTRUMENTED" != "OFF" ]; then + # For instrumented builds, don't install the built files (so $PREFIX + # is entirely unused). + cmake --build . ${CORES:+-j${CORES}} --target clang --target lld +else + cmake --build . ${CORES:+-j${CORES}} + cmake --install . --strip -cp ../LICENSE.TXT $PREFIX + cp ../LICENSE.TXT $PREFIX +fi From 839b37219e2833c5dae39522356918a1991d9add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sat, 10 May 2025 23:51:22 +0300 Subject: [PATCH 08/20] pgo-training: Add a script for doing PGO training of a toolchain Use a makefile for running a set of commands in parallel. --- pgo-training.make | 57 ++++++++++++++++++++++++++++++++++++++++++ pgo-training.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100755 pgo-training.make create mode 100755 pgo-training.sh diff --git a/pgo-training.make b/pgo-training.make new file mode 100755 index 00000000..b26bc029 --- /dev/null +++ b/pgo-training.make @@ -0,0 +1,57 @@ +#!/bin/sh +# +# Copyright (c) 2025 Martin Storsjo +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +CFLAGS = --sysroot=$(STAGE1) -resource-dir=$(shell $(STAGE1)/bin/clang --print-resource-dir) --config-user-dir=$(STAGE1)/bin +CC = $(PREFIX)/bin/clang +CXX = $(PREFIX)/bin/clang++ + +hello-exception-opt-%.exe: test/hello-exception.cpp + $(CXX) -target $*-w64-mingw32 $(CFLAGS) $+ -o $@ -O3 + +hello-exception-%.exe: test/hello-exception.cpp + $(CXX) -target $*-w64-mingw32 $(CFLAGS) $+ -o $@ + +sqlite-opt-%.exe: $(SQLITE)/sqlite3.c $(SQLITE)/shell.c + $(CC) -target $*-w64-mingw32 $(CFLAGS) $+ -o $@ -O3 + +sqlite-%.exe: $(SQLITE)/sqlite3.c $(SQLITE)/shell.c + $(CC) -target $*-w64-mingw32 $(CFLAGS) $+ -o $@ + +LIBCXXTEST = llvm-project/libcxx/test/std/algorithms/alg.sorting/alg.sort/sort/sort.pass.cpp + +libcxxtest-opt-%.exe: $(LIBCXXTEST) + $(CXX) -target $*-w64-mingw32 $(CFLAGS) $+ -o $@ -Illvm-project/libcxx/test/support -O3 + +libcxxtest-%.exe: $(LIBCXXTEST) + $(CXX) -target $*-w64-mingw32 $(CFLAGS) $+ -o $@ -Illvm-project/libcxx/test/support + +ARCHS ?= i686 x86_64 armv7 aarch64 + +TARGETS = hello-exception hello-exception-opt + +ifneq ($(SQLITE),) +TARGETS += sqlite sqlite-opt +endif +ifneq ($(wildcard $(LIBCXXTEST)),) +TARGETS += libcxxtest libcxxtest-opt +endif + +ALLTARGETS = $(foreach arch, $(ARCHS), $(foreach target, $(TARGETS), $(target)-$(arch).exe)) + +all: $(ALLTARGETS) + +clean: + rm -f $(ALLTARGETS) diff --git a/pgo-training.sh b/pgo-training.sh new file mode 100755 index 00000000..918e0e55 --- /dev/null +++ b/pgo-training.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# +# Copyright (c) 2025 Martin Storsjo +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +set -e + +: ${SQLITE_VERSION:=3490200} +: ${SQLITE_YEAR:=2025} + +: ${LLVM_PROFILE_DATA_DIR:=/tmp/llvm-profile} +: ${LLVM_PROFDATA_FILE:=profile.profdata} + +if [ $# -lt 2 ]; then + echo $0 build stage1 + exit 1 +fi +PREFIX="$1" +STAGE1="$2" +PREFIX="$(cd "$PREFIX" && pwd)" + +MAKE=make +if command -v gmake >/dev/null; then + MAKE=gmake +fi + +: ${CORES:=$(nproc 2>/dev/null)} +: ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)} +: ${CORES:=4} +: ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}} + +download() { + if command -v curl >/dev/null; then + curl -LO "$1" + else + wget "$1" + fi +} + +SQLITE=sqlite-amalgamation-$SQLITE_VERSION +if [ ! -d $SQLITE ]; then + download https://sqlite.org/$SQLITE_YEAR/sqlite-amalgamation-$SQLITE_VERSION.zip + unzip sqlite-amalgamation-$SQLITE_VERSION.zip +fi + +rm -rf "$LLVM_PROFILE_DATA_DIR" +$MAKE -f pgo-training.make PREFIX=$PREFIX STAGE1=$STAGE1 SQLITE=$SQLITE clean +$MAKE -f pgo-training.make PREFIX=$PREFIX STAGE1=$STAGE1 SQLITE=$SQLITE -j$CORES + +rm -f "$LLVM_PROFDATA_FILE" +$STAGE1/bin/llvm-profdata merge -output "$LLVM_PROFDATA_FILE" $LLVM_PROFILE_DATA_DIR/*.profraw +rm -rf "$LLVM_PROFILE_DATA_DIR" From d69ccd33a756e94763e1e91002e4663c3bc0d852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 8 May 2025 16:55:49 +0300 Subject: [PATCH 09/20] build-lldb-mi: Fix finding the build directory As build-llvm now can create a larger variety of build dir names, enumerating all possible suffixes becomes problematic (especially as they don't necessarily appear in one canonical order). Instead, iterate over potential matches. If cross compiling, it is easy as we can require the directory to contain the expected suffix. If not cross compiling, we have no explicit suffix to look for, but we can check that the directory doesn't match common cross compilation triples. --- build-lldb-mi.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/build-lldb-mi.sh b/build-lldb-mi.sh index 7c228213..ebc4db02 100755 --- a/build-lldb-mi.sh +++ b/build-lldb-mi.sh @@ -75,12 +75,32 @@ export LLVM_DIR="$PREFIX" LLVM_SRC="$(pwd)/llvm-project/llvm" if [ -d "$LLVM_SRC" ]; then SUFFIX=${HOST+-}$HOST - for base in build build-asserts; do - if [ -d "$LLVM_SRC/$base$SUFFIX" ]; then - export LLVM_DIR="$LLVM_SRC/$base$SUFFIX" - break + DIRS="" + cd llvm-project/llvm + for dir in build*$SUFFIX; do + if [ -z "$SUFFIX" ]; then + case $dir in + *linux*|*mingw32*) + continue + ;; + esac + fi + if [ -d "$dir" ]; then + DIRS="$DIRS $dir" fi done + if [ -n "$DIRS" ]; then + dir="$(ls -td $DIRS | head -1)" + export LLVM_DIR="$LLVM_SRC/$dir" + echo Using $LLVM_DIR as LLVM build dir + break + else + # No build directory found; this is ok if the installed prefix is a + # full (development) install of LLVM. Warn that we didn't find what + # we were looking for. + echo Warning, did not find a suitable LLVM build dir, assuming $PREFIX contains LLVM development files >&2 + fi + cd ../.. fi if [ -n "$HOST" ]; then From 9e628b0f2d1b893643b0542ecd4cdfb891e43520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 4 Jun 2025 15:25:17 +0300 Subject: [PATCH 10/20] build-lldb-mi: Disallow detecting LLVM outside of $LLVM_DIR Do the same as when cross compiling; disallow detecting dependencies outside of the given CMAKE_FIND_ROOT_PATH. Don't export LLVM_DIR as we no longer need to pass it implicitly that way. This makes the errors clearer, if LLVM isn't found where expected, instead of misdetecting it from a different installation of LLVM in the system. If lldb-mi would try to find other optional dependencies, they would no longer be found; this was already the case when cross compiling though. --- build-lldb-mi.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/build-lldb-mi.sh b/build-lldb-mi.sh index ebc4db02..1dd6b13d 100755 --- a/build-lldb-mi.sh +++ b/build-lldb-mi.sh @@ -65,7 +65,7 @@ else esac fi -export LLVM_DIR="$PREFIX" +LLVM_DIR="$PREFIX" # Try to find/guess the builddir under the llvm buildtree next by. # If LLVM was built without LLVM_INSTALL_TOOLCHAIN_ONLY, and the LLVM @@ -91,7 +91,7 @@ if [ -d "$LLVM_SRC" ]; then done if [ -n "$DIRS" ]; then dir="$(ls -td $DIRS | head -1)" - export LLVM_DIR="$LLVM_SRC/$dir" + LLVM_DIR="$LLVM_SRC/$dir" echo Using $LLVM_DIR as LLVM build dir break else @@ -121,14 +121,14 @@ if [ -n "$HOST" ]; then exit 1 ;; esac - - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH=$LLVM_DIR" - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER" - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY" - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY" - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY" fi +CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH=$LLVM_DIR" +CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER" +CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY" +CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY" +CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY" + if [ -n "$MACOS_REDIST" ]; then : ${MACOS_REDIST_ARCHS:=arm64 x86_64} : ${MACOS_REDIST_VERSION:=10.12} From c6001d30567cf3274731dd9a24dbfa08c925052b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 9 May 2025 00:26:14 +0300 Subject: [PATCH 11/20] build-cross-tools: Allow passing LTO and PGO options to build-llvm.sh --- build-cross-tools.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build-cross-tools.sh b/build-cross-tools.sh index 1aa94804..fd28ec71 100755 --- a/build-cross-tools.sh +++ b/build-cross-tools.sh @@ -44,6 +44,9 @@ while [ $# -gt 0 ]; do --disable-make) NO_MAKE=1 ;; + --thinlto|--lto|--pgo*) + LLVM_ARGS="$LLVM_ARGS $1" + ;; *) if [ -z "$NATIVE" ]; then NATIVE="$1" @@ -60,7 +63,7 @@ while [ $# -gt 0 ]; do shift done if [ -z "$CROSS_ARCH" ]; then - echo $0 native prefix arch [--with-python] [--disable-lldb] [--disable-lldb-mi] [--disable-clang-tool-extra] [--disable-mingw-w64-tools] [--disable-make] + echo $0 native prefix arch [--with-python] [--disable-lldb] [--disable-lldb-mi] [--disable-clang-tool-extra] [--disable-mingw-w64-tools] [--disable-make] [--thinlto] [--lto] [--pgo[=profile]] exit 1 fi From 37daec78acfe86ba2c94fd72db144487638104b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 8 May 2025 16:36:44 +0300 Subject: [PATCH 12/20] build-all: Allow passing more options through to build-llvm.sh --- build-all.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-all.sh b/build-all.sh index 9d38b33b..4e70373c 100755 --- a/build-all.sh +++ b/build-all.sh @@ -24,7 +24,7 @@ HOST_ARGS="" while [ $# -gt 0 ]; do case "$1" in - --enable-asserts|--disable-dylib) + --enable-asserts|--disable-dylib|--with-clang|--thinlto) LLVM_ARGS="$LLVM_ARGS $1" ;; --host-clang|--host-clang=*) @@ -84,7 +84,7 @@ while [ $# -gt 0 ]; do shift done if [ -z "$PREFIX" ]; then - echo "$0 [--host-clang[=clang]] [--enable-asserts] [--disable-dylib] [--full-llvm] [--disable-lldb] [--disable-lldb-mi] [--disable-clang-tools-extra] [--host=triple] [--with-default-win32-winnt=0x601] [--with-default-msvcrt=ucrt] [--enable-cfguard|--disable-cfguard] [--no-runtimes] [--no-tools] [--wipe-runtimes] [--clean-runtimes] dest" + echo "$0 [--host-clang[=clang]] [--enable-asserts] [--disable-dylib] [--with-clang] [--thinlto] [--full-llvm] [--disable-lldb] [--disable-lldb-mi] [--disable-clang-tools-extra] [--host=triple] [--with-default-win32-winnt=0x601] [--with-default-msvcrt=ucrt] [--enable-cfguard|--disable-cfguard] [--no-runtimes] [--no-tools] [--wipe-runtimes] [--clean-runtimes] dest" exit 1 fi From d3c7a1b06f60ef7a810002038becd5294a26eb4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 2 Jun 2025 16:12:20 +0300 Subject: [PATCH 13/20] build-all: Add an --llvm-only option --- build-all.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build-all.sh b/build-all.sh index 4e70373c..48a3f045 100755 --- a/build-all.sh +++ b/build-all.sh @@ -73,6 +73,9 @@ while [ $# -gt 0 ]; do --clean-runtimes) CLEAN_RUNTIMES=1 ;; + --llvm-only) + LLVM_ONLY=1 + ;; *) if [ -n "$PREFIX" ]; then echo Unrecognized parameter $1 @@ -84,7 +87,7 @@ while [ $# -gt 0 ]; do shift done if [ -z "$PREFIX" ]; then - echo "$0 [--host-clang[=clang]] [--enable-asserts] [--disable-dylib] [--with-clang] [--thinlto] [--full-llvm] [--disable-lldb] [--disable-lldb-mi] [--disable-clang-tools-extra] [--host=triple] [--with-default-win32-winnt=0x601] [--with-default-msvcrt=ucrt] [--enable-cfguard|--disable-cfguard] [--no-runtimes] [--no-tools] [--wipe-runtimes] [--clean-runtimes] dest" + echo "$0 [--host-clang[=clang]] [--enable-asserts] [--disable-dylib] [--with-clang] [--thinlto] [--full-llvm] [--disable-lldb] [--disable-lldb-mi] [--disable-clang-tools-extra] [--host=triple] [--with-default-win32-winnt=0x601] [--with-default-msvcrt=ucrt] [--enable-cfguard|--disable-cfguard] [--no-runtimes] [--llvm-only] [--no-tools] [--wipe-runtimes] [--clean-runtimes] dest" exit 1 fi @@ -109,6 +112,9 @@ if [ -z "$NO_TOOLS" ]; then ./strip-llvm.sh $PREFIX $HOST_ARGS fi fi + if [ -n "$LLVM_ONLY" ]; then + exit 0 + fi ./install-wrappers.sh $PREFIX $HOST_ARGS ${HOST_CLANG:+--host-clang=$HOST_CLANG} ./build-mingw-w64-tools.sh $PREFIX $HOST_ARGS fi From 7dcff8f89f7e6d0ecbd0095f351412bfd5b5638c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 3 Jun 2025 00:18:14 +0300 Subject: [PATCH 14/20] build-all: Add support for PGO builds Allow both doing one single stage at a time, or driving the full build with three stages all in one command. --- build-all.sh | 110 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 4 deletions(-) diff --git a/build-all.sh b/build-all.sh index 48a3f045..39bfa676 100755 --- a/build-all.sh +++ b/build-all.sh @@ -76,18 +76,55 @@ while [ $# -gt 0 ]; do --llvm-only) LLVM_ONLY=1 ;; + --stage1) + STAGE1=1 + LLVM_ARGS="$LLVM_ARGS --disable-lldb --disable-clang-tools-extra" + NO_LLDB=1 + ;; + --profile|--profile=*) + case "$1" in + --profile=*) + INSTRUMENTATION="=${1#*=}" + ;; + esac + PROFILE=1 + LLVM_ARGS="$LLVM_ARGS --disable-lldb --disable-clang-tools-extra --with-clang --disable-dylib --instrumented$INSTRUMENTATION" + NO_LLDB=1 + LLVM_ONLY=1 + ;; + --pgo|--pgo=*) + PGO=1 + LLVM_ARGS="$LLVM_ARGS --with-clang $1" + ;; + --full-pgo|--full-pgo=*) + case "$1" in + --full-pgo=*) + INSTRUMENTATION="=${1#*=}" + ;; + esac + PGO=1 + FULL_PGO=1 + ;; *) if [ -n "$PREFIX" ]; then - echo Unrecognized parameter $1 - exit 1 + if [ -n "$PREFIX_PGO" ]; then + echo Unrecognized parameter $1 + exit 1 + fi + PREFIX_PGO="$1" + else + PREFIX="$1" fi - PREFIX="$1" ;; esac shift done if [ -z "$PREFIX" ]; then - echo "$0 [--host-clang[=clang]] [--enable-asserts] [--disable-dylib] [--with-clang] [--thinlto] [--full-llvm] [--disable-lldb] [--disable-lldb-mi] [--disable-clang-tools-extra] [--host=triple] [--with-default-win32-winnt=0x601] [--with-default-msvcrt=ucrt] [--enable-cfguard|--disable-cfguard] [--no-runtimes] [--llvm-only] [--no-tools] [--wipe-runtimes] [--clean-runtimes] dest" + echo "$0 [--host-clang[=clang]] [--enable-asserts] [--disable-dylib] [--with-clang] [--thinlto] [--full-llvm] [--disable-lldb] [--disable-lldb-mi] [--disable-clang-tools-extra] [--host=triple] [--with-default-win32-winnt=0x601] [--with-default-msvcrt=ucrt] [--enable-cfguard|--disable-cfguard] [--no-runtimes] [--llvm-only] [--no-tools] [--wipe-runtimes] [--clean-runtimes] [--stage1] [--profile[=type]] [--pgo[=profile]] [--full-pgo[=type]] dest [pgo-dest]" + exit 1 +fi +if [ -n "$PREFIX_PGO" ] && [ -z "$PGO" ] && [ -z "$FULL_PGO" ]; then + echo Unrecognized parameter $1 exit 1 fi @@ -102,15 +139,80 @@ if [ -n "${HOST_CLANG}" ] && [ "${CFGUARD_ARGS}" = "--enable-cfguard" ]; then "${HOST_CLANG}" -c -x c -o - - -Werror -mguard=cf /dev/null 2>/dev/null || CFGUARD_ARGS="--disable-cfguard" fi +if [ -n "$FULL_PGO" ]; then + if [ -z "$PREFIX_PGO" ]; then + echo Must provide a second destination for a PGO build + exit 1 + fi + ./build-all.sh "$PREFIX" --stage1 $LLVM_ARGS $MINGW_ARGS $CFGUARD_ARGS + unset COMPILER_LAUNCHER + ./build-all.sh "$PREFIX" --profile$INSTRUMENTATION $LLVM_ARGS + ./build-all.sh "$PREFIX" "$PREFIX_PGO" --thinlto --pgo --llvm-only $LLVM_ARGS + # If one already has a usable profile, one could also do the following + # two steps only: + # ./build-all.sh "$PREFIX" --stage1 --llvm-only + # ./build-all.sh "$PREFIX" "$PREFIX_PGO" --pgo + exit 0 +fi + +if [ -n "$PROFILE" ]; then + export PATH=$PREFIX/bin:$PATH + STAGE1_PREFIX=$PREFIX + PREFIX=/tmp/dummy-prefix +elif [ -n "$PGO" ]; then + if [ -z "$PREFIX_PGO" ]; then + echo Must provide a second destination for a PGO build + exit 1 + fi + export PATH=$PREFIX/bin:$PATH + STAGE1_PREFIX=$PREFIX + PREFIX=$PREFIX_PGO + + if [ -n "$LLVM_ONLY" ] && [ "$PREFIX" != "$STAGE1_PREFIX" ] ; then + # Only rebuilding LLVM, not any runtimes. Copy the stage1 toolchain + # and rebuild LLVM on top of it. + rm -rf $PREFIX + mkdir -p "$(dirname "$PREFIX")" + cp -a "$STAGE1_PREFIX" "$PREFIX" + # Remove the native Linux/macOS runtimes which aren't needed in + # the final distribution. + rm -rf "$PREFIX"/lib/clang/*/lib/darwin + rm -rf "$PREFIX"/lib/clang/*/lib/linux + fi +fi + +if [ "$(uname)" = "Darwin" ]; then + if [ -n "$PROFILE" ] || [ -n "$PGO" ]; then + # Using a custom Clang, which doesn't find the SDK automatically. + # CMake sets this automatically, but if using the compiler directly, + # this is needed. (If compilation uses "cc" or "gcc", it will miss + # the stage1 llvm-mingw toolchain and use the system compiler anyway.) + export SDKROOT=$(xcrun --show-sdk-path) + fi +fi + if [ -z "$NO_TOOLS" ]; then if [ -z "${HOST_CLANG}" ]; then ./build-llvm.sh $PREFIX $LLVM_ARGS $HOST_ARGS + if [ -n "$PROFILE" ]; then + ./pgo-training.sh llvm-project/llvm/build-instrumented $STAGE1_PREFIX + exit 0 + fi if [ -z "$NO_LLDB" ] && [ -z "$NO_LLDB_MI" ]; then ./build-lldb-mi.sh $PREFIX $HOST_ARGS fi if [ -z "$FULL_LLVM" ]; then ./strip-llvm.sh $PREFIX $HOST_ARGS fi + if [ -n "$STAGE1" ]; then + if [ "$(uname)" = "Darwin" ]; then + ./build-llvm.sh $PREFIX --macos-native-tools + fi + # Build runtimes. On Linux, this is needed for profiling. + # On macOS, it is also needed for OS availability helpers like + # __isPlatformVersionAtLeast. + ./build-compiler-rt.sh --native $PREFIX + fi fi if [ -n "$LLVM_ONLY" ]; then exit 0 From eb3cb9c31db2b0506315d963a39dfae905c2206d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 8 May 2025 16:53:38 +0300 Subject: [PATCH 15/20] github: Build macOS and Linux toolchains with a stage1 Clang --- .github/workflows/build.yml | 101 +++++++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c706785..375a68b9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,13 +64,52 @@ jobs: parameters.txt retention-days: 7 + linux-stage1: + if: (github.event_name != 'schedule') || (github.repository == 'mstorsjo/llvm-mingw') + needs: [prepare] + runs-on: ubuntu-22.04 + 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: | + # 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 --stage1 --llvm-only + .github/workflows/store-version.sh install/llvm/versions.txt + cd install + DISTRO=ubuntu-$(grep DISTRIB_RELEASE /etc/lsb-release | cut -f 2 -d =)-$(uname -m) + NAME=llvm-$TAG-$DISTRO + mv llvm $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-llvm-x86_64 + path: | + llvm-*.tar.xz + retention-days: 7 + # Build a cross compiler for Linux, targeting Windows. linux: if: (github.event_name != 'schedule') || (github.repository == 'mstorsjo/llvm-mingw') - needs: [prepare] + needs: [prepare, linux-stage1] runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: linux-llvm-x86_64 + - name: Unpack stage1 Clang + run: | + tar -Jxf llvm-*.tar.xz + rm llvm-*.tar.xz + sudo mv llvm* /opt/llvm + echo /opt/llvm/bin >> $GITHUB_PATH - name: Build env: LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}} @@ -82,7 +121,7 @@ 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 --with-clang .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 @@ -102,10 +141,19 @@ 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, linux-stage1, prepare] runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: linux-llvm-x86_64 + - name: Unpack stage1 Clang + run: | + tar -Jxf llvm-*.tar.xz + rm llvm-*.tar.xz + sudo mv llvm* /opt/llvm + echo /opt/llvm/bin >> $GITHUB_PATH - name: Build env: LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}} @@ -113,7 +161,7 @@ jobs: 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 $(pwd)/install/llvm-mingw --no-runtimes --host=aarch64-linux-gnu --with-clang .github/workflows/store-version.sh install/llvm-mingw/versions.txt - uses: actions/download-artifact@v4 with: @@ -183,13 +231,51 @@ 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] 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 + echo $HOME/llvm/bin >> $GITHUB_PATH - name: Build env: LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}} @@ -203,7 +289,8 @@ 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 + export SDKROOT=$(xcrun --show-sdk-path) + MACOS_REDIST=1 LLVM_CMAKEFLAGS="-DLLVM_ENABLE_ZSTD=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw --with-clang .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 @@ -689,6 +776,8 @@ jobs: run: | rm -rf linux-asserts* rm -rf msys2* + rm -rf linux-llvm-* + rm -rf macos-llvm* mv *-toolchain/*.zip *-toolchain/*.tar.xz . - name: Upload binaries env: From bc8eea6fc04d068b96f5da56d483747753da604b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 9 May 2025 00:29:50 +0300 Subject: [PATCH 16/20] github: Build all second stage toolchains with thinlto --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 375a68b9..478181c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -121,7 +121,7 @@ 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 --with-clang + LLVM_CMAKEFLAGS="-DLLVM_ENABLE_LIBXML2=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw --with-clang --thinlto .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 @@ -161,7 +161,7 @@ jobs: 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 --with-clang + ./build-all.sh $(pwd)/install/llvm-mingw --no-runtimes --host=aarch64-linux-gnu --with-clang --thinlto .github/workflows/store-version.sh install/llvm-mingw/versions.txt - uses: actions/download-artifact@v4 with: @@ -290,7 +290,7 @@ jobs: # universal binaries fails as those libraries are unavailable in the # other (x86_64) architecture form. export SDKROOT=$(xcrun --show-sdk-path) - MACOS_REDIST=1 LLVM_CMAKEFLAGS="-DLLVM_ENABLE_ZSTD=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw --with-clang + MACOS_REDIST=1 LLVM_CMAKEFLAGS="-DLLVM_ENABLE_ZSTD=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw --with-clang --thinlto .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 @@ -398,7 +398,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 .github/workflows/store-version.sh install/llvm-mingw/versions.txt cd install NAME=llvm-mingw-$TAG-${{matrix.crt}}-${{matrix.arch}} From 05625eaf62d1e86e69875ba6efa7cb9c8e76657b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sat, 24 May 2025 00:35:19 +0300 Subject: [PATCH 17/20] github: Build the linux full toolchain already in stage1 This makes a cross compiler available before doing the full second stage. --- .github/workflows/build.yml | 58 +++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 478181c6..218efbae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,6 +73,7 @@ jobs: - name: Build env: LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}} + MINGW_W64_VERSION: ${{needs.prepare.outputs.MINGW_W64_VERSION}} TAG: ${{needs.prepare.outputs.TAG}} SOURCE_DATE_EPOCH: ${{needs.prepare.outputs.COMMIT_DATE_UNIX}} BUILD_DATE: ${{needs.prepare.outputs.BUILD_DATE}} @@ -80,18 +81,20 @@ 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 --stage1 --llvm-only - .github/workflows/store-version.sh install/llvm/versions.txt + 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-$TAG-$DISTRO - mv llvm $NAME + 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-llvm-x86_64 + name: linux-stage1-ucrt-x86_64-toolchain path: | - llvm-*.tar.xz + llvm-mingw-*.tar.xz retention-days: 7 # Build a cross compiler for Linux, targeting Windows. @@ -103,25 +106,26 @@ jobs: - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 with: - name: linux-llvm-x86_64 + name: linux-stage1-ucrt-x86_64-toolchain - name: Unpack stage1 Clang run: | - tar -Jxf llvm-*.tar.xz - rm llvm-*.tar.xz - sudo mv llvm* /opt/llvm - echo /opt/llvm/bin >> $GITHUB_PATH + 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 - name: Build env: LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}} - MINGW_W64_VERSION: ${{needs.prepare.outputs.MINGW_W64_VERSION}} TAG: ${{needs.prepare.outputs.TAG}} SOURCE_DATE_EPOCH: ${{needs.prepare.outputs.COMMIT_DATE_UNIX}} BUILD_DATE: ${{needs.prepare.outputs.BUILD_DATE}} run: | + mkdir -p install + cp -a /opt/llvm-mingw install # 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 --with-clang --thinlto + LLVM_CMAKEFLAGS="-DLLVM_ENABLE_LIBXML2=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw --with-clang --thinlto --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 @@ -141,19 +145,19 @@ 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, linux-stage1, prepare] + needs: [linux-stage1, prepare] runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 with: - name: linux-llvm-x86_64 + name: linux-stage1-ucrt-x86_64-toolchain - name: Unpack stage1 Clang run: | - tar -Jxf llvm-*.tar.xz - rm llvm-*.tar.xz - sudo mv llvm* /opt/llvm - echo /opt/llvm/bin >> $GITHUB_PATH + 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 - name: Build env: LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}} @@ -163,17 +167,9 @@ jobs: 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 --with-clang --thinlto .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 @@ -367,7 +363,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, prepare] runs-on: ubuntu-latest strategy: fail-fast: false @@ -380,7 +376,7 @@ 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 @@ -776,7 +772,7 @@ jobs: run: | rm -rf linux-asserts* rm -rf msys2* - rm -rf linux-llvm-* + rm -rf linux-stage1-* rm -rf macos-llvm* mv *-toolchain/*.zip *-toolchain/*.tar.xz . - name: Upload binaries From 80fad736442d3221c349862fcbd75a1a81d5d40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 9 May 2025 23:24:21 +0300 Subject: [PATCH 18/20] github: Build with PGO Using Frontend instrumentation rather than IR. This gives less total speedup, but makes the profile much more usable for cross other build targets. Build the full Linux toolchain in stage1; this avoids needing to rebuild runtimes for doing the profiling in stage2, and avoids needing to wait for stage3 to complete before cross building for Windows. --- .github/workflows/build.yml | 66 +++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 218efbae..4003b22e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -97,10 +97,41 @@ jobs: 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] + needs: [prepare, linux-stage1, linux-profile] runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 @@ -112,7 +143,9 @@ jobs: 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/download-artifact@v4 + with: + name: profile - name: Build env: LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}} @@ -120,12 +153,10 @@ jobs: SOURCE_DATE_EPOCH: ${{needs.prepare.outputs.COMMIT_DATE_UNIX}} BUILD_DATE: ${{needs.prepare.outputs.BUILD_DATE}} run: | - mkdir -p install - cp -a /opt/llvm-mingw install # 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 --with-clang --thinlto --llvm-only + 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 @@ -145,7 +176,7 @@ 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-stage1, prepare] + needs: [linux-stage1, linux-profile, prepare] runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 @@ -157,7 +188,9 @@ jobs: 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/download-artifact@v4 + with: + name: profile - name: Build env: LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}} @@ -165,7 +198,7 @@ jobs: 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 --with-clang --thinlto + ./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 - name: Assemble the cross-built toolchain run: | @@ -259,7 +292,7 @@ jobs: # Build a cross compiler for macOS, targeting Windows. macos: if: (github.event_name != 'schedule') || (github.repository == 'mstorsjo/llvm-mingw') - needs: [prepare, macos-stage1] + needs: [prepare, macos-stage1, linux-profile] runs-on: macos-latest steps: - uses: actions/checkout@v4 @@ -271,7 +304,9 @@ jobs: tar -Jxf llvm-*.tar.xz rm llvm-*.tar.xz mv llvm* $HOME/llvm - echo $HOME/llvm/bin >> $GITHUB_PATH + - uses: actions/download-artifact@v4 + with: + name: profile - name: Build env: LLVM_VERSION: ${{needs.prepare.outputs.LLVM_VERSION}} @@ -285,8 +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. - export SDKROOT=$(xcrun --show-sdk-path) - MACOS_REDIST=1 LLVM_CMAKEFLAGS="-DLLVM_ENABLE_ZSTD=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw --with-clang --thinlto + 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 @@ -363,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-stage1, prepare] + needs: [linux-stage1, linux-profile, prepare] runs-on: ubuntu-latest strategy: fail-fast: false @@ -384,6 +418,9 @@ jobs: 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}} @@ -394,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 --thinlto + ./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}} @@ -774,6 +811,7 @@ jobs: rm -rf msys2* rm -rf linux-stage1-* rm -rf macos-llvm* + rm -rf profile* mv *-toolchain/*.zip *-toolchain/*.tar.xz . - name: Upload binaries env: From ca34a156340698771d12460ca5d012e6bebbd3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 30 May 2025 23:59:59 +0300 Subject: [PATCH 19/20] github: Build the msvcrt toolchains with LTO and PGO --- .github/workflows/msvcrt.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/msvcrt.yml b/.github/workflows/msvcrt.yml index 9fb12761..ff0856e4 100644 --- a/.github/workflows/msvcrt.yml +++ b/.github/workflows/msvcrt.yml @@ -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}} @@ -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}} From 04bc2bc1c58454c51270887be0f96e2dd1a36077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 28 Feb 2024 14:33:01 +0200 Subject: [PATCH 20/20] github: Build the whole multiplatform docker image with Dockerfile.toolchain This makes the docker image contain a PGO optimized compiler, without needing to redo all of the PGO build stages in docker. This reverts commit 8f421127194ea0ca2325bbe6648a783612718619, and fixes building the multiplatform image in a simpler way. Instead of doing two separate builds, with separate Dockerfiles, just do one multiplatform build of one Dockerfile, which docker runs serially, for each one of the included architectures, just packaging the prebuilt toolchains in the docker image. --- .github/workflows/docker.yml | 49 ++++-------------------------------- 1 file changed, 5 insertions(+), 44 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 411a20be..c992bb54 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -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 @@ -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 @@ -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}}