about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-05-10 10:30:02 +0000
committerbors <bors@rust-lang.org>2018-05-10 10:30:02 +0000
commit57dc98434eb818733dbc941405fdee59e5c3a023 (patch)
tree4b76049ca5ef8fb2e8f600599f407121e49676d0
parentc8a3ec1ce6dc12f86de39bf5ac55fc2fa38358f8 (diff)
parent7e5b9ac41e36b29d5208f4e5455aade07d4d107d (diff)
downloadrust-57dc98434eb818733dbc941405fdee59e5c3a023.tar.gz
rust-57dc98434eb818733dbc941405fdee59e5c3a023.zip
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 https://github.com/rust-lang/rust/issues/49879#issuecomment-383602941
-rw-r--r--.travis.yml6
-rw-r--r--appveyor.yml18
-rw-r--r--config.toml.example4
-rw-r--r--src/Cargo.lock40
-rw-r--r--src/bootstrap/Cargo.toml5
-rw-r--r--src/bootstrap/bin/llvm-config-wrapper.rs27
-rw-r--r--src/bootstrap/bin/sccache-plus-cl.rs10
-rw-r--r--src/bootstrap/builder.rs6
-rw-r--r--src/bootstrap/config.rs3
-rw-r--r--src/bootstrap/native.rs68
-rw-r--r--src/ci/docker/dist-i686-linux/Dockerfile49
-rwxr-xr-xsrc/ci/docker/dist-i686-linux/build-binutils.sh26
-rwxr-xr-xsrc/ci/docker/dist-i686-linux/build-cmake.sh25
-rwxr-xr-xsrc/ci/docker/dist-i686-linux/build-curl.sh43
-rwxr-xr-xsrc/ci/docker/dist-i686-linux/build-gcc.sh50
-rwxr-xr-xsrc/ci/docker/dist-i686-linux/build-git.sh24
-rwxr-xr-xsrc/ci/docker/dist-i686-linux/build-headers.sh25
-rwxr-xr-xsrc/ci/docker/dist-i686-linux/build-openssl.sh28
-rwxr-xr-xsrc/ci/docker/dist-i686-linux/build-python.sh30
-rw-r--r--src/ci/docker/dist-i686-linux/shared.sh25
-rw-r--r--src/ci/docker/dist-x86_64-linux/Dockerfile25
-rwxr-xr-xsrc/ci/docker/dist-x86_64-linux/build-clang.sh64
-rwxr-xr-xsrc/ci/docker/dist-x86_64-linux/build-gcc.sh1
m---------src/llvm0
24 files changed, 266 insertions, 336 deletions
diff --git a/.travis.yml b/.travis.yml
index 63831cd5961..23c47bc9f76 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -230,7 +230,11 @@ install:
           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 &&
             chmod +x /usr/local/bin/sccache &&
           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 &&
-            chmod +x /usr/local/bin/stamp
+            chmod +x /usr/local/bin/stamp &&
+          travis_retry curl -f http://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-apple-darwin.tar.xz | tar xJf - &&
+            export CC=`pwd`/clang+llvm-6.0.0-x86_64-apple-darwin/bin/clang &&
+            export CXX=`pwd`/clang+llvm-6.0.0-x86_64-apple-darwin/bin/clang++ &&
+            export AR=ar
           ;;
     esac
 
diff --git a/appveyor.yml b/appveyor.yml
index a15f3dd8d5c..a92f4a17811 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -138,6 +138,20 @@ install:
   - if defined MINGW_URL 7z x -y %MINGW_ARCHIVE% > nul
   - if defined MINGW_URL set PATH=%CD%\%MINGW_DIR%\bin;C:\msys64\usr\bin;%PATH%
 
+  # If we're compiling for MSVC then we, like most other distribution builders,
+  # switch to clang as the compiler. This'll allow us eventually to enable LTO
+  # amongst LLVM and rustc. Note that we only do this on MSVC as I don't think
+  # clang has an output mode compatible with MinGW that we need. If it does we
+  # should switch to clang for MinGW as well!
+  #
+  # Note that the LLVM installer is an NSIS installer
+  #
+  # Original downloaded here came from
+  # http://releases.llvm.org/6.0.0/LLVM-6.0.0-win64.exe
+  - 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
+  - if NOT defined MINGW_URL .\LLVM-6.0.0-win64.exe /S /NCRC /D=C:\clang-rust
+  - if NOT defined MINGW_URL set RUST_CONFIGURE_ARGS=%RUST_CONFIGURE_ARGS% --set llvm.clang-cl=C:\clang-rust\bin\clang-cl.exe
+
   # Here we do a pretty heinous thing which is to mangle the MinGW installation
   # we just had above. Currently, as of this writing, we're using MinGW-w64
   # 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:
   - set PATH=C:\Python27;%PATH%
 
   # Download and install sccache
-  - 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
-  - mv 2018-04-02-sccache-x86_64-pc-windows-msvc sccache.exe
+  - 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
+  - mv 2018-04-26-sccache-x86_64-pc-windows-msvc sccache.exe
   - set PATH=%PATH%;%CD%
 
   # Download and install ninja
