diff --git a/tools/cargo_embargo/src/config.rs b/tools/cargo_embargo/src/config.rs index 931c10d2d..bf27f3395 100644 --- a/tools/cargo_embargo/src/config.rs +++ b/tools/cargo_embargo/src/config.rs @@ -75,15 +75,15 @@ pub struct Config { /// Options that apply to everything in a package (i.e. everything associated with a particular /// Cargo.toml file). -#[derive(Deserialize, Default)] +#[derive(Deserialize)] #[serde(deny_unknown_fields)] pub struct PackageConfig { /// Whether to compile for device. Defaults to true. - #[serde(default)] - pub device_supported: Option, + #[serde(default = "default_true")] + pub device_supported: bool, /// Whether to compile for host. Defaults to true. - #[serde(default)] - pub host_supported: Option, + #[serde(default = "default_true")] + pub host_supported: bool, /// Generate "rust_library_rlib" instead of "rust_library". #[serde(default)] pub force_rlib: bool, @@ -107,3 +107,19 @@ pub struct PackageConfig { #[serde(default)] pub copy_out: bool, } + +impl Default for PackageConfig { + fn default() -> Self { + Self { + device_supported: true, + host_supported: true, + force_rlib: false, + no_presubmit: false, + add_toplevel_block: None, + add_module_block: None, + dep_blocklist: Default::default(), + patch: None, + copy_out: false, + } + } +} diff --git a/tools/cargo_embargo/src/main.rs b/tools/cargo_embargo/src/main.rs index 84638ca72..1b8900e23 100644 --- a/tools/cargo_embargo/src/main.rs +++ b/tools/cargo_embargo/src/main.rs @@ -403,7 +403,7 @@ fn crate_to_bp_modules( ) -> Result> { let mut modules = Vec::new(); for crate_type in &crate_.types { - let host = if package_cfg.device_supported.unwrap_or(true) { "" } else { "_host" }; + let host = if package_cfg.device_supported { "" } else { "_host" }; let rlib = if package_cfg.force_rlib { "_rlib" } else { "" }; let (module_type, module_name, stem) = match crate_type { CrateType::Bin => { @@ -458,8 +458,8 @@ fn crate_to_bp_modules( m.props.set("defaults", vec![defaults.clone()]); } - if package_cfg.host_supported.unwrap_or(true) - && package_cfg.device_supported.unwrap_or(true) + if package_cfg.host_supported + && package_cfg.device_supported && module_type != "rust_proc_macro" { m.props.set("host_supported", true); @@ -475,7 +475,7 @@ fn crate_to_bp_modules( if crate_.types.contains(&CrateType::Test) { m.props.set("test_suites", vec!["general-tests"]); m.props.set("auto_gen_config", true); - if package_cfg.host_supported.unwrap_or(true) { + if package_cfg.host_supported { m.props.object("test_options").set("unit_test", !package_cfg.no_presubmit); } }