Skip to content
Merged
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
7 changes: 1 addition & 6 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ mod environment;
use environment::Env;

mod schema;
use crate::workspace::features::EmbedMetadata;
pub use schema::*;

/// Helper macro for creating typed access methods.
Expand Down Expand Up @@ -1261,11 +1260,7 @@ impl GlobalContext {
}

pub fn should_embed_metadata(&self) -> bool {
match self.cli_unstable().embed_metadata {
EmbedMetadata::Embed => true,
EmbedMetadata::DoNotEmbed => false,
EmbedMetadata::Unset => true,
}
self.cli_unstable().embed_metadata.unwrap_or(true)
}

pub fn network_allowed(&self) -> bool {
Expand Down
24 changes: 6 additions & 18 deletions src/workspace/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,6 @@ enum Status {
Removed,
}

/// Config for the `-Zembed-metadata` option.
#[derive(Debug, Default, Deserialize)]
pub enum EmbedMetadata {
/// Embed metadata in .rlib files, the original rustc behavior.
Embed,
/// Do not embed metadata in .rlib files.
DoNotEmbed,
/// The `-Zembed-metadata` flag wasn't set.
#[default]
Unset,
}

/// A listing of stable and unstable new syntax in Cargo.toml.
///
/// This generates definitions and impls for [`Features`] and [`Feature`]
Expand Down Expand Up @@ -883,7 +871,7 @@ macro_rules! unstable_cli_options {
unstable_cli_options!(
// Permanently unstable features:
allow_features: Option<AllowFeatures> = ("Allow *only* the listed unstable features"),
embed_metadata: EmbedMetadata = ("Avoid embedding metadata in library artifacts"),
embed_metadata: Option<bool> = ("Avoid embedding metadata in library artifacts"),
print_im_a_teapot: bool,

// All other unstable features.
Expand Down Expand Up @@ -1322,11 +1310,11 @@ impl CliUnstable {
}
}

fn parse_embed_metadata(key: &str, value: Option<&str>) -> CargoResult<EmbedMetadata> {
fn parse_option_bool(key: &str, value: Option<&str>) -> CargoResult<Option<bool>> {
match value {
None => Ok(EmbedMetadata::Unset),
Some("yes") => Ok(EmbedMetadata::Embed),
Some("no") => Ok(EmbedMetadata::DoNotEmbed),
None => Ok(None),
Some("yes") => Ok(Some(true)),
Some("no") => Ok(Some(false)),
Some(s) => bail!("flag -Z{key} expected `no` or `yes`, found: `{s}`"),
}
}
Expand Down Expand Up @@ -1382,7 +1370,7 @@ impl CliUnstable {
// Permanently unstable features
// Sorted alphabetically:
"allow-features" => self.allow_features = Some(parse_list(v).into_iter().collect()),
"embed-metadata" => self.embed_metadata = parse_embed_metadata(k, v)?,
"embed-metadata" => self.embed_metadata = parse_option_bool(k, v)?,
"print-im-a-teapot" => self.print_im_a_teapot = parse_bool(k, v)?,

// Stabilized features
Expand Down
18 changes: 18 additions & 0 deletions tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2651,3 +2651,21 @@ rustdocflags = ["--default-theme=dark"]
.env("CARGO_HOME", &cargo_home)
.run();
}

#[cargo_test]
fn unstable_embed_metadata() {
write_config_toml(
"\
[unstable]
embed-metadata = false
",
);

let gctx = new_gctx();

let value = gctx
.get::<Option<bool>>("unstable.embed-metadata")
.unwrap()
.unwrap();
assert!(!value);
}