Skip to content

Commit 66a7db9

Browse files
committed
make a llvm-tools rustup component
1 parent 8e67307 commit 66a7db9

File tree

6 files changed

+103
-44
lines changed

6 files changed

+103
-44
lines changed

src/bootstrap/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ impl<'a> Builder<'a> {
451451
dist::Cargo,
452452
dist::Rls,
453453
dist::Rustfmt,
454+
dist::LlvmTools,
454455
dist::Extended,
455456
dist::HashSign
456457
),

src/bootstrap/compile.rs

Lines changed: 1 addition & 21 deletions
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, LLVM_TOOLS};
34+
use {Compiler, Mode};
3535
use native;
3636
use tool;
3737

@@ -775,23 +775,6 @@ 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-
795778
fn copy_lld_to_sysroot(builder: &Builder,
796779
target_compiler: Compiler,
797780
lld_install_root: &Path) {
@@ -983,9 +966,6 @@ impl Step for Assemble {
983966
copy_codegen_backends_to_sysroot(builder,
984967
build_compiler,
985968
target_compiler);
986-
if builder.config.ship_llvm_tools {
987-
copy_llvm_tools_to_sysroot(builder, target_compiler);
988-
}
989969
if let Some(lld_install) = lld_install {
990970
copy_lld_to_sysroot(builder, target_compiler, &lld_install);
991971
}

src/bootstrap/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub struct Config {
8888
pub llvm_link_jobs: Option<u32>,
8989

9090
pub lld_enabled: bool,
91-
pub ship_llvm_tools: bool,
91+
pub llvm_tools_enabled: bool,
9292

9393
// rust codegen options
9494
pub rust_optimize: bool,
@@ -533,7 +533,7 @@ impl Config {
533533
set(&mut config.test_miri, rust.test_miri);
534534
set(&mut config.wasm_syscall, rust.wasm_syscall);
535535
set(&mut config.lld_enabled, rust.lld);
536-
set(&mut config.ship_llvm_tools, rust.llvm_tools);
536+
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
537537
config.rustc_parallel_queries = rust.experimental_parallel_queries.unwrap_or(false);
538538
config.rustc_default_linker = rust.default_linker.clone();
539539
config.musl_root = rust.musl_root.clone().map(PathBuf::from);

src/bootstrap/dist.rs

Lines changed: 79 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub fn pkgname(builder: &Builder, component: &str) -> String {
4343
format!("{}-{}", component, builder.rls_package_vers())
4444
} else if component == "rustfmt" {
4545
format!("{}-{}", component, builder.rustfmt_package_vers())
46+
} else if component == "llvm-tools" {
47+
format!("{}-{}", component, builder.llvm_tools_vers())
4648
} else {
4749
assert!(component.starts_with("rust"));
4850
format!("{}-{}", component, builder.rust_package_vers())
@@ -394,7 +396,7 @@ impl Step for Rustc {
394396
let compiler = self.compiler;
395397
let host = self.compiler.host;
396398

397-
builder.info(&format!("Dist rustc stage{} ({})", compiler.stage, compiler.host));
399+
builder.info(&format!("Dist rustc stage{} ({})", compiler.stage, host));
398400
let name = pkgname(builder, "rustc");
399401
let image = tmpdir(builder).join(format!("{}-{}-image", name, host));
400402
let _ = fs::remove_dir_all(&image);
@@ -503,24 +505,6 @@ impl Step for Rustc {
503505
builder.copy(&src, &dst);
504506
}
505507

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-
524508
// Man pages
525509
t!(fs::create_dir_all(image.join("share/man/man1")));
526510
let man_src = builder.src.join("src/doc/man");
@@ -1756,6 +1740,7 @@ impl Step for HashSign {
17561740
cmd.arg(builder.package_vers(&builder.release_num("cargo")));
17571741
cmd.arg(builder.package_vers(&builder.release_num("rls")));
17581742
cmd.arg(builder.package_vers(&builder.release_num("rustfmt")));
1743+
cmd.arg(builder.llvm_tools_vers());
17591744
cmd.arg(addr);
17601745

17611746
builder.create_dir(&distdir(builder));
@@ -1766,3 +1751,78 @@ impl Step for HashSign {
17661751
assert!(status.success());
17671752
}
17681753
}
1754+
1755+
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
1756+
pub struct LlvmTools {
1757+
pub stage: u32,
1758+
pub compiler: Compiler,
1759+
pub target: Interned<String>,
1760+
}
1761+
1762+
impl Step for LlvmTools {
1763+
type Output = Option<PathBuf>;
1764+
const ONLY_HOSTS: bool = true;
1765+
1766+
fn should_run(run: ShouldRun) -> ShouldRun {
1767+
run.path("llvm-tools")
1768+
}
1769+
1770+
fn make_run(run: RunConfig) {
1771+
run.builder.ensure(LlvmTools {
1772+
stage: run.builder.top_stage,
1773+
compiler: run.builder.compiler(run.builder.top_stage, run.target),
1774+
target: run.target,
1775+
});
1776+
}
1777+
1778+
fn run(self, builder: &Builder) -> Option<PathBuf> {
1779+
let compiler = self.compiler;
1780+
let host = compiler.host;
1781+
1782+
let stage = self.stage;
1783+
assert!(builder.config.extended);
1784+
1785+
builder.info(&format!("Dist LlvmTools stage{} ({})", stage, host));
1786+
let src = builder.src.join("src/llvm");
1787+
let name = pkgname(builder, "llvm-tools");
1788+
1789+
let tmp = tmpdir(builder);
1790+
let image = tmp.join("llvm-tools-image");
1791+
drop(fs::remove_dir_all(&image));
1792+
t!(fs::create_dir_all(&image.join("bin")));
1793+
1794+
// Prepare the image directory
1795+
for tool in LLVM_TOOLS {
1796+
let exe = builder
1797+
.llvm_out(host)
1798+
.join("bin")
1799+
.join(exe(tool, &compiler.host));
1800+
builder.install(&exe, &image.join("bin"), 0o755);
1801+
}
1802+
1803+
// Prepare the overlay
1804+
let overlay = tmp.join("llvm-tools-overlay");
1805+
drop(fs::remove_dir_all(&overlay));
1806+
builder.create_dir(&overlay);
1807+
builder.install(&src.join("README.txt"), &overlay, 0o644);
1808+
builder.install(&src.join("LICENSE.TXT"), &overlay, 0o644);
1809+
1810+
// Generate the installer tarball
1811+
let mut cmd = rust_installer(builder);
1812+
cmd.arg("generate")
1813+
.arg("--product-name=Rust")
1814+
.arg("--rel-manifest-dir=rustlib")
1815+
.arg("--success-message=llvm-tools-installed.")
1816+
.arg("--image-dir").arg(&image)
1817+
.arg("--work-dir").arg(&tmpdir(builder))
1818+
.arg("--output-dir").arg(&distdir(builder))
1819+
.arg("--non-installed-overlay").arg(&overlay)
1820+
.arg(format!("--package-name={}-{}", name, host))
1821+
.arg("--legacy-manifest-dirs=rustlib,cargo")
1822+
.arg("--component-name=llvm-tools");
1823+
1824+
1825+
builder.run(&mut cmd);
1826+
Some(distdir(builder).join(format!("{}-{}.tar.gz", name, host)))
1827+
}
1828+
}

src/bootstrap/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,24 @@ impl Build {
957957
self.package_vers(&self.release_num("rustfmt"))
958958
}
959959

960+
fn llvm_tools_vers(&self) -> String {
961+
let stdout = build_helper::output(
962+
Command::new(self.llvm_out(self.config.build).join("build/bin/llvm-size"))
963+
.arg("--version"),
964+
);
965+
966+
for line in stdout.lines() {
967+
if line.contains("LLVM version") {
968+
if let Some(vers) = line.split_whitespace().nth(2) {
969+
return vers.to_string();
970+
}
971+
}
972+
}
973+
974+
panic!("The output of $LLVM_TOOL has changed; \
975+
please fix `bootstrap::Build.llvm_tools_vers`");
976+
}
977+
960978
/// Returns the `version` string associated with this compiler for Rust
961979
/// itself.
962980
///

src/bootstrap/native.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ impl Step for Llvm {
170170
//
171171
// If we are shipping llvm tools then we statically link them LLVM
172172
if (target.contains("linux-gnu") || target.contains("apple-darwin")) &&
173-
!builder.config.ship_llvm_tools {
173+
!builder.config.llvm_tools_enabled {
174174
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
175175
}
176176

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

0 commit comments

Comments
 (0)