Skip to content

Commit 9fe8b08

Browse files
committed
ship LLVM tools with the toolchain
1 parent f76f6fb commit 9fe8b08

File tree

7 files changed

+55
-4
lines changed

7 files changed

+55
-4
lines changed

config.toml.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@
343343
# rustc to execute.
344344
#lld = false
345345

346+
# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the
347+
# sysroot.
348+
#llvm-tools = false
349+
346350
# Whether to deny warnings in crates
347351
#deny-warnings = true
348352

src/bootstrap/compile.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use filetime::FileTime;
3131
use serde_json;
3232

3333
use util::{exe, libdir, is_dylib, CiEnv};
34-
use {Compiler, Mode};
34+
use {Compiler, Mode, LLVM_TOOLS};
3535
use native;
3636
use tool;
3737

@@ -775,6 +775,23 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder,
775775
}
776776
}
777777

778+
fn copy_llvm_tools_to_sysroot(builder: &Builder,
779+
target_compiler: Compiler) {
780+
let target = target_compiler.host;
781+
782+
let dst = builder.sysroot_libdir(target_compiler, target)
783+
.parent()
784+
.unwrap()
785+
.join("bin");
786+
t!(fs::create_dir_all(&dst));
787+
788+
let src = builder.llvm_out(target).join("bin");
789+
for tool in LLVM_TOOLS {
790+
let exe = exe(tool, &target);
791+
builder.copy(&src.join(&exe), &dst.join(&exe));
792+
}
793+
}
794+
778795
fn copy_lld_to_sysroot(builder: &Builder,
779796
target_compiler: Compiler,
780797
lld_install_root: &Path) {
@@ -966,6 +983,9 @@ impl Step for Assemble {
966983
copy_codegen_backends_to_sysroot(builder,
967984
build_compiler,
968985
target_compiler);
986+
if builder.config.ship_llvm_tools {
987+
copy_llvm_tools_to_sysroot(builder, target_compiler);
988+
}
969989
if let Some(lld_install) = lld_install {
970990
copy_lld_to_sysroot(builder, target_compiler, &lld_install);
971991
}

src/bootstrap/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub struct Config {
8686
pub llvm_link_jobs: Option<u32>,
8787

8888
pub lld_enabled: bool,
89+
pub ship_llvm_tools: bool,
8990

9091
// rust codegen options
9192
pub rust_optimize: bool,
@@ -305,6 +306,7 @@ struct Rust {
305306
codegen_backends_dir: Option<String>,
306307
wasm_syscall: Option<bool>,
307308
lld: Option<bool>,
309+
llvm_tools: Option<bool>,
308310
deny_warnings: Option<bool>,
309311
}
310312

@@ -518,6 +520,7 @@ impl Config {
518520
set(&mut config.test_miri, rust.test_miri);
519521
set(&mut config.wasm_syscall, rust.wasm_syscall);
520522
set(&mut config.lld_enabled, rust.lld);
523+
set(&mut config.ship_llvm_tools, rust.llvm_tools);
521524
config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false);
522525
config.rustc_default_linker = rust.default_linker.clone();
523526
config.musl_root = rust.musl_root.clone().map(PathBuf::from);

src/bootstrap/configure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ def set(key, value):
333333
elif option.name == 'full-tools':
334334
set('rust.codegen-backends', ['llvm', 'emscripten'])
335335
set('rust.lld', True)
336+
set('rust.llvm-tools', True)
336337
set('build.extended', True)
337338
elif option.name == 'option-checking':
338339
# this was handled above

src/bootstrap/dist.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::process::{Command, Stdio};
2626

2727
use build_helper::output;
2828

29-
use {Compiler, Mode};
29+
use {Compiler, Mode, LLVM_TOOLS};
3030
use channel;
3131
use util::{libdir, is_dylib, exe};
3232
use builder::{Builder, RunConfig, ShouldRun, Step};
@@ -503,6 +503,24 @@ impl Step for Rustc {
503503
builder.copy(&src, &dst);
504504
}
505505

506+
if builder.config.ship_llvm_tools {
507+
let src = builder.sysroot_libdir(compiler, host)
508+
.parent()
509+
.unwrap()
510+
.join("bin");
511+
512+
let dst = image.join("lib/rustlib")
513+
.join(&*host)
514+
.join("bin");
515+
516+
t!(fs::create_dir_all(&dst.parent().unwrap()));
517+
518+
for tool in LLVM_TOOLS {
519+
let exe = exe(tool, &compiler.host);
520+
builder.copy(&src.join(&exe), &dst.join(&exe));
521+
}
522+
}
523+
506524
// Man pages
507525
t!(fs::create_dir_all(image.join("share/man/man1")));
508526
let man_src = builder.src.join("src/doc/man");

src/bootstrap/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ use flags::Subcommand;
199199
use cache::{Interned, INTERNER};
200200
use toolstate::ToolState;
201201

202+
const LLVM_TOOLS: &[&str] = &["llvm-nm", "llvm-objcopy", "llvm-objdump", "llvm-size"];
203+
202204
/// A structure representing a Rust compiler.
203205
///
204206
/// Each compiler has a `stage` that it is associated with and a `host` that

src/bootstrap/native.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,11 @@ impl Step for Llvm {
167167
// which saves both memory during parallel links and overall disk space
168168
// for the tools. We don't distribute any of those tools, so this is
169169
// just a local concern. However, it doesn't work well everywhere.
170-
if target.contains("linux-gnu") || target.contains("apple-darwin") {
171-
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
170+
//
171+
// If we are shipping llvm tools then we statically link them LLVM
172+
if (target.contains("linux-gnu") || target.contains("apple-darwin")) &&
173+
!builder.config.ship_llvm_tools {
174+
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
172175
}
173176

174177
if target.contains("msvc") {

0 commit comments

Comments
 (0)