Skip to content

Commit

Permalink
bootstrap: Build LLVM with ThinLTO on Linux64.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed May 30, 2018
1 parent b447ad7 commit 55aaf63
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use util::{exe, libdir, is_dylib, CiEnv};
use {Compiler, Mode};
use native;
use tool;

use cache::{INTERNER, Interned};
use builder::{Step, RunConfig, ShouldRun, Builder};

Expand Down Expand Up @@ -635,20 +634,28 @@ impl Step for CodegenBackend {
return;
}

let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "build");
let mut cargo = builder.cargo(compiler, Mode::Librustc, target, "rustc");
let mut features = builder.rustc_features().to_string();
cargo.arg("--manifest-path")
.arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
rustc_cargo_env(builder, &mut cargo);

features += &build_codegen_backend(&builder, &mut cargo, &compiler, target, backend);
cargo.arg("--features").arg(features);

let tmp_stamp = builder.cargo_out(compiler, Mode::Librustc, target)
.join(".tmp.stamp");

if builder.config.llvm_thin_lto {
cargo.deferred_arg("--")
.deferred_arg("-Clink-arg=-fuse-ld=lld")
.deferred_arg("-Clink-arg=-flto=thin")
.deferred_arg("-Clink-arg=-O2");
}

let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
let files = run_cargo(builder,
cargo.arg("--features").arg(features),
&mut cargo,
&tmp_stamp,
false);
if builder.config.dry_run {
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct Config {
pub llvm_assertions: bool,
pub llvm_optimize: bool,
pub llvm_release_debuginfo: bool,
pub llvm_thin_lto: bool,
pub llvm_version_check: bool,
pub llvm_static_stdcpp: bool,
pub llvm_link_shared: bool,
Expand Down Expand Up @@ -246,6 +247,7 @@ struct Llvm {
assertions: Option<bool>,
optimize: Option<bool>,
release_debuginfo: Option<bool>,
thin_lto: Option<bool>,
version_check: Option<bool>,
static_libstdcpp: Option<bool>,
targets: Option<String>,
Expand Down Expand Up @@ -501,6 +503,7 @@ impl Config {
llvm_assertions = llvm.assertions;
set(&mut config.llvm_optimize, llvm.optimize);
set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);
set(&mut config.llvm_thin_lto, llvm.thin_lto);
set(&mut config.llvm_version_check, llvm.version_check);
set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp);
set(&mut config.llvm_link_shared, llvm.link_shared);
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ impl Step for Llvm {
.define("LLVM_TARGET_ARCH", target.split('-').next().unwrap())
.define("LLVM_DEFAULT_TARGET_TRIPLE", target);

if builder.config.llvm_thin_lto {
cfg.define("LLVM_ENABLE_LTO", "Thin")
.define("LLVM_ENABLE_LLD", "ON");
}

// By default, LLVM will automatically find OCaml and, if it finds it,
// install the LLVM bindings in LLVM_OCAML_INSTALL_PATH, which defaults
// to /usr/bin/ocaml.
Expand Down
4 changes: 3 additions & 1 deletion src/ci/docker/dist-x86_64-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ ENV RUST_CONFIGURE_ARGS \
--enable-sanitizers \
--enable-profiler \
--enable-compiler-docs \
--set target.x86_64-unknown-linux-gnu.linker=clang
--set target.x86_64-unknown-linux-gnu.linker=clang \
--set target.x86_64-unknown-linux-gnu.ar=/rustroot/bin/llvm-ar \
--set target.x86_64-unknown-linux-gnu.ranlib=/rustroot/bin/llvm-ranlib
ENV SCRIPT python2.7 ../x.py dist --host $HOSTS --target $HOSTS
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=clang

Expand Down

0 comments on commit 55aaf63

Please sign in to comment.