diff --git a/config.toml.example b/config.toml.example
index 34fcc755b3a..33ad9147ce0 100644
--- a/config.toml.example
+++ b/config.toml.example
@@ -76,6 +76,10 @@
 # passed to prefer linking to shared libraries.
 #link-shared = false
 
+# On MSVC you can compile LLVM with clang-cl, but the test suite doesn't pass
+# with clang-cl, so this is special in that it only compiles LLVM with clang-cl
+#clang-cl = '/path/to/clang-cl.exe'
+
 # =============================================================================
 # General build configuration options
 # =============================================================================
diff --git a/src/Cargo.lock b/src/Cargo.lock
index 21c35458398..e2a9a6efbda 100644
--- a/src/Cargo.lock
+++ b/src/Cargo.lock
@@ -20,7 +20,7 @@ name = "alloc_jemalloc"
 version = "0.0.0"
 dependencies = [
  "build_helper 0.1.0",
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "compiler_builtins 0.0.0",
  "core 0.0.0",
  "libc 0.0.0",
@@ -117,7 +117,7 @@ name = "backtrace-sys"
 version = "0.1.16"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -145,7 +145,7 @@ name = "bootstrap"
 version = "0.0.0"
 dependencies = [
  "build_helper 0.1.0",
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "cmake 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
  "filetime 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -270,7 +270,7 @@ version = "0.1.0"
 
 [[package]]
 name = "cc"
-version = "1.0.10"
+version = "1.0.15"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
@@ -348,7 +348,7 @@ name = "cmake"
 version = "0.1.30"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -379,7 +379,7 @@ dependencies = [
 name = "compiler_builtins"
 version = "0.0.0"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "core 0.0.0",
 ]
 
@@ -513,7 +513,7 @@ name = "curl"
 version = "0.4.12"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "curl-sys 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "curl-sys 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -525,10 +525,10 @@ dependencies = [
 
 [[package]]
 name = "curl-sys"
-version = "0.4.2"
+version = "0.4.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
  "libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
  "openssl-sys 0.9.28 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1044,9 +1044,9 @@ name = "libgit2-sys"
 version = "0.7.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "cmake 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
- "curl-sys 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "curl-sys 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
  "libssh2-sys 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1071,7 +1071,7 @@ name = "libz-sys"
 version = "1.0.18"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
  "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
  "vcpkg 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1110,7 +1110,7 @@ name = "lzma-sys"
 version = "0.1.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "filetime 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
  "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1192,7 +1192,7 @@ name = "miniz-sys"
 version = "0.1.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -1288,7 +1288,7 @@ name = "openssl-sys"
 version = "0.9.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
  "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
  "vcpkg 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1459,7 +1459,7 @@ dependencies = [
 name = "profiler_builtins"
 version = "0.0.0"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "compiler_builtins 0.0.0",
  "core 0.0.0",
 ]
@@ -1988,7 +1988,7 @@ version = "0.0.0"
 dependencies = [
  "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "build_helper 0.1.0",
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc_cratesio_shim 0.0.0",
 ]
@@ -2149,7 +2149,7 @@ dependencies = [
 name = "rustc_trans"
 version = "0.0.0"
 dependencies = [
- "cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "env_logger 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "jobserver 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3014,7 +3014,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87"
 "checksum cargo_metadata 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1f56ec3e469bca7c276f2eea015aa05c5e381356febdbb0683c2580189604537"
 "checksum cargo_metadata 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ebd6272a2ca4fd39dbabbd6611eb03df45c2259b3b80b39a9ff8fbdcf42a4b3"
-"checksum cc 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8b9d2900f78631a5876dc5d6c9033ede027253efcd33dd36b1309fc6cab97ee0"
+"checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba"
 "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
 "checksum chrono 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ba5f60682a4c264e7f8d77b82e7788938a76befdf949d4a98026d19099c9d873"
 "checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536"
@@ -3031,7 +3031,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
 "checksum crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09de9ee0fc255ace04c7fa0763c9395a945c37c8292bb554f8d48361d1dcf1b4"
 "checksum curl 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "aaf20bbe084f285f215eef2165feed70d6b75ba29cad24469badb853a4a287d0"
-"checksum curl-sys 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f3f7738d877ec81040305d5bb91976ac594f564f5e455dc02a29a23c1d00fe6f"
+"checksum curl-sys 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71c63a540a9ee4e15e56c3ed9b11a2f121239b9f6d7b7fe30f616e048148df9a"
 "checksum debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9a032eac705ca39214d169f83e3d3da290af06d8d1d344d1baad2fd002dca4b3"
 "checksum derive-new 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fcb923bab47a948f1b01cec2f758fdebba95c9ebc255458654b2b88efe59d71"
 "checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a"
diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml
index 2f9c4e148a6..af33ebf3c42 100644
--- a/src/bootstrap/Cargo.toml
+++ b/src/bootstrap/Cargo.toml
@@ -28,6 +28,11 @@ name = "sccache-plus-cl"
 path = "bin/sccache-plus-cl.rs"
 test = false
 
+[[bin]]
+name = "llvm-config-wrapper"
+path = "bin/llvm-config-wrapper.rs"
+test = false
+
 [dependencies]
 build_helper = { path = "../build_helper" }
 cmake = "0.1.23"
diff --git a/src/bootstrap/bin/llvm-config-wrapper.rs b/src/bootstrap/bin/llvm-config-wrapper.rs
new file mode 100644
index 00000000000..b1703f8c728
--- /dev/null
+++ b/src/bootstrap/bin/llvm-config-wrapper.rs
@@ -0,0 +1,27 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// The sheer existence of this file is an awful hack. See the comments in
+// `src/bootstrap/native.rs` for why this is needed when compiling LLD.
+
+use std::env;
+use std::process::{self, Stdio, Command};
+use std::io::{self, Write};
+
+fn main() {
+    let real_llvm_config = env::var_os("LLVM_CONFIG_REAL").unwrap();
+    let mut cmd = Command::new(real_llvm_config);
+    cmd.args(env::args().skip(1)).stderr(Stdio::piped());
+    let output = cmd.output().expect("failed to spawn llvm-config");
+    let stdout = String::from_utf8_lossy(&output.stdout);
+    print!("{}", stdout.replace("\\", "/"));
+    io::stdout().flush().unwrap();
+    process::exit(output.status.code().unwrap_or(1));
+}
diff --git a/src/bootstrap/bin/sccache-plus-cl.rs b/src/bootstrap/bin/sccache-plus-cl.rs
index 8584014d48d..0a20ac7e492 100644
--- a/src/bootstrap/bin/sccache-plus-cl.rs
+++ b/src/bootstrap/bin/sccache-plus-cl.rs
@@ -16,8 +16,8 @@ use std::process::{self, Command};
 fn main() {
     let target = env::var("SCCACHE_TARGET").unwrap();
     // Locate the actual compiler that we're invoking
-    env::remove_var("CC");
-    env::remove_var("CXX");
+    env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
+    env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
     let mut cfg = cc::Build::new();
     cfg.cargo_metadata(false)
        .out_dir("/")
@@ -39,6 +39,12 @@ fn main() {
         cmd.arg(arg);
     }
 
+    if let Ok(s) = env::var("SCCACHE_EXTRA_ARGS") {
+        for s in s.split_whitespace() {
+            cmd.arg(s);
+        }
+    }
+
     let status = cmd.status().expect("failed to spawn");
     process::exit(status.code().unwrap_or(2))
 }
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 701313d8082..f87436504c6 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -751,7 +751,11 @@ impl<'a> Builder<'a> {
         // the options through environment variables that are fetched and understood by both.
         //
         // FIXME: the guard against msvc shouldn't need to be here
-        if !target.contains("msvc") {
+        if target.contains("msvc") {
+            if let Some(ref cl) = self.config.llvm_clang_cl {
+                cargo.env("CC", cl).env("CXX", cl);
+            }
+        } else {
             let ccache = self.config.ccache.as_ref();
             let ccacheify = |s: &Path| {
                 let ccache = match ccache {
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
index 6dd6291be23..9840682d137 100644
--- a/src/bootstrap/config.rs
+++ b/src/bootstrap/config.rs
@@ -82,6 +82,7 @@ pub struct Config {
     pub llvm_version_check: bool,
     pub llvm_static_stdcpp: bool,
     pub llvm_link_shared: bool,
+    pub llvm_clang_cl: Option<String>,
     pub llvm_targets: Option<String>,
     pub llvm_experimental_targets: String,
     pub llvm_link_jobs: Option<u32>,
@@ -250,6 +251,7 @@ struct Llvm {
     experimental_targets: Option<String>,
     link_jobs: Option<u32>,
     link_shared: Option<bool>,
+    clang_cl: Option<String>
 }
 
 #[derive(Deserialize, Default, Clone)]
@@ -504,6 +506,7 @@ impl Config {
             config.llvm_experimental_targets = llvm.experimental_targets.clone()
                 .unwrap_or("WebAssembly".to_string());
             config.llvm_link_jobs = llvm.link_jobs;
+            config.llvm_clang_cl = llvm.clang_cl.clone();
         }
 
         if let Some(ref rust) = toml.rust {
diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs
index d952cb5bfc4..002044050f3 100644
--- a/src/bootstrap/native.rs
+++ b/src/bootstrap/native.rs
@@ -275,21 +275,53 @@ fn configure_cmake(builder: &Builder,
         return
     }
 
-    let cc = builder.cc(target);
-    let cxx = builder.cxx(target).unwrap();
+    let (cc, cxx) = match builder.config.llvm_clang_cl {
+        Some(ref cl) => (cl.as_ref(), cl.as_ref()),
+        None => (builder.cc(target), builder.cxx(target).unwrap()),
+    };
 
     // Handle msvc + ninja + ccache specially (this is what the bots use)
     if target.contains("msvc") &&
        builder.config.ninja &&
-       builder.config.ccache.is_some() {
-        let mut cc = env::current_exe().expect("failed to get cwd");
-        cc.set_file_name("sccache-plus-cl.exe");
+       builder.config.ccache.is_some()
+    {
+       let mut wrap_cc = env::current_exe().expect("failed to get cwd");
+       wrap_cc.set_file_name("sccache-plus-cl.exe");
 
-       cfg.define("CMAKE_C_COMPILER", sanitize_cc(&cc))
-          .define("CMAKE_CXX_COMPILER", sanitize_cc(&cc));
+       cfg.define("CMAKE_C_COMPILER", sanitize_cc(&wrap_cc))
+          .define("CMAKE_CXX_COMPILER", sanitize_cc(&wrap_cc));
        cfg.env("SCCACHE_PATH",
                builder.config.ccache.as_ref().unwrap())
-          .env("SCCACHE_TARGET", target);
+          .env("SCCACHE_TARGET", target)
+          .env("SCCACHE_CC", &cc)
+          .env("SCCACHE_CXX", &cxx);
+
+       // Building LLVM on MSVC can be a little ludicrous at times. We're so far
+       // off the beaten path here that I'm not really sure this is even half
+       // supported any more. Here we're trying to:
+       //
+       // * Build LLVM on MSVC
+       // * Build LLVM with `clang-cl` instead of `cl.exe`
+       // * Build a project with `sccache`
+       // * Build for 32-bit as well
+       // * Build with Ninja
+       //
+       // For `cl.exe` there are different binaries to compile 32/64 bit which
+       // we use but for `clang-cl` there's only one which internally
+       // multiplexes via flags. As a result it appears that CMake's detection
+       // of a compiler's architecture and such on MSVC **doesn't** pass any
+       // custom flags we pass in CMAKE_CXX_FLAGS below. This means that if we
+       // use `clang-cl.exe` it's always diagnosed as a 64-bit compiler which
+       // definitely causes problems since all the env vars are pointing to
+       // 32-bit libraries.
+       //
+       // To hack aroudn this... again... we pass an argument that's
+       // unconditionally passed in the sccache shim. This'll get CMake to
+       // correctly diagnose it's doing a 32-bit compilation and LLVM will
+       // internally configure itself appropriately.
+       if builder.config.llvm_clang_cl.is_some() && target.contains("i686") {
+           cfg.env("SCCACHE_EXTRA_ARGS", "-m32");
+       }
 
     // If ccache is configured we inform the build a little differently hwo
     // to invoke ccache while also invoking our compilers.
@@ -368,9 +400,27 @@ impl Step for Lld {
         let mut cfg = cmake::Config::new(builder.src.join("src/tools/lld"));
         configure_cmake(builder, target, &mut cfg, true);
 
+        // This is an awful, awful hack. Discovered when we migrated to using
+        // clang-cl to compile LLVM/LLD it turns out that LLD, when built out of
+        // tree, will execute `llvm-config --cmakedir` and then tell CMake about
+        // that directory for later processing. Unfortunately if this path has
+        // forward slashes in it (which it basically always does on Windows)
+        // then CMake will hit a syntax error later on as... something isn't
+        // escaped it seems?
+        //
+        // Instead of attempting to fix this problem in upstream CMake and/or
+        // LLVM/LLD we just hack around it here. This thin wrapper will take the
+        // output from llvm-config and replace all instances of `\` with `/` to
+        // ensure we don't hit the same bugs with escaping. It means that you
+        // can't build on a system where your paths require `\` on Windows, but
+        // there's probably a lot of reasons you can't do that other than this.
+        let llvm_config_shim = env::current_exe()
+            .unwrap()
+            .with_file_name("llvm-config-wrapper");
         cfg.out_dir(&out_dir)
            .profile("Release")
-           .define("LLVM_CONFIG_PATH", llvm_config)
+           .env("LLVM_CONFIG_REAL", llvm_config)
+           .define("LLVM_CONFIG_PATH", llvm_config_shim)
            .define("LLVM_INCLUDE_TESTS", "OFF");
 
         cfg.build();
diff --git a/src/ci/docker/dist-i686-linux/Dockerfile b/src/ci/docker/dist-i686-linux/Dockerfile
index 0ec57ee0886..d591fb28f36 100644
--- a/src/ci/docker/dist-i686-linux/Dockerfile
+++ b/src/ci/docker/dist-i686-linux/Dockerfile
@@ -29,13 +29,13 @@ ENV PATH=/rustroot/bin:$PATH
 ENV LD_LIBRARY_PATH=/rustroot/lib64:/rustroot/lib
 ENV PKG_CONFIG_PATH=/rustroot/lib/pkgconfig
 WORKDIR /tmp
-COPY dist-i686-linux/shared.sh dist-i686-linux/build-binutils.sh /tmp/
+COPY dist-x86_64-linux/shared.sh /tmp/
 
 # We need a build of openssl which supports SNI to download artifacts from
 # static.rust-lang.org. This'll be used to link into libcurl below (and used
 # later as well), so build a copy of OpenSSL with dynamic libraries into our
 # generic root.
-COPY dist-i686-linux/build-openssl.sh /tmp/
+COPY dist-x86_64-linux/build-openssl.sh /tmp/
 RUN ./build-openssl.sh
 
 # The `curl` binary on CentOS doesn't support SNI which is needed for fetching
@@ -44,36 +44,43 @@ RUN ./build-openssl.sh
 #
 # Note that we also disable a bunch of optional features of curl that we don't
 # really need.
-COPY dist-i686-linux/build-curl.sh /tmp/
+COPY dist-x86_64-linux/build-curl.sh /tmp/
 RUN ./build-curl.sh
 
 # binutils < 2.22 has a bug where the 32-bit executables it generates
 # immediately segfault in Rust, so we need to install our own binutils.
 #
 # See https://github.com/rust-lang/rust/issues/20440 for more info
+COPY dist-x86_64-linux/build-binutils.sh /tmp/
 RUN ./build-binutils.sh
 
+# libssh2 (a dependency of Cargo) requires cmake 2.8.11 or higher but CentOS
+# only has 2.6.4, so build our own
+COPY dist-x86_64-linux/build-cmake.sh /tmp/
+RUN ./build-cmake.sh
+
 # Need a newer version of gcc than centos has to compile LLVM nowadays
-COPY dist-i686-linux/build-gcc.sh /tmp/
+COPY dist-x86_64-linux/build-gcc.sh /tmp/
 RUN ./build-gcc.sh
 
 # CentOS 5.5 has Python 2.4 by default, but LLVM needs 2.7+
-COPY dist-i686-linux/build-python.sh /tmp/
+COPY dist-x86_64-linux/build-python.sh /tmp/
 RUN ./build-python.sh
 
+# Now build LLVM+Clang 6, afterwards configuring further compilations to use the
+# clang/clang++ compilers.
+COPY dist-x86_64-linux/build-clang.sh /tmp/
+RUN ./build-clang.sh
+ENV CC=clang CXX=clang++
+
 # Apparently CentOS 5.5 desn't have `git` in yum, but we're gonna need it for
 # cloning, so download and build it here.
-COPY dist-i686-linux/build-git.sh /tmp/
+COPY dist-x86_64-linux/build-git.sh /tmp/
 RUN ./build-git.sh
 
-# libssh2 (a dependency of Cargo) requires cmake 2.8.11 or higher but CentOS
-# only has 2.6.4, so build our own
-COPY dist-i686-linux/build-cmake.sh /tmp/
-RUN ./build-cmake.sh
-
 # for sanitizers, we need kernel headers files newer than the ones CentOS ships
 # with so we install newer ones here
-COPY dist-i686-linux/build-headers.sh /tmp/
+COPY dist-x86_64-linux/build-headers.sh /tmp/
 RUN ./build-headers.sh
 
 COPY scripts/sccache.sh /scripts/
@@ -84,11 +91,21 @@ ENV HOSTS=i686-unknown-linux-gnu
 ENV RUST_CONFIGURE_ARGS \
       --enable-full-tools \
       --enable-sanitizers \
-      --enable-profiler
+      --enable-profiler \
+      --set target.i686-unknown-linux-gnu.linker=clang \
+      --build=i686-unknown-linux-gnu
 ENV SCRIPT python2.7 ../x.py dist --build $HOSTS --host $HOSTS --target $HOSTS
-
-# This is the only builder which will create source tarballs
-ENV DIST_SRC 1
+ENV CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER=clang
+
+# This was added when we switched from gcc to clang. It's not clear why this is
+# needed unfortunately, but without this the stage1 bootstrap segfaults
+# somewhere inside of a build script. The build ends up just hanging instead of
+# actually killing the process that segfaulted, but if the process is run
+# manually in a debugger the segfault is immediately seen as well as the
+# misaligned stack access.
+#
+# Added in #50200 there's some more logs there
+ENV CFLAGS -mstackrealign
 
 # When we build cargo in this container, we don't want it to use the system
 # libcurl, instead it should compile its own.
diff --git a/src/ci/docker/dist-i686-linux/build-binutils.sh b/src/ci/docker/dist-i686-linux/build-binutils.sh
deleted file mode 100755
index f4bdbd80d0e..00000000000
--- a/src/ci/docker/dist-i686-linux/build-binutils.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-# file at the top-level directory of this distribution and at
-# http://rust-lang.org/COPYRIGHT.
-#
-# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-# option. This file may not be copied, modified, or distributed
-# except according to those terms.
-
-set -ex
-
-source shared.sh
-
-curl https://ftp.gnu.org/gnu/binutils/binutils-2.25.1.tar.bz2 | tar xfj -
-
-mkdir binutils-build
-cd binutils-build
-hide_output ../binutils-2.25.1/configure --prefix=/rustroot
-hide_output make -j10
-hide_output make install
-
-cd ..
-rm -rf binutils-build
-rm -rf binutils-2.25.1
diff --git a/src/ci/docker/dist-i686-linux/build-cmake.sh b/src/ci/docker/dist-i686-linux/build-cmake.sh
deleted file mode 100755
index 9a3763d421a..00000000000
--- a/src/ci/docker/dist-i686-linux/build-cmake.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-# file at the top-level directory of this distribution and at
-# http://rust-lang.org/COPYRIGHT.
-#
-# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-# option. This file may not be copied, modified, or distributed
-# except according to those terms.
-
-set -ex
-source shared.sh
-
-curl https://cmake.org/files/v3.6/cmake-3.6.3.tar.gz | tar xzf -
-
-mkdir cmake-build
-cd cmake-build
-hide_output ../cmake-3.6.3/configure --prefix=/rustroot
-hide_output make -j10
-hide_output make install
-
-cd ..
-rm -rf cmake-build
-rm -rf cmake-3.6.3
diff --git a/src/ci/docker/dist-i686-linux/build-curl.sh b/src/ci/docker/dist-i686-linux/build-curl.sh
deleted file mode 100755
index edf3175b81c..00000000000
--- a/src/ci/docker/dist-i686-linux/build-curl.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-# file at the top-level directory of this distribution and at
-# http://rust-lang.org/COPYRIGHT.
-#
-# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-# option. This file may not be copied, modified, or distributed
-# except according to those terms.
-
-set -ex
-source shared.sh
-
-VERSION=7.51.0
-
-curl http://cool.haxx.se/download/curl-$VERSION.tar.bz2 | tar xjf -
-
-mkdir curl-build
-cd curl-build
-hide_output ../curl-$VERSION/configure \
-      --prefix=/rustroot \
-      --with-ssl=/rustroot \
-      --disable-sspi \
-      --disable-gopher \
-      --disable-smtp \
-      --disable-smb \
-      --disable-imap \
-      --disable-pop3 \
-      --disable-tftp \
-      --disable-telnet \
-      --disable-manual \
-      --disable-dict \
-      --disable-rtsp \
-      --disable-ldaps \
-      --disable-ldap
-hide_output make -j10
-hide_output make install
-
-cd ..
-rm -rf curl-build
-rm -rf curl-$VERSION
-yum erase -y curl
diff --git a/src/ci/docker/dist-i686-linux/build-gcc.sh b/src/ci/docker/dist-i686-linux/build-gcc.sh
deleted file mode 100755
index 08020e533ff..00000000000
--- a/src/ci/docker/dist-i686-linux/build-gcc.sh
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-# file at the top-level directory of this distribution and at
-# http://rust-lang.org/COPYRIGHT.
-#
-# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-# option. This file may not be copied, modified, or distributed
-# except according to those terms.
-
-set -ex
-
-source shared.sh
-
-GCC=4.8.5
-
-curl https://ftp.gnu.org/gnu/gcc/gcc-$GCC/gcc-$GCC.tar.bz2 | tar xjf -
-cd gcc-$GCC
-
-# FIXME(#49246): Remove the `sed` below.
-#
-# On 2018 March 21st, two Travis builders' cache for Docker are suddenly invalidated. Normally this
-# is fine, because we just need to rebuild the Docker image. However, it reveals a network issue:
-# downloading from `ftp://gcc.gnu.org/` from Travis (using passive mode) often leads to "Connection
-# timed out" error, and even when the download completed, the file is usually corrupted. This causes
-# nothing to be landed that day.
-#
-# We observed that the `gcc-4.8.5.tar.bz2` above can be downloaded successfully, so as a stability
-# improvement we try to download from the HTTPS mirror instead. Turns out this uncovered the third
-# bug: the host `gcc.gnu.org` and `cygwin.com` share the same IP, and the TLS certificate of the
-# latter host is presented to `wget`! Therefore, we choose to download from the insecure HTTP server
-# instead here.
-#
-sed -i'' 's|ftp://gcc\.gnu\.org/|http://gcc.gnu.org/|g' ./contrib/download_prerequisites
-
-./contrib/download_prerequisites
-mkdir ../gcc-build
-cd ../gcc-build
-hide_output ../gcc-$GCC/configure \
-    --prefix=/rustroot \
-    --enable-languages=c,c++
-hide_output make -j10
-hide_output make install
-ln -nsf gcc /rustroot/bin/cc
-
-cd ..
-rm -rf gcc-build
-rm -rf gcc-$GCC
-yum erase -y gcc gcc-c++ binutils
diff --git a/src/ci/docker/dist-i686-linux/build-git.sh b/src/ci/docker/dist-i686-linux/build-git.sh
deleted file mode 100755
index aa31f50ba03..00000000000
--- a/src/ci/docker/dist-i686-linux/build-git.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-# file at the top-level directory of this distribution and at
-# http://rust-lang.org/COPYRIGHT.
-#
-# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-# option. This file may not be copied, modified, or distributed
-# except according to those terms.
-
-set -ex
-source shared.sh
-
-curl -L https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz | tar xzf -
-
-cd git-2.10.0
-make configure
-hide_output ./configure --prefix=/rustroot
-hide_output make -j10
-hide_output make install
-
-cd ..
-rm -rf git-2.10.0
diff --git a/src/ci/docker/dist-i686-linux/build-headers.sh b/src/ci/docker/dist-i686-linux/build-headers.sh
deleted file mode 100755
index 2f15114d6f9..00000000000
--- a/src/ci/docker/dist-i686-linux/build-headers.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-# file at the top-level directory of this distribution and at
-# http://rust-lang.org/COPYRIGHT.
-#
-# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-# option. This file may not be copied, modified, or distributed
-# except according to those terms.
-
-set -ex
-source shared.sh
-
-curl https://cdn.kernel.org/pub/linux/kernel/v3.x/linux-3.2.84.tar.xz | unxz | tar x
-
-cd linux-3.2.84
-hide_output make mrproper
-hide_output make INSTALL_HDR_PATH=dest headers_install
-
-find dest/include \( -name .install -o -name ..install.cmd \) -delete
-yes | cp -fr dest/include/* /usr/include
-
-cd ..
-rm -rf linux-3.2.84
diff --git a/src/ci/docker/dist-i686-linux/build-openssl.sh b/src/ci/docker/dist-i686-linux/build-openssl.sh
deleted file mode 100755
index e7226ace020..00000000000
--- a/src/ci/docker/dist-i686-linux/build-openssl.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-# file at the top-level directory of this distribution and at
-# http://rust-lang.org/COPYRIGHT.
-#
-# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-# option. This file may not be copied, modified, or distributed
-# except according to those terms.
-
-set -ex
-source shared.sh
-
-VERSION=1.0.2k
-URL=https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/openssl-$VERSION.tar.gz
-
-curl $URL | tar xzf -
-
-cd openssl-$VERSION
-hide_output ./config --prefix=/rustroot shared -fPIC
-hide_output make -j10
-hide_output make install
-cd ..
-rm -rf openssl-$VERSION
-
-# Make the system cert collection available to the new install.
-ln -nsf /etc/pki/tls/cert.pem /rustroot/ssl/
diff --git a/src/ci/docker/dist-i686-linux/build-python.sh b/src/ci/docker/dist-i686-linux/build-python.sh
deleted file mode 100755
index c6b8cdde4b9..00000000000
--- a/src/ci/docker/dist-i686-linux/build-python.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/env bash
-# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-# file at the top-level directory of this distribution and at
-# http://rust-lang.org/COPYRIGHT.
-#
-# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-# option. This file may not be copied, modified, or distributed
-# except according to those terms.
-
-set -ex
-source shared.sh
-
-curl https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz | \
-  tar xzf -
-
-mkdir python-build
-cd python-build
-
-# Gotta do some hackery to tell python about our custom OpenSSL build, but other
-# than that fairly normal.
-CFLAGS='-I /rustroot/include' LDFLAGS='-L /rustroot/lib -L /rustroot/lib64' \
-    hide_output ../Python-2.7.12/configure --prefix=/rustroot
-hide_output make -j10
-hide_output make install
-
-cd ..
-rm -rf python-build
-rm -rf Python-2.7.12
diff --git a/src/ci/docker/dist-i686-linux/shared.sh b/src/ci/docker/dist-i686-linux/shared.sh
deleted file mode 100644
index 97e6d2908cf..00000000000
--- a/src/ci/docker/dist-i686-linux/shared.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-# file at the top-level directory of this distribution and at
-# http://rust-lang.org/COPYRIGHT.
-#
-# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-# option. This file may not be copied, modified, or distributed
-# except according to those terms.
-
-hide_output() {
-  set +x
-  on_err="
-echo ERROR: An error was encountered with the build.
-cat /tmp/build.log
-exit 1
-"
-  trap "$on_err" ERR
-  bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
-  PING_LOOP_PID=$!
-  $@ &> /tmp/build.log
-  trap - ERR
-  kill $PING_LOOP_PID
-  set -x
-}
diff --git a/src/ci/docker/dist-x86_64-linux/Dockerfile b/src/ci/docker/dist-x86_64-linux/Dockerfile
index 28c97e8c6db..5726fab7524 100644
--- a/src/ci/docker/dist-x86_64-linux/Dockerfile
+++ b/src/ci/docker/dist-x86_64-linux/Dockerfile
@@ -29,7 +29,7 @@ ENV PATH=/rustroot/bin:$PATH
 ENV LD_LIBRARY_PATH=/rustroot/lib64:/rustroot/lib
 ENV PKG_CONFIG_PATH=/rustroot/lib/pkgconfig
 WORKDIR /tmp
-COPY dist-x86_64-linux/shared.sh dist-x86_64-linux/build-binutils.sh /tmp/
+COPY dist-x86_64-linux/shared.sh /tmp/
 
 # We need a build of openssl which supports SNI to download artifacts from
 # static.rust-lang.org. This'll be used to link into libcurl below (and used
@@ -51,9 +51,15 @@ RUN ./build-curl.sh
 # immediately segfault in Rust, so we need to install our own binutils.
 #
 # See https://github.com/rust-lang/rust/issues/20440 for more info
+COPY dist-x86_64-linux/build-binutils.sh /tmp/
 RUN ./build-binutils.sh
 
-# Need a newer version of gcc than centos has to compile LLVM nowadays
+# libssh2 (a dependency of Cargo) requires cmake 2.8.11 or higher but CentOS
+# only has 2.6.4, so build our own
+COPY dist-x86_64-linux/build-cmake.sh /tmp/
+RUN ./build-cmake.sh
+
+# Build a version of gcc capable of building LLVM 6
 COPY dist-x86_64-linux/build-gcc.sh /tmp/
 RUN ./build-gcc.sh
 
@@ -61,16 +67,17 @@ RUN ./build-gcc.sh
 COPY dist-x86_64-linux/build-python.sh /tmp/
 RUN ./build-python.sh
 
+# Now build LLVM+Clang 6, afterwards configuring further compilations to use the
+# clang/clang++ compilers.
+COPY dist-x86_64-linux/build-clang.sh /tmp/
+RUN ./build-clang.sh
+ENV CC=clang CXX=clang++
+
 # Apparently CentOS 5.5 desn't have `git` in yum, but we're gonna need it for
 # cloning, so download and build it here.
 COPY dist-x86_64-linux/build-git.sh /tmp/
 RUN ./build-git.sh
 
-# libssh2 (a dependency of Cargo) requires cmake 2.8.11 or higher but CentOS
-# only has 2.6.4, so build our own
-COPY dist-x86_64-linux/build-cmake.sh /tmp/
-RUN ./build-cmake.sh
-
 # for sanitizers, we need kernel headers files newer than the ones CentOS ships
 # with so we install newer ones here
 COPY dist-x86_64-linux/build-headers.sh /tmp/
@@ -85,8 +92,10 @@ ENV RUST_CONFIGURE_ARGS \
       --enable-full-tools \
       --enable-sanitizers \
       --enable-profiler \
-      --enable-compiler-docs
+      --enable-compiler-docs \
+      --set target.x86_64-unknown-linux-gnu.linker=clang
 ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS
+ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang
 
 # This is the only builder which will create source tarballs
 ENV DIST_SRC 1
diff --git a/src/ci/docker/dist-x86_64-linux/build-clang.sh b/src/ci/docker/dist-x86_64-linux/build-clang.sh
new file mode 100755
index 00000000000..b0c27aa45bf
--- /dev/null
+++ b/src/ci/docker/dist-x86_64-linux/build-clang.sh
@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+# file at the top-level directory of this distribution and at
+# http://rust-lang.org/COPYRIGHT.
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+set -ex
+
+source shared.sh
+
+LLVM=6.0.0
+
+mkdir clang
+cd clang
+
+curl https://releases.llvm.org/$LLVM/llvm-$LLVM.src.tar.xz | \
+  xz -d | \
+  tar xf -
+
+cd llvm-$LLVM.src
+
+mkdir -p tools/clang
+
+curl https://releases.llvm.org/$LLVM/cfe-$LLVM.src.tar.xz | \
+  xz -d | \
+  tar xf - -C tools/clang --strip-components=1
+
+mkdir ../clang-build
+cd ../clang-build
+
+# For whatever reason the default set of include paths for clang is different
+# than that of gcc. As a result we need to manually include our sysroot's
+# include path, /rustroot/include, to clang's default include path.
+#
+# Alsow there's this weird oddity with gcc where there's an 'include-fixed'
+# directory that it generates. It turns out [1] that Centos 5's headers are so
+# old that they're incompatible with modern C semantics. While gcc automatically
+# fixes that clang doesn't account for this. Tell clang to manually include the
+# fixed headers so we can successfully compile code later on.
+#
+# [1]: https://sourceware.org/ml/crossgcc/2008-11/msg00028.html
+INC="/rustroot/include"
+INC="$INC:/rustroot/lib/gcc/x86_64-unknown-linux-gnu/4.8.5/include-fixed"
+INC="$INC:/usr/include"
+
+hide_output \
+    cmake ../llvm-$LLVM.src \
+      -DCMAKE_C_COMPILER=/rustroot/bin/gcc \
+      -DCMAKE_CXX_COMPILER=/rustroot/bin/g++ \
+      -DCMAKE_BUILD_TYPE=Release \
+      -DCMAKE_INSTALL_PREFIX=/rustroot \
+      -DLLVM_TARGETS_TO_BUILD=X86 \
+      -DC_INCLUDE_DIRS="$INC"
+
+hide_output make -j10
+hide_output make install
+
+cd ../..
+rm -rf clang
diff --git a/src/ci/docker/dist-x86_64-linux/build-gcc.sh b/src/ci/docker/dist-x86_64-linux/build-gcc.sh
index 08020e533ff..62ea2506f4e 100755
--- a/src/ci/docker/dist-x86_64-linux/build-gcc.sh
+++ b/src/ci/docker/dist-x86_64-linux/build-gcc.sh
@@ -42,7 +42,6 @@ hide_output ../gcc-$GCC/configure \
     --enable-languages=c,c++
 hide_output make -j10
 hide_output make install
-ln -nsf gcc /rustroot/bin/cc
 
 cd ..
 rm -rf gcc-build
diff --git a/src/llvm b/src/llvm
-Subproject 7243155b1c3da0a980c868a87adebf00e0b3398
+Subproject b6c1a03fb498f6c03d1cbfd4404223a046f8c3b