Skip to content

Commit dc1f829

Browse files
committed
Auto merge of rust-lang#95440 - jyn514:error-index, r=Mark-Simulacrum
Fix `x test src/tools/error_index_generator --stage {0,1}` There were two fixes needed: 1. Use `top_stage` instead of `top_stage - 1`. There was a long and torturous comment about trying to match rustdoc's version, but it works better without the hard-coding than with (before it gave errors that `libtest.so` couldn't be found). 2. Make sure that `ci-llvm/lib` is added to LD_LIBRARY_PATH. Previously the error index would be unable to load LLVM for stage0 builds. At some point we should probably have a discussion about how rustdoc stages should be numbered; confusion between 0/1/2 has come up several times in bootstrap now. cc rust-lang#92538 Note that this is still broken when using `download-rustc = true` and `--stage 1`, but that's *really* a corner case and should affect almost no one. `--stage {0,2}` work fine with download-rustc. Fixes rust-lang#80096.
2 parents e745b4d + 7470592 commit dc1f829

File tree

5 files changed

+44
-58
lines changed

5 files changed

+44
-58
lines changed

src/bootstrap/builder.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,18 @@ impl<'a> Builder<'a> {
835835
}
836836
}
837837

838+
pub fn rustc_lib_paths(&self, compiler: Compiler) -> Vec<PathBuf> {
839+
let mut dylib_dirs = vec![self.rustc_libdir(compiler)];
840+
841+
// Ensure that the downloaded LLVM libraries can be found.
842+
if self.config.llvm_from_ci {
843+
let ci_llvm_lib = self.out.join(&*compiler.host.triple).join("ci-llvm").join("lib");
844+
dylib_dirs.push(ci_llvm_lib);
845+
}
846+
847+
dylib_dirs
848+
}
849+
838850
/// Adds the compiler's directory of dynamic libraries to `cmd`'s dynamic
839851
/// library lookup path.
840852
pub fn add_rustc_lib_path(&self, compiler: Compiler, cmd: &mut Command) {
@@ -845,15 +857,7 @@ impl<'a> Builder<'a> {
845857
return;
846858
}
847859

848-
let mut dylib_dirs = vec![self.rustc_libdir(compiler)];
849-
850-
// Ensure that the downloaded LLVM libraries can be found.
851-
if self.config.llvm_from_ci {
852-
let ci_llvm_lib = self.out.join(&*compiler.host.triple).join("ci-llvm").join("lib");
853-
dylib_dirs.push(ci_llvm_lib);
854-
}
855-
856-
add_dylib_path(dylib_dirs, cmd);
860+
add_dylib_path(self.rustc_lib_paths(compiler), cmd);
857861
}
858862

859863
/// Gets a path to the compiler specified.

src/bootstrap/tool.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -379,22 +379,14 @@ pub struct ErrorIndex {
379379

380380
impl ErrorIndex {
381381
pub fn command(builder: &Builder<'_>) -> Command {
382-
// This uses stage-1 to match the behavior of building rustdoc.
383-
// Error-index-generator links with the rustdoc library, so we want to
384-
// use the same librustdoc to avoid building rustdoc twice (and to
385-
// avoid building the compiler an extra time). This uses
386-
// saturating_sub to deal with building with stage 0. (Using stage 0
387-
// isn't recommended, since it will fail if any new error index tests
388-
// use new syntax, but it should work otherwise.)
389-
let compiler = builder.compiler(builder.top_stage.saturating_sub(1), builder.config.build);
382+
// Error-index-generator links with the rustdoc library, so we need to add `rustc_lib_paths`
383+
// for rustc_private and libLLVM.so, and `sysroot_lib` for libstd, etc.
384+
let host = builder.config.build;
385+
let compiler = builder.compiler_for(builder.top_stage, host, host);
390386
let mut cmd = Command::new(builder.ensure(ErrorIndex { compiler }));
391-
add_dylib_path(
392-
vec![
393-
PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host)),
394-
builder.rustc_libdir(compiler),
395-
],
396-
&mut cmd,
397-
);
387+
let mut dylib_paths = builder.rustc_lib_paths(compiler);
388+
dylib_paths.push(PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host)));
389+
add_dylib_path(dylib_paths, &mut cmd);
398390
cmd
399391
}
400392
}

src/bootstrap/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn libdir(target: TargetSelection) -> &'static str {
6363
}
6464

6565
/// Adds a list of lookup paths to `cmd`'s dynamic library lookup path.
66-
/// If The dylib_path_par is already set for this cmd, the old value will be overwritten!
66+
/// If the dylib_path_var is already set for this cmd, the old value will be overwritten!
6767
pub fn add_dylib_path(path: Vec<PathBuf>, cmd: &mut Command) {
6868
let mut list = dylib_path();
6969
for path in path {

src/tools/error_index_generator/build.rs

-32
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ fn main() {
77
// Note that we could skip one of the .. but this ensures we at least loosely find the right
88
// directory.
99
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
10-
let dest = out_dir.join("error_codes.rs");
1110

1211
let error_codes_path = "../../../compiler/rustc_error_codes/src/error_codes.rs";
1312

@@ -29,35 +28,4 @@ fn main() {
2928
let md_content = fs::read_to_string(entry.path()).unwrap();
3029
fs::write(&out_dir.join(entry.file_name()), &md_content).unwrap();
3130
}
32-
33-
let mut all = String::new();
34-
all.push_str(
35-
r###"
36-
fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
37-
let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();
38-
macro_rules! register_diagnostics {
39-
($($ecode:ident: $message:expr,)*) => (
40-
register_diagnostics!{$($ecode:$message,)* ;}
41-
);
42-
43-
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
44-
$(
45-
{long_codes.extend([
46-
(stringify!($ecode), Some($message)),
47-
].iter());}
48-
)*
49-
$(
50-
{long_codes.extend([
51-
stringify!($code),
52-
].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
53-
)*
54-
)
55-
}
56-
"###,
57-
);
58-
all.push_str(r#"include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));"#);
59-
all.push_str("\nlong_codes\n");
60-
all.push_str("}\n");
61-
62-
fs::write(&dest, all).unwrap();
6331
}

src/tools/error_index_generator/main.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,26 @@ fn main() {
277277
}
278278
}
279279

280-
include!(concat!(env!("OUT_DIR"), "/error_codes.rs"));
280+
fn register_all() -> Vec<(&'static str, Option<&'static str>)> {
281+
let mut long_codes: Vec<(&'static str, Option<&'static str>)> = Vec::new();
282+
macro_rules! register_diagnostics {
283+
($($ecode:ident: $message:expr,)*) => (
284+
register_diagnostics!{$($ecode:$message,)* ;}
285+
);
286+
287+
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
288+
$(
289+
{long_codes.extend([
290+
(stringify!($ecode), Some($message)),
291+
].iter());}
292+
)*
293+
$(
294+
{long_codes.extend([
295+
stringify!($code),
296+
].iter().cloned().map(|s| (s, None)).collect::<Vec<_>>());}
297+
)*
298+
)
299+
}
300+
include!(concat!(env!("OUT_DIR"), "/all_error_codes.rs"));
301+
long_codes
302+
}

0 commit comments

Comments
 (0)