From c86e7c49500d7abc03f1377997b445896c74f020 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 Apr 2016 10:00:25 -0700 Subject: [PATCH 1/4] rustbuild: Add helper to abstract hard_link/copy Also helps provide context if it fails. --- src/bootstrap/build/compile.rs | 30 +++++++++++++++--------------- src/bootstrap/build/util.rs | 11 ++++++++++- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/bootstrap/build/compile.rs b/src/bootstrap/build/compile.rs index dee586c769936..a67f1ba48b560 100644 --- a/src/bootstrap/build/compile.rs +++ b/src/bootstrap/build/compile.rs @@ -15,7 +15,7 @@ use std::process::Command; use build_helper::output; -use build::util::{exe, staticlib, libdir, mtime, is_dylib}; +use build::util::{exe, staticlib, libdir, mtime, is_dylib, copy}; use build::{Build, Compiler, Mode}; /// Build the standard library. @@ -32,8 +32,8 @@ pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) { let libdir = build.sysroot_libdir(compiler, target); let _ = fs::remove_dir_all(&libdir); t!(fs::create_dir_all(&libdir)); - t!(fs::hard_link(&build.compiler_rt_built.borrow()[target], - libdir.join(staticlib("compiler-rt", target)))); + copy(&build.compiler_rt_built.borrow()[target], + &libdir.join(staticlib("compiler-rt", target))); build_startup_objects(build, target, &libdir); @@ -77,8 +77,8 @@ pub fn std_link(build: &Build, if host != compiler.host { let _ = fs::remove_dir_all(&libdir); t!(fs::create_dir_all(&libdir)); - t!(fs::hard_link(&build.compiler_rt_built.borrow()[target], - libdir.join(staticlib("compiler-rt", target)))); + copy(&build.compiler_rt_built.borrow()[target], + &libdir.join(staticlib("compiler-rt", target))); } add_to_sysroot(&out_dir, &libdir); @@ -93,7 +93,7 @@ pub fn std_link(build: &Build, /// Only required for musl targets that statically link to libc fn copy_third_party_objects(build: &Build, target: &str, into: &Path) { for &obj in &["crt1.o", "crti.o", "crtn.o"] { - t!(fs::copy(compiler_file(build.cc(target), obj), into.join(obj))); + copy(&compiler_file(build.cc(target), obj), &into.join(obj)); } } @@ -119,7 +119,7 @@ fn build_startup_objects(build: &Build, target: &str, into: &Path) { } for obj in ["crt2.o", "dllcrt2.o"].iter() { - t!(fs::copy(compiler_file(build.cc(target), obj), into.join(obj))); + copy(&compiler_file(build.cc(target), obj), &into.join(obj)); } } @@ -240,9 +240,10 @@ fn libtest_shim(build: &Build, compiler: &Compiler, target: &str) -> PathBuf { build.cargo_out(compiler, Mode::Libtest, target).join("libtest_shim.rlib") } -fn compiler_file(compiler: &Path, file: &str) -> String { - output(Command::new(compiler) - .arg(format!("-print-file-name={}", file))).trim().to_string() +fn compiler_file(compiler: &Path, file: &str) -> PathBuf { + let out = output(Command::new(compiler) + .arg(format!("-print-file-name={}", file))); + PathBuf::from(out.trim()) } /// Prepare a new compiler from the artifacts in `stage` @@ -270,7 +271,7 @@ pub fn assemble_rustc(build: &Build, stage: u32, host: &str) { for f in t!(fs::read_dir(&src_libdir)).map(|f| t!(f)) { let filename = f.file_name().into_string().unwrap(); if is_dylib(&filename) { - t!(fs::hard_link(&f.path(), sysroot_libdir.join(&filename))); + copy(&f.path(), &sysroot_libdir.join(&filename)); } } @@ -282,7 +283,7 @@ pub fn assemble_rustc(build: &Build, stage: u32, host: &str) { t!(fs::create_dir_all(&bindir)); let compiler = build.compiler_path(&Compiler::new(stage, host)); let _ = fs::remove_file(&compiler); - t!(fs::hard_link(rustc, compiler)); + copy(&rustc, &compiler); // See if rustdoc exists to link it into place let rustdoc = exe("rustdoc", host); @@ -290,7 +291,7 @@ pub fn assemble_rustc(build: &Build, stage: u32, host: &str) { let rustdoc_dst = bindir.join(&rustdoc); if fs::metadata(&rustdoc_src).is_ok() { let _ = fs::remove_file(&rustdoc_dst); - t!(fs::hard_link(&rustdoc_src, &rustdoc_dst)); + copy(&rustdoc_src, &rustdoc_dst); } } @@ -329,8 +330,7 @@ fn add_to_sysroot(out_dir: &Path, sysroot_dst: &Path) { let (_, path) = paths.iter().map(|path| { (mtime(&path).seconds(), path) }).max().unwrap(); - t!(fs::hard_link(&path, - sysroot_dst.join(path.file_name().unwrap()))); + copy(&path, &sysroot_dst.join(path.file_name().unwrap())); } } diff --git a/src/bootstrap/build/util.rs b/src/bootstrap/build/util.rs index 35d22ee5d2658..41cf924d44a92 100644 --- a/src/bootstrap/build/util.rs +++ b/src/bootstrap/build/util.rs @@ -30,6 +30,15 @@ pub fn mtime(path: &Path) -> FileTime { }).unwrap_or(FileTime::zero()) } +pub fn copy(src: &Path, dst: &Path) { + let res = fs::hard_link(src, dst); + let res = res.or_else(|_| fs::copy(src, dst).map(|_| ())); + if let Err(e) = res { + panic!("failed to copy `{}` to `{}`: {}", src.display(), + dst.display(), e) + } +} + pub fn cp_r(src: &Path, dst: &Path) { for f in t!(fs::read_dir(src)) { let f = t!(f); @@ -42,7 +51,7 @@ pub fn cp_r(src: &Path, dst: &Path) { cp_r(&path, &dst); } else { let _ = fs::remove_file(&dst); - t!(fs::hard_link(&path, dst)); + copy(&path, &dst); } } } From 4e758722f4f9ccf9054ebf179b8630a37ce954f1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 Apr 2016 10:00:51 -0700 Subject: [PATCH 2/4] rustbuild: Verify flags are configured Building with `--target foo` should fail because that target wasn't actually validated. --- src/bootstrap/build/sanity.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bootstrap/build/sanity.rs b/src/bootstrap/build/sanity.rs index be4416c697c56..6ce2749638841 100644 --- a/src/bootstrap/build/sanity.rs +++ b/src/bootstrap/build/sanity.rs @@ -119,4 +119,16 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake } } } + + for host in build.flags.host.iter() { + if !build.config.host.contains(host) { + panic!("specified host `{}` is not in the ./configure list", host); + } + } + for target in build.flags.target.iter() { + if !build.config.target.contains(target) { + panic!("specified target `{}` is not in the ./configure list", + target); + } + } } From d78063dd8459f71b9bd87d6a59a142598ba79573 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 Apr 2016 10:01:31 -0700 Subject: [PATCH 3/4] rustbuild: Support cross rust-docs packages Right now if you configure multiple hosts rustbuild will only build documentation for the build triple, but we've got all the support necessary to build documentation for different architectures as well. This commit reinterprets the `target` field of doc `Step` instances to be the target of the documentation rather than the target of the rustdoc/tool being run. This should enable `make dist` to start producing a bunch of `rust-docs` packages for all the cross architectures that rustbuild is producing now. --- src/bootstrap/build/dist.rs | 10 +++++--- src/bootstrap/build/doc.rs | 50 +++++++++++++++++++------------------ src/bootstrap/build/step.rs | 21 ++++++++++------ 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/bootstrap/build/dist.rs b/src/bootstrap/build/dist.rs index 855528ea4409f..6ae652bd66da6 100644 --- a/src/bootstrap/build/dist.rs +++ b/src/bootstrap/build/dist.rs @@ -52,7 +52,7 @@ pub fn docs(build: &Build, stage: u32, host: &str) { .arg(format!("--image-dir={}", sanitize_sh(&image))) .arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build)))) .arg(format!("--output-dir={}", sanitize_sh(&distdir(build)))) - .arg(format!("--package-name={}", name)) + .arg(format!("--package-name={}-{}", name, host)) .arg("--component-name=rust-docs") .arg("--legacy-manifest-dirs=rustlib,cargo") .arg("--bulk-dirs=share/doc/rust/html"); @@ -61,9 +61,11 @@ pub fn docs(build: &Build, stage: u32, host: &str) { // As part of this step, *also* copy the docs directory to a directory which // buildbot typically uploads. - let dst = distdir(build).join("doc").join(&build.package_vers); - t!(fs::create_dir_all(&dst)); - cp_r(&src, &dst); + if host == build.config.build { + let dst = distdir(build).join("doc").join(&build.package_vers); + t!(fs::create_dir_all(&dst)); + cp_r(&src, &dst); + } } pub fn mingw(build: &Build, host: &str) { diff --git a/src/bootstrap/build/doc.rs b/src/bootstrap/build/doc.rs index 50c0c56807bc2..5782dd5ec28dd 100644 --- a/src/bootstrap/build/doc.rs +++ b/src/bootstrap/build/doc.rs @@ -16,18 +16,18 @@ use std::process::Command; use build::{Build, Compiler, Mode}; use build::util::{up_to_date, cp_r}; -pub fn rustbook(build: &Build, stage: u32, host: &str, name: &str, out: &Path) { +pub fn rustbook(build: &Build, stage: u32, target: &str, name: &str, out: &Path) { t!(fs::create_dir_all(out)); let out = out.join(name); - let compiler = Compiler::new(stage, host); + let compiler = Compiler::new(stage, &build.config.build); let src = build.src.join("src/doc").join(name); let index = out.join("index.html"); let rustbook = build.tool(&compiler, "rustbook"); if up_to_date(&src, &index) && up_to_date(&rustbook, &index) { return } - println!("Rustbook stage{} ({}) - {}", stage, host, name); + println!("Rustbook stage{} ({}) - {}", stage, target, name); let _ = fs::remove_dir_all(&out); build.run(build.tool_cmd(&compiler, "rustbook") .arg("build") @@ -35,11 +35,11 @@ pub fn rustbook(build: &Build, stage: u32, host: &str, name: &str, out: &Path) { .arg(out)); } -pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) { - println!("Documenting stage{} standalone ({})", stage, host); +pub fn standalone(build: &Build, stage: u32, target: &str, out: &Path) { + println!("Documenting stage{} standalone ({})", stage, target); t!(fs::create_dir_all(out)); - let compiler = Compiler::new(stage, host); + let compiler = Compiler::new(stage, &build.config.build); let favicon = build.src.join("src/doc/favicon.inc"); let footer = build.src.join("src/doc/footer.inc"); @@ -105,16 +105,17 @@ pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) { } } -pub fn std(build: &Build, stage: u32, host: &str, out: &Path) { - println!("Documenting stage{} std ({})", stage, host); - let compiler = Compiler::new(stage, host); +pub fn std(build: &Build, stage: u32, target: &str, out: &Path) { + println!("Documenting stage{} std ({})", stage, target); + t!(fs::create_dir_all(out)); + let compiler = Compiler::new(stage, &build.config.build); let out_dir = build.stage_out(&compiler, Mode::Libstd) - .join(host).join("doc"); + .join(target).join("doc"); let rustdoc = build.rustdoc(&compiler); build.clear_if_dirty(&out_dir, &rustdoc); - let mut cargo = build.cargo(&compiler, Mode::Libstd, host, "doc"); + let mut cargo = build.cargo(&compiler, Mode::Libstd, target, "doc"); cargo.arg("--manifest-path") .arg(build.src.join("src/rustc/std_shim/Cargo.toml")) .arg("--features").arg(build.std_features()); @@ -122,32 +123,32 @@ pub fn std(build: &Build, stage: u32, host: &str, out: &Path) { cp_r(&out_dir, out) } -pub fn test(build: &Build, stage: u32, host: &str, out: &Path) { - println!("Documenting stage{} test ({})", stage, host); - let compiler = Compiler::new(stage, host); +pub fn test(build: &Build, stage: u32, target: &str, out: &Path) { + println!("Documenting stage{} test ({})", stage, target); + let compiler = Compiler::new(stage, &build.config.build); let out_dir = build.stage_out(&compiler, Mode::Libtest) - .join(host).join("doc"); + .join(target).join("doc"); let rustdoc = build.rustdoc(&compiler); build.clear_if_dirty(&out_dir, &rustdoc); - let mut cargo = build.cargo(&compiler, Mode::Libtest, host, "doc"); + let mut cargo = build.cargo(&compiler, Mode::Libtest, target, "doc"); cargo.arg("--manifest-path") .arg(build.src.join("src/rustc/test_shim/Cargo.toml")); build.run(&mut cargo); cp_r(&out_dir, out) } -pub fn rustc(build: &Build, stage: u32, host: &str, out: &Path) { - println!("Documenting stage{} compiler ({})", stage, host); - let compiler = Compiler::new(stage, host); +pub fn rustc(build: &Build, stage: u32, target: &str, out: &Path) { + println!("Documenting stage{} compiler ({})", stage, target); + let compiler = Compiler::new(stage, &build.config.build); let out_dir = build.stage_out(&compiler, Mode::Librustc) - .join(host).join("doc"); + .join(target).join("doc"); let rustdoc = build.rustdoc(&compiler); if !up_to_date(&rustdoc, &out_dir.join("rustc/index.html")) { t!(fs::remove_dir_all(&out_dir)); } - let mut cargo = build.cargo(&compiler, Mode::Librustc, host, "doc"); + let mut cargo = build.cargo(&compiler, Mode::Librustc, target, "doc"); cargo.arg("--manifest-path") .arg(build.src.join("src/rustc/Cargo.toml")) .arg("--features").arg(build.rustc_features()); @@ -155,9 +156,10 @@ pub fn rustc(build: &Build, stage: u32, host: &str, out: &Path) { cp_r(&out_dir, out) } -pub fn error_index(build: &Build, stage: u32, host: &str, out: &Path) { - println!("Documenting stage{} error index ({})", stage, host); - let compiler = Compiler::new(stage, host); +pub fn error_index(build: &Build, stage: u32, target: &str, out: &Path) { + println!("Documenting stage{} error index ({})", stage, target); + t!(fs::create_dir_all(out)); + let compiler = Compiler::new(stage, &build.config.build); let mut index = build.tool_cmd(&compiler, "error_index_generator"); index.arg("html"); index.arg(out.join("error-index.html")); diff --git a/src/bootstrap/build/step.rs b/src/bootstrap/build/step.rs index 4e3aacd3720ff..a185a65975fdd 100644 --- a/src/bootstrap/build/step.rs +++ b/src/bootstrap/build/step.rs @@ -274,22 +274,28 @@ impl<'a> Step<'a> { vec![self.llvm(()).target(&build.config.build)] } Source::Llvm { _dummy } => Vec::new(), + + // Note that all doc targets depend on artifacts from the build + // architecture, not the target (which is where we're generating + // docs into). Source::DocStd { stage } => { - vec![self.libstd(self.compiler(stage))] + let compiler = self.target(&build.config.build).compiler(stage); + vec![self.libstd(compiler)] } Source::DocTest { stage } => { - vec![self.libtest(self.compiler(stage))] + let compiler = self.target(&build.config.build).compiler(stage); + vec![self.libtest(compiler)] } Source::DocBook { stage } | Source::DocNomicon { stage } | Source::DocStyle { stage } => { - vec![self.tool_rustbook(stage)] + vec![self.target(&build.config.build).tool_rustbook(stage)] } Source::DocErrorIndex { stage } => { - vec![self.tool_error_index(stage)] + vec![self.target(&build.config.build).tool_error_index(stage)] } Source::DocStandalone { stage } => { - vec![self.rustc(stage)] + vec![self.target(&build.config.build).rustc(stage)] } Source::DocRustc { stage } => { vec![self.doc_test(stage)] @@ -333,7 +339,6 @@ impl<'a> Step<'a> { Source::Dist { stage } => { let mut base = Vec::new(); - base.push(self.dist_docs(stage)); for host in build.config.host.iter() { let host = self.target(host); @@ -344,7 +349,9 @@ impl<'a> Step<'a> { let compiler = self.compiler(stage); for target in build.config.target.iter() { - base.push(self.target(target).dist_std(compiler)); + let target = self.target(target); + base.push(target.dist_docs(stage)); + base.push(target.dist_std(compiler)); } } return base From 5b29f9a9b069fb7b7ef5adaaa6ca0549e8f3aa14 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 Apr 2016 10:03:24 -0700 Subject: [PATCH 4/4] rustbuild: Update bootstrap dependencies Not much new, just bringing everything along. --- src/bootstrap/Cargo.lock | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock index 05186d48ce2d1..c33838a146c2c 100644 --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock @@ -3,16 +3,16 @@ name = "bootstrap" version = "0.0.0" dependencies = [ "build_helper 0.1.0", - "cmake 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "cmake 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -21,10 +21,10 @@ version = "0.1.0" [[package]] name = "cmake" -version = "0.1.13" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.25 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -32,12 +32,12 @@ name = "filetime" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "gcc" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -50,13 +50,13 @@ name = "kernel32-sys" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libc" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -64,25 +64,25 @@ name = "num_cpus" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-serialize" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "toml" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "winapi" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]]