Skip to content

Commit 7e5b9ac

Browse files
committed
ci: Compile LLVM with Clang 6.0.0
Currently on CI we predominately compile LLVM with the default system compiler which means gcc on Linux, some version of Clang on OSX, MSVC on Windows, and gcc on MinGW. This commit switches Linux, OSX, and Windows to all use Clang 6.0.0 to build LLVM (aka the C/C++ compiler as part of the bootstrap). This looks to generate faster code according to #49879 which translates to a faster rustc (as LLVM internally is faster) The major changes here were to the containers that build Linux releases, basically adding a new step that uses the previous gcc 4.8 compiler to compile the next Clang 6.0.0 compiler. Otherwise the OSX and Windows scripts have been updated to download precompiled versions of Clang 6 and configure the build to use them. Note that `cc` was updated here to fix using `clang-cl` with `cc-rs` on MSVC, as well as an update to `sccache` on Windows which was needed to correctly work with `clang-cl`. Finally the MinGW compiler is entirely left out here intentionally as it's currently thought that Clang can't generate C++ code for MinGW and we need to use gcc, but this should be verified eventually.
1 parent ac287ed commit 7e5b9ac

24 files changed

+267
-337
lines changed

.travis.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ install:
230230
travis_retry curl -fo /usr/local/bin/sccache https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/2018-04-02-sccache-x86_64-apple-darwin &&
231231
chmod +x /usr/local/bin/sccache &&
232232
travis_retry curl -fo /usr/local/bin/stamp https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/2017-03-17-stamp-x86_64-apple-darwin &&
233-
chmod +x /usr/local/bin/stamp
233+
chmod +x /usr/local/bin/stamp &&
234+
travis_retry curl -f http://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-apple-darwin.tar.xz | tar xJf - &&
235+
export CC=`pwd`/clang+llvm-6.0.0-x86_64-apple-darwin/bin/clang &&
236+
export CXX=`pwd`/clang+llvm-6.0.0-x86_64-apple-darwin/bin/clang++ &&
237+
export AR=ar
234238
;;
235239
esac
236240

appveyor.yml

+16-2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ install:
138138
- if defined MINGW_URL 7z x -y %MINGW_ARCHIVE% > nul
139139
- if defined MINGW_URL set PATH=%CD%\%MINGW_DIR%\bin;C:\msys64\usr\bin;%PATH%
140140

141+
# If we're compiling for MSVC then we, like most other distribution builders,
142+
# switch to clang as the compiler. This'll allow us eventually to enable LTO
143+
# amongst LLVM and rustc. Note that we only do this on MSVC as I don't think
144+
# clang has an output mode compatible with MinGW that we need. If it does we
145+
# should switch to clang for MinGW as well!
146+
#
147+
# Note that the LLVM installer is an NSIS installer
148+
#
149+
# Original downloaded here came from
150+
# http://releases.llvm.org/6.0.0/LLVM-6.0.0-win64.exe
151+
- if NOT defined MINGW_URL appveyor-retry appveyor DownloadFile https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/LLVM-6.0.0-win64.exe
152+
- if NOT defined MINGW_URL .\LLVM-6.0.0-win64.exe /S /NCRC /D=C:\clang-rust
153+
- if NOT defined MINGW_URL set RUST_CONFIGURE_ARGS=%RUST_CONFIGURE_ARGS% --set llvm.clang-cl=C:\clang-rust\bin\clang-cl.exe
154+
141155
# Here we do a pretty heinous thing which is to mangle the MinGW installation
142156
# we just had above. Currently, as of this writing, we're using MinGW-w64
143157
# builds of gcc, and that's currently at 6.3.0. We use 6.3.0 as it appears to
@@ -166,8 +180,8 @@ install:
166180
- set PATH=C:\Python27;%PATH%
167181

168182
# Download and install sccache
169-
- appveyor-retry appveyor DownloadFile https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/2018-04-02-sccache-x86_64-pc-windows-msvc
170-
- mv 2018-04-02-sccache-x86_64-pc-windows-msvc sccache.exe
183+
- appveyor-retry appveyor DownloadFile https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/2018-04-26-sccache-x86_64-pc-windows-msvc
184+
- mv 2018-04-26-sccache-x86_64-pc-windows-msvc sccache.exe
171185
- set PATH=%PATH%;%CD%
172186

