Skip to content

Commit

Permalink
make a llvm-tools rustup component
Browse files Browse the repository at this point in the history
  • Loading branch information
japaric committed Jun 3, 2018
1 parent 8e67307 commit 66a7db9
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 44 deletions.
1 change: 1 addition & 0 deletions src/bootstrap/builder.rs
Expand Up @@ -451,6 +451,7 @@ impl<'a> Builder<'a> {
dist::Cargo,
dist::Rls,
dist::Rustfmt,
dist::LlvmTools,
dist::Extended,
dist::HashSign
),
Expand Down
22 changes: 1 addition & 21 deletions 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, LLVM_TOOLS};
use {Compiler, Mode};
use native;
use tool;

Expand Down Expand Up @@ -775,23 +775,6 @@ 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 @@ -983,9 +966,6 @@ 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
4 changes: 2 additions & 2 deletions src/bootstrap/config.rs
Expand Up @@ -88,7 +88,7 @@ pub struct Config {
pub llvm_link_jobs: Option<u32>,

pub lld_enabled: bool,
pub ship_llvm_tools: bool,
pub llvm_tools_enabled: bool,

// rust codegen options
pub rust_optimize: bool,
Expand Down Expand Up @@ -533,7 +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);
set(&mut config.llvm_tools_enabled, 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
98 changes: 79 additions & 19 deletions src/bootstrap/dist.rs
Expand Up @@ -43,6 +43,8 @@ pub fn pkgname(builder: &Builder, component: &str) -> String {
format!("{}-{}", component, builder.rls_package_vers())
} else if component == "rustfmt" {
format!("{}-{}", component, builder.rustfmt_package_vers())
} else if component == "llvm-tools" {
format!("{}-{}", component, builder.llvm_tools_vers())
} else {
assert!(component.starts_with("rust"));
format!("{}-{}", component, builder.rust_package_vers())
Expand Down Expand Up @@ -394,7 +396,7 @@ impl Step for Rustc {
let compiler = self.compiler;
let host = self.compiler.host;

builder.info(&format!("Dist rustc stage{} ({})", compiler.stage, compiler.host));
builder.info(&format!("Dist rustc stage{} ({})", compiler.stage, host));
let name = pkgname(builder, "rustc");
let image = tmpdir(builder).join(format!("{}-{}-image", name, host));
let _ = fs::remove_dir_all(&image);
Expand Down Expand Up @@ -503,24 +505,6 @@ 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 Expand Up @@ -1756,6 +1740,7 @@ impl Step for HashSign {
cmd.arg(builder.package_vers(&builder.release_num("cargo")));
cmd.arg(builder.package_vers(&builder.release_num("rls")));
cmd.arg(builder.package_vers(&builder.release_num("rustfmt")));
cmd.arg(builder.llvm_tools_vers());
cmd.arg(addr);

builder.create_dir(&distdir(builder));
Expand All @@ -1766,3 +1751,78 @@ impl Step for HashSign {
assert!(status.success());
}
}

#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct LlvmTools {
pub stage: u32,
pub compiler: Compiler,
pub target: Interned<String>,
}

impl Step for LlvmTools {
type Output = Option<PathBuf>;
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
run.path("llvm-tools")
}

fn make_run(run: RunConfig) {
run.builder.ensure(LlvmTools {
stage: run.builder.top_stage,
compiler: run.builder.compiler(run.builder.top_stage, run.target),
target: run.target,
});
}

fn run(self, builder: &Builder) -> Option<PathBuf> {
let compiler = self.compiler;
let host = compiler.host;

let stage = self.stage;
assert!(builder.config.extended);

builder.info(&format!("Dist LlvmTools stage{} ({})", stage, host));
let src = builder.src.join("src/llvm");
let name = pkgname(builder, "llvm-tools");

let tmp = tmpdir(builder);
let image = tmp.join("llvm-tools-image");
drop(fs::remove_dir_all(&image));
t!(fs::create_dir_all(&image.join("bin")));

// Prepare the image directory
for tool in LLVM_TOOLS {
let exe = builder
.llvm_out(host)
.join("bin")
.join(exe(tool, &compiler.host));
builder.install(&exe, &image.join("bin"), 0o755);
}

// Prepare the overlay
let overlay = tmp.join("llvm-tools-overlay");
drop(fs::remove_dir_all(&overlay));
builder.create_dir(&overlay);
builder.install(&src.join("README.txt"), &overlay, 0o644);
builder.install(&src.join("LICENSE.TXT"), &overlay, 0o644);

// Generate the installer tarball
let mut cmd = rust_installer(builder);
cmd.arg("generate")
.arg("--product-name=Rust")
.arg("--rel-manifest-dir=rustlib")
.arg("--success-message=llvm-tools-installed.")
.arg("--image-dir").arg(&image)
.arg("--work-dir").arg(&tmpdir(builder))
.arg("--output-dir").arg(&distdir(builder))
.arg("--non-installed-overlay").arg(&overlay)
.arg(format!("--package-name={}-{}", name, host))
.arg("--legacy-manifest-dirs=rustlib,cargo")
.arg("--component-name=llvm-tools");


builder.run(&mut cmd);
Some(distdir(builder).join(format!("{}-{}.tar.gz", name, host)))
}
}
18 changes: 18 additions & 0 deletions src/bootstrap/lib.rs
Expand Up @@ -957,6 +957,24 @@ impl Build {
self.package_vers(&self.release_num("rustfmt"))
}

fn llvm_tools_vers(&self) -> String {
let stdout = build_helper::output(
Command::new(self.llvm_out(self.config.build).join("build/bin/llvm-size"))
.arg("--version"),
);

for line in stdout.lines() {
if line.contains("LLVM version") {
if let Some(vers) = line.split_whitespace().nth(2) {
return vers.to_string();
}
}
}

panic!("The output of $LLVM_TOOL has changed; \
please fix `bootstrap::Build.llvm_tools_vers`");
}

/// Returns the `version` string associated with this compiler for Rust
/// itself.
///
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/native.rs
Expand Up @@ -170,12 +170,12 @@ impl Step for Llvm {
//
// 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 {
!builder.config.llvm_tools_enabled {
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
}

// For distribution we want the LLVM tools to be *statically* linked to libstdc++
if builder.config.ship_llvm_tools {
if builder.config.llvm_tools_enabled {
cfg.define("CMAKE_EXE_LINKER_FLAGS", "-Wl,-Bsymbolic -static-libstdc++");
}

Expand Down

0 comments on commit 66a7db9

Please sign in to comment.