Skip to content

Commit 1779057

Browse files
committed
Auto merge of #32751 - alexcrichton:dist-docs, r=brson
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.
2 parents bf44003 + 5b29f9a commit 1779057

File tree

7 files changed

+100
-68
lines changed

7 files changed

+100
-68
lines changed

src/bootstrap/Cargo.lock

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/build/compile.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::process::Command;
1515

1616
use build_helper::output;
1717

18-
use build::util::{exe, staticlib, libdir, mtime, is_dylib};
18+
use build::util::{exe, staticlib, libdir, mtime, is_dylib, copy};
1919
use build::{Build, Compiler, Mode};
2020

2121
/// Build the standard library.
@@ -32,8 +32,8 @@ pub fn std<'a>(build: &'a Build, target: &str, compiler: &Compiler<'a>) {
3232
let libdir = build.sysroot_libdir(compiler, target);
3333
let _ = fs::remove_dir_all(&libdir);
3434
t!(fs::create_dir_all(&libdir));
35-
t!(fs::hard_link(&build.compiler_rt_built.borrow()[target],
36-
libdir.join(staticlib("compiler-rt", target))));
35+
copy(&build.compiler_rt_built.borrow()[target],
36+
&libdir.join(staticlib("compiler-rt", target)));
3737

3838
build_startup_objects(build, target, &libdir);
3939

