diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 0d584be4ad0b0..8dd0f54a11479 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -639,6 +639,7 @@ fn test_codegen_options_tracking_hash() { tracked!(debuginfo, DebugInfo::Limited); tracked!(dwarf_version, Some(5)); tracked!(embed_bitcode, false); + tracked!(embed_metadata, Some(false)); tracked!(force_frame_pointers, FramePointer::Always); tracked!(force_unwind_tables, Some(true)); tracked!(instrument_coverage, InstrumentCoverage::Yes); @@ -819,7 +820,7 @@ fn test_unstable_options_tracking_hash() { tracked!(direct_access_external_data, Some(true)); tracked!(dual_proc_macros, true); tracked!(dwarf_version, Some(5)); - tracked!(embed_metadata, false); + tracked!(embed_metadata, Some(false)); tracked!(embed_source, true); tracked!(export_executable_symbols, true); tracked!(fewer_names, Some(true)); diff --git a/compiler/rustc_metadata/src/diagnostics.rs b/compiler/rustc_metadata/src/diagnostics.rs index 18796f51375a1..1060423523e5c 100644 --- a/compiler/rustc_metadata/src/diagnostics.rs +++ b/compiler/rustc_metadata/src/diagnostics.rs @@ -325,7 +325,7 @@ impl Diagnostic<'_> for MultipleCandidates { #[derive(Diagnostic)] #[diag( - "only metadata stub found for `{$flavor}` dependency `{$crate_name}` please provide path to the corresponding .rmeta file with full metadata" + "only metadata stub found for `{$flavor}` dependency `{$crate_name}`. Please provide path to the corresponding .rmeta file with full metadata" )] pub(crate) struct FullMetadataNotFound { #[primary_span] diff --git a/compiler/rustc_metadata/src/fs.rs b/compiler/rustc_metadata/src/fs.rs index ed177708facc0..e653522950651 100644 --- a/compiler/rustc_metadata/src/fs.rs +++ b/compiler/rustc_metadata/src/fs.rs @@ -48,13 +48,12 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> Result = (None, parse_opt_bool, [TRACKED], + "embed metadata in rlibs and dylibs (default: yes)"), extra_filename: String = (String::new(), parse_string, [UNTRACKED], "extra data to put in each output filename"), force_frame_pointers: FramePointer = (FramePointer::MayOmit, parse_frame_pointer, [TRACKED], @@ -2494,7 +2496,8 @@ options! { them only if an error has not been emitted"), ehcont_guard: bool = (false, parse_bool, [TRACKED], "generate Windows EHCont Guard tables"), - embed_metadata: bool = (true, parse_bool, [TRACKED], + // FIXME(kobzol): remove in 2027 + embed_metadata: Option = (None, parse_opt_bool, [TRACKED], "embed metadata in rlibs and dylibs (default: yes)"), embed_source: bool = (false, parse_bool, [TRACKED], "embed source text in DWARF debug sections (default: no)"), diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 060e614e82180..0914675902138 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -954,6 +954,11 @@ impl Session { } } } + + /// Should metadata be embedded within .rlib and .dylib files? + pub fn embed_metadata(&self) -> bool { + self.opts.cg.embed_metadata.or(self.opts.unstable_opts.embed_metadata).unwrap_or(true) + } } // JUSTIFICATION: defn of the suggested wrapper fns diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 0f85e6d00e36b..67c4fd7806933 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -152,6 +152,14 @@ at start-up, because the combination is invalid. > reason for that is that it's how it was for rustc 1.44 and prior. In 1.45 this > option was added to turn off what had always been the default. +## embed-metadata + +This option instructs `rustc` to include the full metadata in `rlib` and `dylib` +crate types. The default value is `yes` (enabled). If disabled (`no`), only stub +metadata will be stored in these files, to reduce their size on disk. When using +`-Cembed-metadata=no`, you will probably want to use `--emit=metadata` to produce +the full metadata into a separate `.rmeta` file. + ## extra-filename This option allows you to put extra data in each output filename. It takes a diff --git a/src/doc/unstable-book/src/compiler-flags/embed-metadata.md b/src/doc/unstable-book/src/compiler-flags/embed-metadata.md index a2a790ee76af3..6ce71f4775232 100644 --- a/src/doc/unstable-book/src/compiler-flags/embed-metadata.md +++ b/src/doc/unstable-book/src/compiler-flags/embed-metadata.md @@ -1,3 +1,5 @@ ## `embed-metadata` This option instructs `rustc` to include the full metadata in `rlib` and `dylib` crate types. The default value is `yes` (enabled). If disabled (`no`), only stub metadata will be stored in these files, to reduce their size on disk. When using `-Zembed-metadata=no`, you will probably want to use `--emit=metadata` to produce the full metadata into a separate `.rmeta` file. + +Note that this flag has been stabilized as `-Cembed-metadata`. The unstable variant of the flag is provided purely for making the migration easier; it will be removed in the future. diff --git a/tests/run-make/embed-metadata/rmake.rs b/tests/run-make/embed-metadata/rmake.rs index 2de6575feb886..ff80e733c3708 100644 --- a/tests/run-make/embed-metadata/rmake.rs +++ b/tests/run-make/embed-metadata/rmake.rs @@ -1,8 +1,7 @@ //@ ignore-cross-compile //@ needs-crate-type: dylib -// Tests the -Zembed-metadata compiler flag. -// Tracking issue: https://github.com/rust-lang/rust/issues/139165 +// Tests the -Cembed-metadata compiler flag. use run_make_support::rfs::{create_dir, remove_file, rename}; use run_make_support::{Rustc, dynamic_lib_name, path, run_in_tmpdir, rust_lib_name, rustc}; @@ -78,7 +77,7 @@ fn lookup_rmeta_missing(kind: LibraryKind) { fn build_dep_rustc(kind: LibraryKind) -> Rustc { let mut dep_rustc = rustc(); dep_rustc - .arg("-Zembed-metadata=no") + .arg("-Cembed-metadata=no") .crate_type(kind.crate_type()) .input("dep1.rs") .emit("metadata,link"); diff --git a/tests/run-make/metadata-stub-incremental-reuse/rmake.rs b/tests/run-make/metadata-stub-incremental-reuse/rmake.rs index e76433c97d159..adc64d6c38b74 100644 --- a/tests/run-make/metadata-stub-incremental-reuse/rmake.rs +++ b/tests/run-make/metadata-stub-incremental-reuse/rmake.rs @@ -1,6 +1,6 @@ //@ needs-target-std // -// Under `-Zembed-metadata=no` the rlib carries only a metadata stub, which +// Under `-Cembed-metadata=no` the rlib carries only a metadata stub, which // rustc writes as a separate file alongside the full metadata. Recompiling // with `-C incremental` can reuse the full metadata from a work product, and // the stub must still be produced on that path. @@ -13,7 +13,7 @@ fn build(out_dir: &str, incremental: &str) { .crate_name("foo") .crate_type("lib") .emit("dep-info,metadata,link") - .arg("-Zembed-metadata=no") + .arg("-Cembed-metadata=no") .incremental(incremental) .out_dir(out_dir) .run();