173187
# Download and install ninja

config.toml.example

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
# passed to prefer linking to shared libraries.
7777
#link-shared = false
7878

79+
# On MSVC you can compile LLVM with clang-cl, but the test suite doesn't pass
80+
# with clang-cl, so this is special in that it only compiles LLVM with clang-cl
81+
#clang-cl = '/path/to/clang-cl.exe'
82+
7983
# =============================================================================
8084
# General build configuration options
8185
# =============================================================================

src/Cargo.lock

+20-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ name = "sccache-plus-cl"
2828
path = "bin/sccache-plus-cl.rs"
2929
test = false
3030

31+
[[bin]]
32+
name = "llvm-config-wrapper"
33+
path = "bin/llvm-config-wrapper.rs"
34+
test = false
35+
3136
[dependencies]
3237
build_helper = { path = "../build_helper" }
3338
cmake = "0.1.23"
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// The sheer existence of this file is an awful hack. See the comments in
12+
// `src/bootstrap/native.rs` for why this is needed when compiling LLD.
13+
14+
use std::env;
15+
use std::process::{self, Stdio, Command};
16+
use std::io::{self, Write};
17+
18+
fn main() {
19+
let real_llvm_config = env::var_os("LLVM_CONFIG_REAL").unwrap();
20+
let mut cmd = Command::new(real_llvm_config);
21+
cmd.args(env::args().skip(1)).stderr(Stdio::piped());
22+
let output = cmd.output().expect("failed to spawn llvm-config");
23+
let stdout = String::from_utf8_lossy(&output.stdout);
24+
print!("{}", stdout.replace("\\", "/"));
25+
io::stdout().flush().unwrap();
26+
process::exit(output.status.code().unwrap_or(1));
27+
}

src/bootstrap/bin/sccache-plus-cl.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use std::process::{self, Command};
1616
fn main() {
1717
let target = env::var("SCCACHE_TARGET").unwrap();
1818
// Locate the actual compiler that we're invoking
19-
env::remove_var("CC");
20-
env::remove_var("CXX");
19+
env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
20+
env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
2121
let mut cfg = cc::Build::new();
2222
cfg.cargo_metadata(false)
2323
.out_dir("/")
@@ -39,6 +39,12 @@ fn main() {
3939
cmd.arg(arg);
4040
}
4141

42+
if let Ok(s) = env::var("SCCACHE_EXTRA_ARGS") {
43+
for s in s.split_whitespace() {
44+
cmd.arg(s);
45+
}
46+
}
47+
4248
let status = cmd.status().expect("failed to spawn");
4349
process::exit(status.code().unwrap_or(2))
4450
}

src/bootstrap/builder.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,11 @@ impl<'a> Builder<'a> {
726726
// the options through environment variables that are fetched and understood by both.
727727
//
728728
// FIXME: the guard against msvc shouldn't need to be here
729-
if !target.contains("msvc") {
729+
if target.contains("msvc") {
730+
if let Some(ref cl) = self.config.llvm_clang_cl {
731+
cargo.env("CC", cl).env("CXX", cl);
732+
}
733+
} else {
730734
let ccache = self.config.ccache.as_ref();
731735
let ccacheify = |s: &Path| {
732736
let ccache = match ccache {

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub struct Config {
8282
pub llvm_version_check: bool,
8383
pub llvm_static_stdcpp: bool,
8484
pub llvm_link_shared: bool,
85+
pub llvm_clang_cl: Option<String>,
8586
pub llvm_targets: Option<String>,
8687
pub llvm_experimental_targets: String,
8788
pub llvm_link_jobs: Option<u32>,
@@ -250,6 +251,7 @@ struct Llvm {
250251
experimental_targets: Option<String>,
251252
link_jobs: Option<u32>,
252253
link_shared: Option<bool>,
254+
clang_cl: Option<String>
253255
}
254256

255257
#[derive(Deserialize, Default, Clone)]
@@ -504,6 +506,7 @@ impl Config {
504506
config.llvm_experimental_targets = llvm.experimental_targets.clone()
505507
.unwrap_or("WebAssembly".to_string());
506508
config.llvm_link_jobs = llvm.link_jobs;
509+
config.llvm_clang_cl = llvm.clang_cl.clone();
507510
}
508511

509512
if let Some(ref rust) = toml.rust {

0 commit comments

Comments
 (0)