Skip to content

Commit 2a1af97

Browse files
committed
Auto merge of #50200 - alexcrichton:compile-with-clang, r=kennytm
Compile LLVM with Clang on release builders Attempting to cache in on some rustc compile time wins mentioned in #49879 (comment)
2 parents 95d0b9e + 7e5b9ac commit 2a1af97

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
@@ -751,7 +751,11 @@ impl<'a> Builder<'a> {
751751
// the options through environment variables that are fetched and understood by both.
752752
//
753753
// FIXME: the guard against msvc shouldn't need to be here
754-
if !target.contains("msvc") {
754+
if target.contains("msvc") {
755+
if let Some(ref cl) = self.config.llvm_clang_cl {
756+
cargo.env("CC", cl).env("CXX", cl);
757+
}
758+
} else {
755759
let ccache = self.config.ccache.as_ref();
756760
let ccacheify = |s: &Path| {
757761
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)