]> git.lizzy.rs Git - rust.git/blob - src/ci/scripts/install-clang.sh
Auto merge of #98866 - nagisa:nagisa/align-offset-wroom, r=Mark-Simulacrum
[rust.git] / src / ci / scripts / install-clang.sh
1 #!/bin/bash
2 # ignore-tidy-linelength
3 # This script installs clang on the local machine. Note that we don't install
4 # clang on Linux since its compiler story is just so different. Each container
5 # has its own toolchain configured appropriately already.
6
7 set -euo pipefail
8 IFS=$'\n\t'
9
10 source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
11
12 # Update both macOS's and Windows's tarballs when bumping the version here.
13 LLVM_VERSION="14.0.5"
14
15 if isMacOS; then
16     # If the job selects a specific Xcode version, use that instead of
17     # downloading our own version.
18     if [[ ${USE_XCODE_CLANG-0} -eq 1 ]]; then
19         bindir="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/usr/bin"
20     else
21         file="${MIRRORS_BASE}/clang%2Bllvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
22         retry curl -f "${file}" -o "clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
23         tar xJf "clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz"
24         bindir="$(pwd)/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin/bin"
25     fi
26
27     ciCommandSetEnv CC "${bindir}/clang"
28     ciCommandSetEnv CXX "${bindir}/clang++"
29
30     # macOS 10.15 onwards doesn't have libraries in /usr/include anymore: those
31     # are now located deep into the filesystem, under Xcode's own files. The
32     # native clang is configured to use the correct path, but our custom one
33     # doesn't. This sets the SDKROOT environment variable to the SDK so that
34     # our own clang can figure out the correct include path on its own.
35     ciCommandSetEnv SDKROOT "$(xcrun --sdk macosx --show-sdk-path)"
36
37     # Configure `AR` specifically so rustbuild doesn't try to infer it as
38     # `clang-ar` by accident.
39     ciCommandSetEnv AR "ar"
40 elif isWindows && [[ ${CUSTOM_MINGW-0} -ne 1 ]]; then
41
42     if [[ ${WINDOWS_SDK_20348_HACK-0} -eq 1 ]]; then
43         rm -rf '/c/Program Files (x86)/Windows Kits/10/include/10.0.20348.0'
44         mv '/c/Program Files (x86)/Windows Kits/10/include/'10.0.{19041,20348}.0
45     fi
46
47     # If we're compiling for MSVC then we, like most other distribution builders,
48     # switch to clang as the compiler. This'll allow us eventually to enable LTO
49     # amongst LLVM and rustc. Note that we only do this on MSVC as I don't think
50     # clang has an output mode compatible with MinGW that we need. If it does we
51     # should switch to clang for MinGW as well!
52     #
53     # The LLVM installer is an NSIS installer, which we can extract with 7z. We
54     # don't want to run the installer directly; extracting it is more reliable
55     # in CI environments.
56
57     mkdir -p citools/clang-rust
58     cd citools
59     retry curl -f "${MIRRORS_BASE}/LLVM-${LLVM_VERSION}-win64.exe" \
60         -o "LLVM-${LLVM_VERSION}-win64.exe"
61     7z x -oclang-rust/ "LLVM-${LLVM_VERSION}-win64.exe"
62     ciCommandSetEnv RUST_CONFIGURE_ARGS \
63         "${RUST_CONFIGURE_ARGS} --set llvm.clang-cl=$(pwd)/clang-rust/bin/clang-cl.exe"
64 fi
65
66 if isWindows; then
67     # GitHub image 20210928.2 added LLVM, but it is broken (and we don't want
68     # to use it anyways).
69     rm -rf /c/Program\ Files/LLVM
70 fi