Skip to content

Commit 75210db

Browse files
authored
[Static SDK] Build clang before running the main build. (#501)
* [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). * [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.
1 parent 2b8f410 commit 75210db

File tree

1 file changed

+49
-6
lines changed
  • swift-ci/sdks/static-linux/scripts

1 file changed

+49
-6
lines changed

swift-ci/sdks/static-linux/scripts/build.sh

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ function run() {
239239
"$@"
240240
}
241241

242+
# -----------------------------------------------------------------------
243+
242244
header "Building CMake from source"
243245

244246
quiet_pushd ${source_dir}/swift-project/cmake
@@ -255,6 +257,8 @@ run export PATH="${build_dir}/cmake/install/bin:$PATH"
255257
quiet_popd
256258
run cmake --version
257259

260+
# -----------------------------------------------------------------------
261+
258262
header "Patching Musl"
259263

260264
echo -n "Patching Musl for locale support... "
@@ -268,6 +272,45 @@ else
268272
exit 1
269273
fi
270274

275+
# -----------------------------------------------------------------------
276+
277+
header "Patching BoringSSL"
278+
279+
echo -n "Patching BoringSSL to disable -Werror... "
280+
sed -i.bak "s/-Werror //g" ${source_dir}/boringssl/CMakeLists.txt
281+
echo "done"
282+
283+
# -----------------------------------------------------------------------
284+
285+
header "Building clang for host"
286+
287+
mkdir -p ${build_dir}/host/clang ${build_dir}/clang
288+
289+
run cmake -G Ninja -S ${source_dir}/swift-project/llvm-project/llvm \
290+
-B ${build_dir}/host/clang \
291+
-DCMAKE_BUILD_TYPE=Release \
292+
-DLLVM_ENABLE_PROJECTS="clang" \
293+
-DLLVM_PARALLEL_LINK_JOBS=1 \
294+
-DCMAKE_INSTALL_PREFIX=${build_dir}/clang
295+
296+
quiet_pushd ${build_dir}/host/clang
297+
run ninja -j$parallel_jobs
298+
quiet_popd
299+
300+
header "Installing clang for host"
301+
302+
quiet_pushd ${build_dir}/host/clang
303+
run ninja -j$parallel_jobs install
304+
quiet_popd
305+
306+
clang_dir=${build_dir}/clang
307+
308+
header "Clang version"
309+
310+
${clang_dir}/bin/clang --version
311+
312+
# -----------------------------------------------------------------------
313+
271314
for arch in $archs; do
272315

273316
# Fix architecture names
@@ -288,11 +331,11 @@ for arch in $archs; do
288331
"${sdk_root}/usr/lib/swift_static"
289332
ln -sf ../swift/clang "${sdk_root}/usr/lib/swift_static/clang"
290333

291-
clang_resource_dir=$(${swift_dir}/bin/clang -print-resource-dir)
334+
clang_resource_dir=$(${clang_dir}/bin/clang -print-resource-dir)
292335
cp -rT $clang_resource_dir/include $sdk_resource_dir/include
293336

294-
cc="${swift_dir}/bin/clang -target $triple -resource-dir ${sdk_resource_dir} --sysroot ${sdk_root}"
295-
cxx="${swift_dir}/bin/clang++ -target $triple -resource-dir ${sdk_resource_dir} --sysroot ${sdk_root} -stdlib=libc++ -unwindlib=libunwind"
337+
cc="${clang_dir}/bin/clang -target $triple -resource-dir ${sdk_resource_dir} --sysroot ${sdk_root}"
338+
cxx="${clang_dir}/bin/clang++ -target $triple -resource-dir ${sdk_resource_dir} --sysroot ${sdk_root} -stdlib=libc++ -unwindlib=libunwind"
296339
as="$cc"
297340

298341
# Creating this gets rid of a warning
@@ -406,9 +449,9 @@ set(CMAKE_SYSROOT ${sdk_root})
406449
set(CMAKE_CROSSCOMPILING=YES)
407450
set(CMAKE_EXE_LINKER_FLAGS "-unwindlib=libunwind -rtlib=compiler-rt -stdlib=libc++ -fuse-ld=lld -lc++ -lc++abi")
408451
409-
set(CMAKE_C_COMPILER ${swift_dir}/bin/clang -resource-dir ${sdk_resource_dir})
410-
set(CMAKE_CXX_COMPILER ${swift_dir}/bin/clang++ -resource-dir ${sdk_resource_dir} -stdlib=libc++)
411-
set(CMAKE_ASM_COMPILER ${swift_dir}/bin/clang -resource-dir ${sdk_resource_dir})
452+
set(CMAKE_C_COMPILER ${clang_dir}/bin/clang -resource-dir ${sdk_resource_dir})
453+
set(CMAKE_CXX_COMPILER ${clang_dir}/bin/clang++ -resource-dir ${sdk_resource_dir} -stdlib=libc++)
454+
set(CMAKE_ASM_COMPILER ${clang_dir}/bin/clang -resource-dir ${sdk_resource_dir})
412455
set(CMAKE_FIND_ROOT_PATH ${sdk_root})
413456
EOF
414457

0 commit comments

Comments
 (0)