From 5e577b8aee60b7ee2394a50d8eec8a3b26541d11 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 30 Apr 2018 10:15:48 +0200 Subject: [PATCH] ship LLVM tools with the toolchain --- config.toml.example | 4 ++++ src/bootstrap/compile.rs | 22 +++++++++++++++++++++- src/bootstrap/config.rs | 3 +++ src/bootstrap/configure.py | 1 + src/bootstrap/dist.rs | 20 +++++++++++++++++++- src/bootstrap/lib.rs | 2 ++ src/bootstrap/native.rs | 7 +++++-- 7 files changed, 55 insertions(+), 4 deletions(-) diff --git a/config.toml.example b/config.toml.example index 33ad9147ce0..cbf20993209 100644 --- a/config.toml.example +++ b/config.toml.example @@ -347,6 +347,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 diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 231ed9d40d2..ea234c0016c 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -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; @@ -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) { @@ -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); } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 9840682d137..b676ba22172 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -88,6 +88,7 @@ pub struct Config { pub llvm_link_jobs: Option, pub lld_enabled: bool, + pub ship_llvm_tools: bool, // rust codegen options pub rust_optimize: bool, @@ -308,6 +309,7 @@ struct Rust { codegen_backends_dir: Option, wasm_syscall: Option, lld: Option, + llvm_tools: Option, deny_warnings: Option, backtrace_on_ice: Option, } @@ -531,6 +533,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); diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 3574b7d210a..36d936bab3b 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -335,6 +335,7 @@ for key in known_args: 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 diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 82ba03ec777..9092deeac46 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -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}; @@ -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"); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index f64161fb027..4d1bc6ad6ba 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -199,6 +199,8 @@ use flags::Subcommand; use cache::{Interned, INTERNER}; use toolstate::ToolState; +const LLVM_TOOLS: &[&str] = &["llvm-nm", "llvm-objcopy", "llvm-objdump", "llvm-size"]; + /// A structure representing a Rust compiler. /// /// Each compiler has a `stage` that it is associated with and a `host` that diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 93292c658ba..2f6af1e0640 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -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") {