Skip to content

Commit a5c9a9c

Browse files
committed
Rustbuild: enable -Zsplit-metadata for stage != 0
1 parent dd50648 commit a5c9a9c

File tree

13 files changed

+45
-20
lines changed

13 files changed

+45
-20
lines changed

Diff for: compiler/rustc_codegen_cranelift/build_system/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ impl<'a> TestRunner<'a> {
445445
cmd.arg("-Cpanic=abort");
446446
cmd.arg("-Zunstable-options");
447447
cmd.arg("--check-cfg=cfg(jit)");
448+
cmd.arg("--emit=metadata,link");
448449
cmd.args(args);
449450
cmd
450451
}

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_span::{
3232
};
3333
use tracing::{debug, instrument, trace};
3434

35-
use crate::errors::{FailCreateFileEncoder, FailWriteFile};
35+
use crate::errors::{FailCreateFileEncoder, FailWriteFile, FailedCreateFile};
3636
use crate::rmeta::*;
3737

3838
pub(super) struct EncodeContext<'a, 'tcx> {
@@ -2276,6 +2276,10 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path, ref_path: &Path) {
22762276
});
22772277
header.position.get()
22782278
});
2279+
} else {
2280+
std::fs::File::create(&ref_path).unwrap_or_else(|err| {
2281+
tcx.dcx().emit_fatal(FailedCreateFile { filename: &ref_path, err });
2282+
});
22792283
}
22802284
}
22812285

Diff for: src/bootstrap/src/bin/rustc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ fn main() {
112112
}
113113
}
114114

