Skip to content

Commit 5e577b8

Browse files
committed
ship LLVM tools with the toolchain
1 parent 7d576f2 commit 5e577b8

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
@@ -347,6 +347,10 @@
347347
# rustc to execute.
348348
#lld = false
349349

350+
# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the
351+
# sysroot.
352+
#llvm-tools = false
353+
350354
# Whether to deny warnings in crates
351355
#deny-warnings = true
352356

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
@@ -88,6 +88,7 @@ pub struct Config {
8888
pub llvm_link_jobs: Option<u32>,
8989

9090
pub lld_enabled: bool,
91+
pub ship_llvm_tools: bool,
9192

9293
// rust codegen options
9394
pub rust_optimize: bool,
@@ -308,6 +309,7 @@ struct Rust {
308309
codegen_backends_dir: Option<String>,
309310
wasm_syscall: Option<bool>,
310311
lld: Option<bool>,
312+
llvm_tools: Option<bool>,
311313
deny_warnings: Option<bool>,
312314
backtrace_on_ice: Option<bool>,
313315
}
@@ -531,6 +533,7 @@ impl Config {
531533
set(&mut config.test_miri, rust.test_miri);
532534
set(&mut config.wasm_syscall, rust.wasm_syscall);
533535
set(&mut config.lld_enabled, rust.lld);
536+
set(&mut config.ship_llvm_tools, rust.llvm_tools);
534537
config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false);
535538
config.rustc_default_linker = rust.default_linker.clone();
536539
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
@@ -335,6 +335,7 @@ def set(key, value):
335335
elif option.name == 'full-tools':
336336
set('rust.codegen-backends', ['llvm', 'emscripten'])
337337
set('rust.lld', True)
338+
set('rust.llvm-tools', True)
338339
set('build.extended', True)
339340
elif option.name == 'option-checking':
340341
# 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)