]> git.lizzy.rs Git - rust.git/blob - src/ci/scripts/install-clang.sh
Rollup merge of #75780 - matklad:unconfuseunpindocs, r=KodrAus
[rust.git] / src / ci / scripts / install-clang.sh
1 #!/bin/bash
2 # This script installs clang on the local machine. Note that we don't install
3 # clang on Linux since its compiler story is just so different. Each container
4 # has its own toolchain configured appropriately already.
5
6 set -euo pipefail
7 IFS=$'\n\t'
8
9 source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
10
11 # Update both macOS's and Windows's tarballs when bumping the version here.
12 LLVM_VERSION="10.0.0"
13
14 if isMacOS; then
15     curl -f "${MIRRORS_BASE}/clang%2Bllvm-${LLVM_VERSION}-x86_64-apple-darwin.tar.xz" | tar xJf -
16
17     ciCommandSetEnv CC "$(pwd)/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin/bin/clang"
18     ciCommandSetEnv CXX "$(pwd)/clang+llvm-${LLVM_VERSION}-x86_64-apple-darwin/bin/clang++"
19
20     # macOS 10.15 onwards doesn't have libraries in /usr/include anymore: those
21     # are now located deep into the filesystem, under Xcode's own files. The
22     # native clang is configured to use the correct path, but our custom one
23     # doesn't. This sets the SDKROOT environment variable to the SDK so that
24     # our own clang can figure out the correct include path on its own.
25     ciCommandSetEnv SDKROOT "$(xcrun --sdk macosx --show-sdk-path)"
26
27     # Configure `AR` specifically so rustbuild doesn't try to infer it as
28     # `clang-ar` by accident.
29     ciCommandSetEnv AR "ar"
30 elif isWindows && [[ ${CUSTOM_MINGW-0} -ne 1 ]]; then
31     # If we're compiling for MSVC then we, like most other distribution builders,
32     # switch to clang as the compiler. This'll allow us eventually to enable LTO
33     # amongst LLVM and rustc. Note that we only do this on MSVC as I don't think
34     # clang has an output mode compatible with MinGW that we need. If it does we
35     # should switch to clang for MinGW as well!
36     #
37     # Note that the LLVM installer is an NSIS installer
38     #
39     # Original downloaded here came from:
40     #
41     #   https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/LLVM-10.0.0-win64.exe
42     #
43     # That installer was run through `wine ./installer.exe /S /NCRC` on Linux
44     # and then the resulting installation directory (found in
45     # `$HOME/.wine/drive_c/Program Files/LLVM`) was packaged up into a tarball.
46     # We've had issues otherwise that the installer will randomly hang, provide
47     # not a lot of useful information, pollute global state, etc. In general the
48     # tarball is just more confined and easier to deal with when working with
49     # various CI environments.
50
51     mkdir -p citools
52     cd citools
53     curl -f "${MIRRORS_BASE}/LLVM-${LLVM_VERSION}-win64.tar.gz" | tar xzf -
54     ciCommandSetEnv RUST_CONFIGURE_ARGS \
55         "${RUST_CONFIGURE_ARGS} --set llvm.clang-cl=$(pwd)/clang-rust/bin/clang-cl.exe"
56 fi