115+
if orig_args.iter().any(|arg| arg == "-Zsplit-metadata")
116+
&& orig_args.windows(2).any(|args| args[0] == "--crate-type" && args[1] == "dylib")
117+
{
118+
cmd.arg("--emit").arg("metadata");
119+
}
120+
115121
// Print backtrace in case of ICE
116122
if env::var("RUSTC_BACKTRACE_ON_ICE").is_ok() && env::var("RUST_BACKTRACE").is_err() {
117123
cmd.env("RUST_BACKTRACE", "1");

Diff for: src/bootstrap/src/core/build_steps/compile.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -2002,14 +2002,12 @@ pub fn run_cargo(
20022002
|| filename.ends_with(".a")
20032003
|| is_debug_info(&filename)
20042004
|| is_dylib(&filename)
2005+
|| filename.ends_with(".rmeta")
20052006
{
2006-
// Always keep native libraries, rust dylibs and debuginfo
2007+
// Always keep native libraries, rust dylibs, debuginfo and crate metadata
20072008
keep = true;
20082009
}
2009-
if is_check && filename.ends_with(".rmeta") {
2010-
// During check builds we need to keep crate metadata
2011-
keep = true;
2012-
} else if rlib_only_metadata {
2010+
if !is_check && rlib_only_metadata {
20132011
if filename.contains("jemalloc_sys")
20142012
|| filename.contains("rustc_smir")
20152013
|| filename.contains("stable_mir")
@@ -2021,7 +2019,6 @@ pub fn run_cargo(
20212019
// Distribute the rest of the rustc crates as rmeta files only to reduce
20222020
// the tarball sizes by about 50%. The object files are linked into
20232021
// librustc_driver.so, so it is still possible to link against them.
2024-
keep |= filename.ends_with(".rmeta");
20252022
}
20262023
} else {
20272024
// In all other cases keep all rlibs
@@ -2067,7 +2064,12 @@ pub fn run_cargo(
20672064
let file_stem = parts.next().unwrap().to_owned();
20682065
let extension = parts.next().unwrap().to_owned();
20692066

2070-
toplevel.push((file_stem, extension, expected_len));
2067+
if extension == "so" || extension == "dylib" {
2068+
// FIXME workaround for the fact that cargo doesn't understand `-Zsplit-metadata`
2069+
toplevel.push((file_stem.clone(), "rmeta".to_owned(), None));
2070+
}
2071+
2072+
toplevel.push((file_stem, extension, Some(expected_len)));
20712073
}
20722074
});
20732075

@@ -2088,7 +2090,7 @@ pub fn run_cargo(
20882090
.collect::<Vec<_>>();
20892091
for (prefix, extension, expected_len) in toplevel {
20902092
let candidates = contents.iter().filter(|&(_, filename, meta)| {
2091-
meta.len() == expected_len
2093+
expected_len.map_or(true, |expected_len| meta.len() == expected_len)
20922094
&& filename
20932095
.strip_prefix(&prefix[..])
20942096
.map(|s| s.starts_with('-') && s.ends_with(&extension[..]))
@@ -2099,6 +2101,7 @@ pub fn run_cargo(
20992101
});
21002102
let path_to_add = match max {
21012103
Some(triple) => triple.0.to_str().unwrap(),
2104+
None if extension == "rmeta" => continue, // cfg(not(bootstrap)) remove this once -Zsplit-metadata is passed for all stages
21022105
None => panic!("no output generated for {prefix:?} {extension:?}"),
21032106
};
21042107
if is_dylib(path_to_add) {

Diff for: src/bootstrap/src/core/builder.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,18 @@ impl<'a> Builder<'a> {
16501650
hostflags.arg("-Zunstable-options");
16511651
hostflags.arg("--check-cfg=cfg(bootstrap)");
16521652

1653+
match mode {
1654+
Mode::Std | Mode::Rustc | Mode::Codegen => {
1655+
// cfg(bootstrap) unconditionally pass this once the bootstrap compiler understands it
1656+
if stage != 0 {
1657+
// FIXME remove once cargo enables this by default
1658+
rustflags.arg("-Zsplit-metadata");
1659+
}
1660+
}
1661+
// Tools may not expect to be compiled with -Zsplit-metadata
1662+
Mode::ToolBootstrap | Mode::ToolStd | Mode::ToolRustc => {}
1663+
}
1664+
16531665
// FIXME: It might be better to use the same value for both `RUSTFLAGS` and `RUSTDOCFLAGS`,
16541666
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
16551667
// #71458.

Diff for: tests/ui/duplicate_entry_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ normalize-stderr-test: "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
1+
//@ normalize-stderr-test: "loaded from .*libstd-.*.rmeta" -> "loaded from SYSROOT/libstd-*.rmeta"
22
// note-pattern: first defined in crate `std`.
33

44
// Test for issue #31788 and E0152
@@ -11,7 +11,7 @@ use core::panic::PanicInfo;
1111

1212
#[lang = "panic_impl"]
1313
fn panic_impl(info: &PanicInfo) -> ! {
14-
//~^ ERROR: found duplicate lang item `panic_impl`
14+
//~^ ERROR: found duplicate lang item `panic_impl`
1515
loop {}
1616
}
1717

Diff for: tests/ui/duplicate_entry_error.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | | }
88
| |_^
99
|
1010
= note: the lang item is first defined in crate `std` (which `duplicate_entry_error` depends on)
11-
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
11+
= note: first definition in `std` loaded from SYSROOT/libstd-*.rmeta
1212
= note: second definition in the local crate (`duplicate_entry_error`)
1313

1414
error: aborting due to 1 previous error

Diff for: tests/ui/error-codes/E0152.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
//@ normalize-stderr-test: "loaded from .*liballoc-.*.rlib" -> "loaded from SYSROOT/liballoc-*.rlib"
1+
//@ normalize-stderr-test: "loaded from .*liballoc-.*.rmeta" -> "loaded from SYSROOT/liballoc-*.rmeta"
22
#![feature(lang_items)]
33

44
#[lang = "owned_box"]
55
struct Foo<T>(T); //~ ERROR E0152
66

7-
fn main() {
8-
}
7+
fn main() {}

Diff for: tests/ui/error-codes/E0152.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | struct Foo<T>(T);
55
| ^^^^^^^^^^^^^^^^^
66
|
77
= note: the lang item is first defined in crate `alloc` (which `std` depends on)
8-
= note: first definition in `alloc` loaded from SYSROOT/liballoc-*.rlib
8+
= note: first definition in `alloc` loaded from SYSROOT/liballoc-*.rmeta
99
= note: second definition in the local crate (`E0152`)
1010

1111
error: aborting due to 1 previous error

Diff for: tests/ui/lang-items/duplicate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ normalize-stderr-test: "loaded from .*libcore-.*.rlib" -> "loaded from SYSROOT/libcore-*.rlib"
1+
//@ normalize-stderr-test: "loaded from .*libcore-.*.rmeta" -> "loaded from SYSROOT/libcore-*.rmeta"
22
#![feature(lang_items)]
33

44
#[lang = "sized"]

Diff for: tests/ui/lang-items/duplicate.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | trait Sized {}
55
| ^^^^^^^^^^^^^^
66
|
77
= note: the lang item is first defined in crate `core` (which `std` depends on)
8-
= note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
8+
= note: first definition in `core` loaded from SYSROOT/libcore-*.rmeta
99
= note: second definition in the local crate (`duplicate`)
1010

1111
error: aborting due to 1 previous error

Diff for: tests/ui/panic-handler/panic-handler-std.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ normalize-stderr-test: "loaded from .*libstd-.*.rlib" -> "loaded from SYSROOT/libstd-*.rlib"
1+
//@ normalize-stderr-test: "loaded from .*libstd-.*.rmeta" -> "loaded from SYSROOT/libstd-*.rmeta"
22
//@ error-pattern: found duplicate lang item `panic_impl`
33

44
extern crate core;

Diff for: tests/ui/panic-handler/panic-handler-std.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | | }
77
| |_^
88
|
99
= note: the lang item is first defined in crate `std` (which `panic_handler_std` depends on)
10-
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
10+
= note: first definition in `std` loaded from SYSROOT/libstd-*.rmeta
1111
= note: second definition in the local crate (`panic_handler_std`)
1212

1313
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)