From 257d100cc4fe4d1f999375845e593f95028d2a3c Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Mon, 22 Sep 2025 15:16:46 +0100 Subject: [PATCH 1/2] [Static SDK] Build clang before running the main build. We need to do this because otherwise libc++ fails to build, since the clang we pick up from the Swift install is an older version than the one libc++ requires (libc++ currently needs Clang 19; we ship Clang 17 with Swift). --- swift-ci/sdks/static-linux/scripts/build.sh | 43 ++++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/swift-ci/sdks/static-linux/scripts/build.sh b/swift-ci/sdks/static-linux/scripts/build.sh index 70d3f2ef..6e938cd8 100755 --- a/swift-ci/sdks/static-linux/scripts/build.sh +++ b/swift-ci/sdks/static-linux/scripts/build.sh @@ -268,6 +268,37 @@ else exit 1 fi +# ----------------------------------------------------------------------- + +header "Building clang for host" + +mkdir -p ${build_dir}/host/clang ${build_dir}/clang + +run cmake -G Ninja -S ${source_dir}/swift-project/llvm-project/llvm \ + -B ${build_dir}/host/clang \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_ENABLE_PROJECTS="clang" \ + -DLLVM_PARALLEL_LINK_JOBS=1 \ + -DCMAKE_INSTALL_PREFIX=${build_dir}/clang + +quiet_pushd ${build_dir}/host/clang +run ninja -j$parallel_jobs +quiet_popd + +header "Installing clang for host" + +quiet_pushd ${build_dir}/host/clang +run ninja -j$parallel_jobs install +quiet_popd + +clang_dir=${build_dir}/clang + +header "Clang version" + +${clang_dir}/bin/clang --version + +# ----------------------------------------------------------------------- + for arch in $archs; do # Fix architecture names @@ -288,11 +319,11 @@ for arch in $archs; do "${sdk_root}/usr/lib/swift_static" ln -sf ../swift/clang "${sdk_root}/usr/lib/swift_static/clang" - clang_resource_dir=$(${swift_dir}/bin/clang -print-resource-dir) + clang_resource_dir=$(${clang_dir}/bin/clang -print-resource-dir) cp -rT $clang_resource_dir/include $sdk_resource_dir/include - cc="${swift_dir}/bin/clang -target $triple -resource-dir ${sdk_resource_dir} --sysroot ${sdk_root}" - cxx="${swift_dir}/bin/clang++ -target $triple -resource-dir ${sdk_resource_dir} --sysroot ${sdk_root} -stdlib=libc++ -unwindlib=libunwind" + cc="${clang_dir}/bin/clang -target $triple -resource-dir ${sdk_resource_dir} --sysroot ${sdk_root}" + cxx="${clang_dir}/bin/clang++ -target $triple -resource-dir ${sdk_resource_dir} --sysroot ${sdk_root} -stdlib=libc++ -unwindlib=libunwind" as="$cc" # Creating this gets rid of a warning @@ -406,9 +437,9 @@ set(CMAKE_SYSROOT ${sdk_root}) set(CMAKE_CROSSCOMPILING=YES) set(CMAKE_EXE_LINKER_FLAGS "-unwindlib=libunwind -rtlib=compiler-rt -stdlib=libc++ -fuse-ld=lld -lc++ -lc++abi") -set(CMAKE_C_COMPILER ${swift_dir}/bin/clang -resource-dir ${sdk_resource_dir}) -set(CMAKE_CXX_COMPILER ${swift_dir}/bin/clang++ -resource-dir ${sdk_resource_dir} -stdlib=libc++) -set(CMAKE_ASM_COMPILER ${swift_dir}/bin/clang -resource-dir ${sdk_resource_dir}) +set(CMAKE_C_COMPILER ${clang_dir}/bin/clang -resource-dir ${sdk_resource_dir}) +set(CMAKE_CXX_COMPILER ${clang_dir}/bin/clang++ -resource-dir ${sdk_resource_dir} -stdlib=libc++) +set(CMAKE_ASM_COMPILER ${clang_dir}/bin/clang -resource-dir ${sdk_resource_dir}) set(CMAKE_FIND_ROOT_PATH ${sdk_root}) EOF From 0f08135c14a5463a69a6abeed4bcc6a42cf216f3 Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Mon, 22 Sep 2025 15:58:01 +0100 Subject: [PATCH 2/2] [Static SDK] Turn off -Werror for BoringSSL. `-Werror` is a stupid option; it basically breaks the build whenever a newer compiler adds a new warning that triggers in your code. We don't need it here, so disable it. --- swift-ci/sdks/static-linux/scripts/build.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/swift-ci/sdks/static-linux/scripts/build.sh b/swift-ci/sdks/static-linux/scripts/build.sh index 6e938cd8..d39ec24b 100755 --- a/swift-ci/sdks/static-linux/scripts/build.sh +++ b/swift-ci/sdks/static-linux/scripts/build.sh @@ -239,6 +239,8 @@ function run() { "$@" } +# ----------------------------------------------------------------------- + header "Building CMake from source" quiet_pushd ${source_dir}/swift-project/cmake @@ -255,6 +257,8 @@ run export PATH="${build_dir}/cmake/install/bin:$PATH" quiet_popd run cmake --version +# ----------------------------------------------------------------------- + header "Patching Musl" echo -n "Patching Musl for locale support... " @@ -270,6 +274,14 @@ fi # ----------------------------------------------------------------------- +header "Patching BoringSSL" + +echo -n "Patching BoringSSL to disable -Werror... " +sed -i.bak "s/-Werror //g" ${source_dir}/boringssl/CMakeLists.txt +echo "done" + +# ----------------------------------------------------------------------- + header "Building clang for host" mkdir -p ${build_dir}/host/clang ${build_dir}/clang