Skip to content

Commit

Permalink
Auto merge of #50336 - japaric:llvm-tools, r=<try>
Browse files Browse the repository at this point in the history
ship LLVM tools with the toolchain

this PR adds llvm-{nm,objcopy,objdump,size} to the rustc sysroot (right next to LLD)

this slightly increases the size of the rustc component. I measured these numbers on x86_64 Linux:

- rustc-1.27.0-dev-x86_64-unknown-linux-gnu.tar.gz 180M -> 193M (+7%)
- rustc-1.27.0-dev-x86_64-unknown-linux-gnu.tar.xz 129M -> 137M (+6%)

r? @alexcrichton
cc #49584
  • Loading branch information
bors committed Apr 30, 2018
2 parents 64e6dda + c3efbbe commit 2f8c92c
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
4 changes: 4 additions & 0 deletions config.toml.example
Expand Up @@ -343,6 +343,10 @@
# rustc to execute.
#lld = false

# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the
# sysroot.
#llvm-tools = false

# Whether to deny warnings in crates
#deny-warnings = true

Expand Down
22 changes: 21 additions & 1 deletion src/bootstrap/compile.rs
Expand Up @@ -31,7 +31,7 @@ use filetime::FileTime;
use serde_json;

use util::{exe, libdir, is_dylib, CiEnv};
use {Compiler, Mode};
use {Compiler, Mode, LLVM_TOOLS};
use native;
use tool;

Expand Down Expand Up @@ -775,6 +775,23 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder,
}
}

fn copy_llvm_tools_to_sysroot(builder: &Builder,
target_compiler: Compiler) {
let target = target_compiler.host;

let dst = builder.sysroot_libdir(target_compiler, target)
.parent()
.unwrap()
.join("bin");
t!(fs::create_dir_all(&dst));

let src = builder.llvm_out(target).join("bin");
for tool in LLVM_TOOLS {
let exe = exe(tool, &target);
builder.copy(&src.join(&exe), &dst.join(&exe));
}
}

fn copy_lld_to_sysroot(builder: &Builder,
target_compiler: Compiler,
lld_install_root: &Path) {
Expand Down Expand Up @@ -966,6 +983,9 @@ impl Step for Assemble {
copy_codegen_backends_to_sysroot(builder,
build_compiler,
target_compiler);
if builder.config.ship_llvm_tools {
copy_llvm_tools_to_sysroot(builder, target_compiler);
}
if let Some(lld_install) = lld_install {
copy_lld_to_sysroot(builder, target_compiler, &lld_install);
}
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/config.rs
Expand Up @@ -86,6 +86,7 @@ pub struct Config {
pub llvm_link_jobs: Option<u32>,

pub lld_enabled: bool,
pub ship_llvm_tools: bool,

// rust codegen options
pub rust_optimize: bool,
Expand Down Expand Up @@ -305,6 +306,7 @@ struct Rust {
codegen_backends_dir: Option<String>,
wasm_syscall: Option<bool>,
lld: Option<bool>,
llvm_tools: Option<bool>,
deny_warnings: Option<bool>,
}

Expand Down Expand Up @@ -518,6 +520,7 @@ impl Config {
set(&mut config.test_miri, rust.test_miri);
set(&mut config.wasm_syscall, rust.wasm_syscall);
set(&mut config.lld_enabled, rust.lld);
set(&mut config.ship_llvm_tools, rust.llvm_tools);
config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false);
config.rustc_default_linker = rust.default_linker.clone();
config.musl_root = rust.musl_root.clone().map(PathBuf::from);
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/configure.py
Expand Up @@ -333,6 +333,7 @@ def set(key, value):
elif option.name == 'full-tools':
set('rust.codegen-backends', ['llvm', 'emscripten'])
set('rust.lld', True)
set('rust.llvm-tools', True)
set('build.extended', True)
elif option.name == 'option-checking':
# this was handled above
Expand Down
20 changes: 19 additions & 1 deletion src/bootstrap/dist.rs
Expand Up @@ -26,7 +26,7 @@ use std::process::{Command, Stdio};

use build_helper::output;

use {Compiler, Mode};
use {Compiler, Mode, LLVM_TOOLS};
use channel;
use util::{libdir, is_dylib, exe};
use builder::{Builder, RunConfig, ShouldRun, Step};
Expand Down Expand Up @@ -503,6 +503,24 @@ impl Step for Rustc {
builder.copy(&src, &dst);
}

if builder.config.ship_llvm_tools {
let src = builder.sysroot_libdir(compiler, host)
.parent()
.unwrap()
.join("bin");

let dst = image.join("lib/rustlib")
.join(&*host)
.join("bin");

t!(fs::create_dir_all(&dst.parent().unwrap()));

for tool in LLVM_TOOLS {
let exe = exe(tool, &compiler.host);
builder.copy(&src.join(&exe), &dst.join(&exe));
}
}

// Man pages
t!(fs::create_dir_all(image.join("share/man/man1")));
let man_src = builder.src.join("src/doc/man");
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/lib.rs
Expand Up @@ -199,6 +199,10 @@ use flags::Subcommand;
use cache::{Interned, INTERNER};
use toolstate::ToolState;

const LLVM_TOOLS: &[&str] = &[
"llvm-nm", "llvm-objcopy", "llvm-objdump", "llvm-profdata", "llvm-size",
];

/// A structure representing a Rust compiler.
///
/// Each compiler has a `stage` that it is associated with and a `host` that
Expand Down
7 changes: 5 additions & 2 deletions src/bootstrap/native.rs
Expand Up @@ -167,8 +167,11 @@ impl Step for Llvm {
// which saves both memory during parallel links and overall disk space
// for the tools. We don't distribute any of those tools, so this is
// just a local concern. However, it doesn't work well everywhere.
if target.contains("linux-gnu") || target.contains("apple-darwin") {
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
//
// If we are shipping llvm tools then we statically link them LLVM
if (target.contains("linux-gnu") || target.contains("apple-darwin")) &&
!builder.config.ship_llvm_tools {
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
}

if target.contains("msvc") {
Expand Down

0 comments on commit 2f8c92c

Please sign in to comment.