diff --git a/tools/cargo_embargo/src/cargo_out.rs b/tools/cargo_embargo/src/cargo_out.rs index fcf467f88..a47f1f739 100644 --- a/tools/cargo_embargo/src/cargo_out.rs +++ b/tools/cargo_embargo/src/cargo_out.rs @@ -23,7 +23,7 @@ use std::path::Path; use std::path::PathBuf; /// Combined representation of --crate-type and --test flags. -#[derive(Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum CrateType { // --crate-type types Bin, @@ -39,6 +39,13 @@ pub enum CrateType { TestNoHarness, } +impl CrateType { + /// Returns whether the crate type is a kind of library. + pub fn is_library(self) -> bool { + matches!(self, Self::Lib | Self::RLib | Self::DyLib | Self::CDyLib | Self::StaticLib) + } +} + /// Info extracted from `CargoOut` for a crate. /// /// Note that there is a 1-to-many relationship between a Cargo.toml file and these `Crate` diff --git a/tools/cargo_embargo/src/main.rs b/tools/cargo_embargo/src/main.rs index 83ee8967c..67ebd59e5 100644 --- a/tools/cargo_embargo/src/main.rs +++ b/tools/cargo_embargo/src/main.rs @@ -70,6 +70,10 @@ fn default_apex_available() -> Vec { vec!["//apex_available:platform".to_string(), "//apex_available:anyapex".to_string()] } +fn default_true() -> bool { + true +} + /// Options that apply to everything. #[derive(serde::Deserialize)] #[serde(deny_unknown_fields)] @@ -90,6 +94,12 @@ struct Config { /// Value to use for every generated library module's "apex_available" field. #[serde(default = "default_apex_available")] apex_available: Vec, + /// Value to use for every generated library module's `product_available` field. + #[serde(default = "default_true")] + product_available: bool, + /// Value to use for every generated library module's `vendor_available` field. + #[serde(default = "default_true")] + vendor_available: bool, /// Map of renames for modules. For example, if a "libfoo" would be generated and there is an /// entry ("libfoo", "libbar"), the generated module will be called "libbar" instead. /// @@ -583,17 +593,16 @@ fn crate_to_bp_modules( m.props.set("shared_libs", process_lib_deps(crate_.shared_libs.clone())); } - if !cfg.apex_available.is_empty() - && [ - CrateType::Lib, - CrateType::RLib, - CrateType::DyLib, - CrateType::CDyLib, - CrateType::StaticLib, - ] - .contains(crate_type) - { - m.props.set("apex_available", cfg.apex_available.clone()); + if crate_type.is_library() { + if !cfg.apex_available.is_empty() { + m.props.set("apex_available", cfg.apex_available.clone()); + } + if cfg.product_available { + m.props.set("product_available", true); + } + if cfg.vendor_available { + m.props.set("vendor_available", true); + } } if let Some(visibility) = cfg.module_visibility.get(module_name) {