From dc6a3d01850b283a1fd301045cec21c97e7c24c5 Mon Sep 17 00:00:00 2001 From: erjuan Date: Tue, 29 Oct 2024 15:29:01 +0800 Subject: [PATCH] delete metadata_id from filename of libtest.so and libstd.so modify builder.rs and compile.rs to build std without metadata_id Signed-off-by: fengting --- src/bootstrap/builder.rs | 5 ++++- src/bootstrap/compile.rs | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 05b66f94727..8ab64bcad54 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1512,7 +1512,10 @@ impl<'a> Builder<'a> { Mode::Codegen => metadata.push_str("codegen"), _ => {} } - cargo.env("__CARGO_DEFAULT_LIB_METADATA", &metadata); + + if mode != Mode::Std { + cargo.env("__CARGO_DEFAULT_LIB_METADATA", &metadata); + } if cmd == "clippy" { rustflags.arg("-Zforce-unstable-if-unmarked"); diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 14c3ef79a78..4cf2818ecb2 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1743,22 +1743,22 @@ pub fn run_cargo( continue; } - let filename = Path::new(&*filename); + let filename_path = Path::new(&*filename); // If this was an output file in the "host dir" we don't actually // worry about it, it's not relevant for us - if filename.starts_with(&host_root_dir) { + if filename_path.starts_with(&host_root_dir) { // Unless it's a proc macro used in the compiler if crate_types.iter().any(|t| t == "proc-macro") { - deps.push((filename.to_path_buf(), DependencyType::Host)); + deps.push((filename_path.to_path_buf(), DependencyType::Host)); } continue; } // If this was output in the `deps` dir then this is a precise file // name (hash included) so we start tracking it. - if filename.starts_with(&target_deps_dir) { - deps.push((filename.to_path_buf(), DependencyType::Target)); + if filename_path.starts_with(&target_deps_dir) { + deps.push((filename_path.to_path_buf(), DependencyType::Target)); continue; } @@ -1772,13 +1772,17 @@ pub fn run_cargo( // `std-.dll.lib` on Windows. The aforementioned methods only // split the file name by the last extension (`.lib`) while we need // to split by all extensions (`.dll.lib`). - let expected_len = t!(filename.metadata()).len(); - let filename = filename.file_name().unwrap().to_str().unwrap(); + let expected_len = t!(filename_path.metadata()).len(); + let filename = filename_path.file_name().unwrap().to_str().unwrap(); let mut parts = filename.splitn(2, '.'); let file_stem = parts.next().unwrap().to_owned(); let extension = parts.next().unwrap().to_owned(); toplevel.push((file_stem, extension, expected_len)); + + if filename.contains("libstd.so") || filename.contains("libtest.so") { + deps.push((filename_path.to_path_buf(), DependencyType::Target)); + } } }); @@ -1794,6 +1798,9 @@ pub fn run_cargo( .map(|e| (e.path(), e.file_name().into_string().unwrap(), t!(e.metadata()))) .collect::>(); for (prefix, extension, expected_len) in toplevel { + if prefix.contains("libstd") || prefix.contains("libtest") { + continue; + } let candidates = contents.iter().filter(|&&(_, ref filename, ref meta)| { meta.len() == expected_len && filename