Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_metadata/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> Result<EncodedMetadata, Err
.unwrap_or_else(|err| tcx.dcx().emit_fatal(FailedCreateTempdir { err }));
let metadata_tmpdir = MaybeTempDir::new(metadata_tmpdir, tcx.sess.opts.cg.save_temps);
let metadata_filename = metadata_tmpdir.as_ref().join("full.rmeta");
let metadata_stub_filename = if !tcx.sess.opts.unstable_opts.embed_metadata
&& !tcx.crate_types().contains(&CrateType::ProcMacro)
{
Some(metadata_tmpdir.as_ref().join("stub.rmeta"))
} else {
None
};
let metadata_stub_filename =
if !tcx.sess.embed_metadata() && !tcx.crate_types().contains(&CrateType::ProcMacro) {
Some(metadata_tmpdir.as_ref().join("stub.rmeta"))
} else {
None
};

if tcx.needs_metadata() {
encode_metadata(tcx, &metadata_filename, metadata_stub_filename.as_deref());
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub(crate) struct CrateHeader {
/// Stubs do not contain the full metadata (it will be typically stored
/// in a separate rmeta file).
///
/// This is used inside rlibs and dylibs when using `-Zembed-metadata=no`.
/// This is used inside rlibs and dylibs when using `-Cembed-metadata=no`.
pub(crate) is_stub: bool,
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2944,6 +2944,10 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
.early_warn("using -Z remark-dir without enabling remarks using e.g. -C remark=all");
}

if cg.embed_metadata.is_some() && unstable_opts.embed_metadata.is_some() {
early_dcx.early_fatal("can't use both -Z embed-metadata and -C embed-metadata");
}

let externs = parse_externs(early_dcx, matches, &unstable_opts);

let remap_path_prefix = parse_remap_path_prefix(early_dcx, matches);
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,8 @@ options! {
"version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
embed_bitcode: bool = (true, parse_bool, [TRACKED],
"emit bitcode in rlibs (default: yes)"),
embed_metadata: Option<bool> = (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],
Expand Down Expand Up @@ -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<bool> = (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)"),
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/doc/rustc/src/codegen-options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/doc/unstable-book/src/compiler-flags/embed-metadata.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 2 additions & 3 deletions tests/run-make/embed-metadata/rmake.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/metadata-stub-incremental-reuse/rmake.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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();
Expand Down
Loading