@@ -77,8 +77,8 @@ pub fn std_link(build: &Build,
7777
if host != compiler.host {
7878
let _ = fs::remove_dir_all(&libdir);
7979
t!(fs::create_dir_all(&libdir));
80-
t!(fs::hard_link(&build.compiler_rt_built.borrow()[target],
81-
libdir.join(staticlib("compiler-rt", target))));
80+
copy(&build.compiler_rt_built.borrow()[target],
81+
&libdir.join(staticlib("compiler-rt", target)));
8282
}
8383
add_to_sysroot(&out_dir, &libdir);
8484

@@ -93,7 +93,7 @@ pub fn std_link(build: &Build,
9393
/// Only required for musl targets that statically link to libc
9494
fn copy_third_party_objects(build: &Build, target: &str, into: &Path) {
9595
for &obj in &["crt1.o", "crti.o", "crtn.o"] {
96-
t!(fs::copy(compiler_file(build.cc(target), obj), into.join(obj)));
96+
copy(&compiler_file(build.cc(target), obj), &into.join(obj));
9797
}
9898
}
9999

@@ -119,7 +119,7 @@ fn build_startup_objects(build: &Build, target: &str, into: &Path) {
119119
}
120120

121121
for obj in ["crt2.o", "dllcrt2.o"].iter() {
122-
t!(fs::copy(compiler_file(build.cc(target), obj), into.join(obj)));
122+
copy(&compiler_file(build.cc(target), obj), &into.join(obj));
123123
}
124124
}
125125

@@ -240,9 +240,10 @@ fn libtest_shim(build: &Build, compiler: &Compiler, target: &str) -> PathBuf {
240240
build.cargo_out(compiler, Mode::Libtest, target).join("libtest_shim.rlib")
241241
}
242242

243-
fn compiler_file(compiler: &Path, file: &str) -> String {
244-
output(Command::new(compiler)
245-
.arg(format!("-print-file-name={}", file))).trim().to_string()
243+
fn compiler_file(compiler: &Path, file: &str) -> PathBuf {
244+
let out = output(Command::new(compiler)
245+
.arg(format!("-print-file-name={}", file)));
246+
PathBuf::from(out.trim())
246247
}
247248

248249
/// Prepare a new compiler from the artifacts in `stage`
@@ -270,7 +271,7 @@ pub fn assemble_rustc(build: &Build, stage: u32, host: &str) {
270271
for f in t!(fs::read_dir(&src_libdir)).map(|f| t!(f)) {
271272
let filename = f.file_name().into_string().unwrap();
272273
if is_dylib(&filename) {
273-
t!(fs::hard_link(&f.path(), sysroot_libdir.join(&filename)));
274+
copy(&f.path(), &sysroot_libdir.join(&filename));
274275
}
275276
}
276277

@@ -282,15 +283,15 @@ pub fn assemble_rustc(build: &Build, stage: u32, host: &str) {
282283
t!(fs::create_dir_all(&bindir));
283284
let compiler = build.compiler_path(&Compiler::new(stage, host));
284285
let _ = fs::remove_file(&compiler);
285-
t!(fs::hard_link(rustc, compiler));
286+
copy(&rustc, &compiler);
286287

287288
// See if rustdoc exists to link it into place
288289
let rustdoc = exe("rustdoc", host);
289290
let rustdoc_src = out_dir.join(&rustdoc);
290291
let rustdoc_dst = bindir.join(&rustdoc);
291292
if fs::metadata(&rustdoc_src).is_ok() {
292293
let _ = fs::remove_file(&rustdoc_dst);
293-
t!(fs::hard_link(&rustdoc_src, &rustdoc_dst));
294+
copy(&rustdoc_src, &rustdoc_dst);
294295
}
295296
}
296297

@@ -329,8 +330,7 @@ fn add_to_sysroot(out_dir: &Path, sysroot_dst: &Path) {
329330
let (_, path) = paths.iter().map(|path| {
330331
(mtime(&path).seconds(), path)
331332
}).max().unwrap();
332-
t!(fs::hard_link(&path,
333-
sysroot_dst.join(path.file_name().unwrap())));
333+
copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
334334
}
335335
}
336336

src/bootstrap/build/dist.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn docs(build: &Build, stage: u32, host: &str) {
5252
.arg(format!("--image-dir={}", sanitize_sh(&image)))
5353
.arg(format!("--work-dir={}", sanitize_sh(&tmpdir(build))))
5454
.arg(format!("--output-dir={}", sanitize_sh(&distdir(build))))
55-
.arg(format!("--package-name={}", name))
55+
.arg(format!("--package-name={}-{}", name, host))
5656
.arg("--component-name=rust-docs")
5757
.arg("--legacy-manifest-dirs=rustlib,cargo")
5858
.arg("--bulk-dirs=share/doc/rust/html");
@@ -61,9 +61,11 @@ pub fn docs(build: &Build, stage: u32, host: &str) {
6161

6262
// As part of this step, *also* copy the docs directory to a directory which
6363
// buildbot typically uploads.
64-
let dst = distdir(build).join("doc").join(&build.package_vers);
65-
t!(fs::create_dir_all(&dst));
66-
cp_r(&src, &dst);
64+
if host == build.config.build {
65+
let dst = distdir(build).join("doc").join(&build.package_vers);
66+
t!(fs::create_dir_all(&dst));
67+
cp_r(&src, &dst);
68+
}
6769
}
6870

6971
pub fn mingw(build: &Build, host: &str) {

src/bootstrap/build/doc.rs

+26-24
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,30 @@ use std::process::Command;
1616
use build::{Build, Compiler, Mode};
1717
use build::util::{up_to_date, cp_r};
1818

19-
pub fn rustbook(build: &Build, stage: u32, host: &str, name: &str, out: &Path) {
19+
pub fn rustbook(build: &Build, stage: u32, target: &str, name: &str, out: &Path) {
2020
t!(fs::create_dir_all(out));
2121

2222
let out = out.join(name);
23-
let compiler = Compiler::new(stage, host);
23+
let compiler = Compiler::new(stage, &build.config.build);
2424
let src = build.src.join("src/doc").join(name);
2525
let index = out.join("index.html");
2626
let rustbook = build.tool(&compiler, "rustbook");
2727
if up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
2828
return
2929
}
30-
println!("Rustbook stage{} ({}) - {}", stage, host, name);
30+
println!("Rustbook stage{} ({}) - {}", stage, target, name);
3131
let _ = fs::remove_dir_all(&out);
3232
build.run(build.tool_cmd(&compiler, "rustbook")
3333
.arg("build")
3434
.arg(&src)
3535
.arg(out));
3636
}
3737

38-
pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) {
39-
println!("Documenting stage{} standalone ({})", stage, host);
38+
pub fn standalone(build: &Build, stage: u32, target: &str, out: &Path) {
39+
println!("Documenting stage{} standalone ({})", stage, target);
4040
t!(fs::create_dir_all(out));
4141

42-
let compiler = Compiler::new(stage, host);
42+
let compiler = Compiler::new(stage, &build.config.build);
4343

4444
let favicon = build.src.join("src/doc/favicon.inc");
4545
let footer = build.src.join("src/doc/footer.inc");
@@ -105,59 +105,61 @@ pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) {
105105
}
106106
}
107107

108-
pub fn std(build: &Build, stage: u32, host: &str, out: &Path) {
109-
println!("Documenting stage{} std ({})", stage, host);
110-
let compiler = Compiler::new(stage, host);
108+
pub fn std(build: &Build, stage: u32, target: &str, out: &Path) {
109+
println!("Documenting stage{} std ({})", stage, target);
110+
t!(fs::create_dir_all(out));
111+
let compiler = Compiler::new(stage, &build.config.build);
111112
let out_dir = build.stage_out(&compiler, Mode::Libstd)
112-
.join(host).join("doc");
113+
.join(target).join("doc");
113114
let rustdoc = build.rustdoc(&compiler);
114115

115116
build.clear_if_dirty(&out_dir, &rustdoc);
116117

117-
let mut cargo = build.cargo(&compiler, Mode::Libstd, host, "doc");
118+
let mut cargo = build.cargo(&compiler, Mode::Libstd, target, "doc");
118119
cargo.arg("--manifest-path")
119120
.arg(build.src.join("src/rustc/std_shim/Cargo.toml"))
120121
.arg("--features").arg(build.std_features());
121122
build.run(&mut cargo);
122123
cp_r(&out_dir, out)
123124
}
124125

125-
pub fn test(build: &Build, stage: u32, host: &str, out: &Path) {
126-
println!("Documenting stage{} test ({})", stage, host);
127-
let compiler = Compiler::new(stage, host);
126+
pub fn test(build: &Build, stage: u32, target: &str, out: &Path) {
127+
println!("Documenting stage{} test ({})", stage, target);
128+
let compiler = Compiler::new(stage, &build.config.build);
128129
let out_dir = build.stage_out(&compiler, Mode::Libtest)
129-
.join(host).join("doc");
130+
.join(target).join("doc");
130131
let rustdoc = build.rustdoc(&compiler);
131132

132133
build.clear_if_dirty(&out_dir, &rustdoc);
133134

134-
let mut cargo = build.cargo(&compiler, Mode::Libtest, host, "doc");
135+
let mut cargo = build.cargo(&compiler, Mode::Libtest, target, "doc");
135136
cargo.arg("--manifest-path")
136137
.arg(build.src.join("src/rustc/test_shim/Cargo.toml"));
137138
build.run(&mut cargo);
138139
cp_r(&out_dir, out)
139140
}
140141

141-
pub fn rustc(build: &Build, stage: u32, host: &str, out: &Path) {
142-
println!("Documenting stage{} compiler ({})", stage, host);
143-
let compiler = Compiler::new(stage, host);
142+
pub fn rustc(build: &Build, stage: u32, target: &str, out: &Path) {
143+
println!("Documenting stage{} compiler ({})", stage, target);
144+
let compiler = Compiler::new(stage, &build.config.build);
144145
let out_dir = build.stage_out(&compiler, Mode::Librustc)
145-
.join(host).join("doc");
146+
.join(target).join("doc");
146147
let rustdoc = build.rustdoc(&compiler);
147148
if !up_to_date(&rustdoc, &out_dir.join("rustc/index.html")) {
148149
t!(fs::remove_dir_all(&out_dir));
149150
}
150-
let mut cargo = build.cargo(&compiler, Mode::Librustc, host, "doc");
151+
let mut cargo = build.cargo(&compiler, Mode::Librustc, target, "doc");
151152
cargo.arg("--manifest-path")
152153
.arg(build.src.join("src/rustc/Cargo.toml"))
153154
.arg("--features").arg(build.rustc_features());
154155
build.run(&mut cargo);
155156
cp_r(&out_dir, out)
156157
}
157158

158-
pub fn error_index(build: &Build, stage: u32, host: &str, out: &Path) {
159-
println!("Documenting stage{} error index ({})", stage, host);
160-
let compiler = Compiler::new(stage, host);
159+
pub fn error_index(build: &Build, stage: u32, target: &str, out: &Path) {
160+
println!("Documenting stage{} error index ({})", stage, target);
161+
t!(fs::create_dir_all(out));
162+
let compiler = Compiler::new(stage, &build.config.build);
161163
let mut index = build.tool_cmd(&compiler, "error_index_generator");
162164
index.arg("html");
163165
index.arg(out.join("error-index.html"));

src/bootstrap/build/sanity.rs

+12
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,16 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
119119
}
120120
}
121121
}
122+
123+
for host in build.flags.host.iter() {
124+
if !build.config.host.contains(host) {
125+
panic!("specified host `{}` is not in the ./configure list", host);
126+
}
127+
}
128+
for target in build.flags.target.iter() {
129+
if !build.config.target.contains(target) {
130+
panic!("specified target `{}` is not in the ./configure list",
131+
target);
132+
}
133+
}
122134
}

0 commit comments

Comments
 (0)