diff --git a/crate_universe/src/config.rs b/crate_universe/src/config.rs index ee926b05db..6a5913d089 100644 --- a/crate_universe/src/config.rs +++ b/crate_universe/src/config.rs @@ -25,7 +25,7 @@ use crate::utils::target_triple::TargetTriple; /// Representations of different kinds of crate vendoring into workspaces. #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(rename_all = "lowercase")] -pub enum VendorMode { +pub(crate) enum VendorMode { /// Crates having full source being vendored into a workspace Local, @@ -47,58 +47,58 @@ impl std::fmt::Display for VendorMode { #[derive(Debug, Serialize, Deserialize, Clone)] #[serde(deny_unknown_fields)] -pub struct RenderConfig { +pub(crate) struct RenderConfig { /// The name of the repository being rendered - pub repository_name: String, + pub(crate) repository_name: String, /// The pattern to use for BUILD file names. /// Eg. `//:BUILD.{name}-{version}.bazel` #[serde(default = "default_build_file_template")] - pub build_file_template: String, + pub(crate) build_file_template: String, /// The pattern to use for a crate target. /// Eg. `@{repository}__{name}-{version}//:{target}` #[serde(default = "default_crate_label_template")] - pub crate_label_template: String, + pub(crate) crate_label_template: String, /// The pattern to use for the `defs.bzl` and `BUILD.bazel` /// file names used for the crates module. /// Eg. `//:{file}` #[serde(default = "default_crates_module_template")] - pub crates_module_template: String, + pub(crate) crates_module_template: String, /// The pattern used for a crate's repository name. /// Eg. `{repository}__{name}-{version}` #[serde(default = "default_crate_repository_template")] - pub crate_repository_template: String, + pub(crate) crate_repository_template: String, /// Default alias rule to use for packages. Can be overridden by annotations. #[serde(default)] - pub default_alias_rule: AliasRule, + pub(crate) default_alias_rule: AliasRule, /// The default of the `package_name` parameter to use for the module macros like `all_crate_deps`. /// In general, this should be be unset to allow the macros to do auto-detection in the analysis phase. - pub default_package_name: Option, + pub(crate) default_package_name: Option, /// Whether to generate `target_compatible_with` annotations on the generated BUILD files. This /// catches a `target_triple`being targeted that isn't declared in `supported_platform_triples`. #[serde(default = "default_generate_target_compatible_with")] - pub generate_target_compatible_with: bool, + pub(crate) generate_target_compatible_with: bool, /// The pattern to use for platform constraints. /// Eg. `@rules_rust//rust/platform:{triple}`. #[serde(default = "default_platforms_template")] - pub platforms_template: String, + pub(crate) platforms_template: String, /// The command to use for regenerating generated files. - pub regen_command: String, + pub(crate) regen_command: String, /// An optional configuration for rendering content to be rendered into repositories. - pub vendor_mode: Option, + pub(crate) vendor_mode: Option, /// Whether to generate package metadata #[serde(default = "default_generate_rules_license_metadata")] - pub generate_rules_license_metadata: bool, + pub(crate) generate_rules_license_metadata: bool, } // Default is manually implemented so that the default values match the default @@ -153,7 +153,7 @@ fn default_generate_rules_license_metadata() -> bool { /// A representation of some Git identifier used to represent the "revision" or "pin" of a checkout. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)] -pub enum Commitish { +pub(crate) enum Commitish { /// From a tag. Tag(String), @@ -176,7 +176,7 @@ impl From for Commitish { /// Information representing deterministic identifiers for some remote asset. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] -pub enum Checksumish { +pub(crate) enum Checksumish { Http { /// The sha256 digest of an http archive sha256: Option, @@ -193,7 +193,7 @@ pub enum Checksumish { } #[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Clone)] -pub enum AliasRule { +pub(crate) enum AliasRule { #[default] #[serde(rename = "alias")] Alias, @@ -208,7 +208,7 @@ pub enum AliasRule { } impl AliasRule { - pub fn bzl(&self) -> Option { + pub(crate) fn bzl(&self) -> Option { match self { AliasRule::Alias => None, AliasRule::Dbg | AliasRule::Fastbuild | AliasRule::Opt => { @@ -218,7 +218,7 @@ impl AliasRule { } } - pub fn rule(&self) -> String { + pub(crate) fn rule(&self) -> String { match self { AliasRule::Alias => "alias".to_owned(), AliasRule::Dbg => "transition_alias_dbg".to_owned(), @@ -230,115 +230,115 @@ impl AliasRule { } #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct CrateAnnotations { +pub(crate) struct CrateAnnotations { /// Which subset of the crate's bins should get produced as `rust_binary` targets. - pub gen_binaries: Option, + pub(crate) gen_binaries: Option, /// Determins whether or not Cargo build scripts should be generated for the current package - pub gen_build_script: Option, + pub(crate) gen_build_script: Option, /// Additional data to pass to /// [deps](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-deps) attribute. - pub deps: Option>>, + pub(crate) deps: Option>>, /// Additional data to pass to /// [proc_macro_deps](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-proc_macro_deps) attribute. - pub proc_macro_deps: Option>>, + pub(crate) proc_macro_deps: Option>>, /// Additional data to pass to the target's /// [crate_features](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-crate_features) attribute. - pub crate_features: Option>>, + pub(crate) crate_features: Option>>, /// Additional data to pass to the target's /// [data](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-data) attribute. - pub data: Option>>, + pub(crate) data: Option>>, /// An optional glob pattern to set on the /// [data](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-data) attribute. - pub data_glob: Option>, + pub(crate) data_glob: Option>, /// Additional data to pass to /// [compile_data](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-compile_data) attribute. - pub compile_data: Option>>, + pub(crate) compile_data: Option>>, /// An optional glob pattern to set on the /// [compile_data](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-compile_data) attribute. - pub compile_data_glob: Option>, + pub(crate) compile_data_glob: Option>, /// If true, disables pipelining for library targets generated for this crate. - pub disable_pipelining: bool, + pub(crate) disable_pipelining: bool, /// Additional data to pass to the target's /// [rustc_env](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-rustc_env) attribute. - pub rustc_env: Option>>, + pub(crate) rustc_env: Option>>, /// Additional data to pass to the target's /// [rustc_env_files](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-rustc_env_files) attribute. - pub rustc_env_files: Option>>, + pub(crate) rustc_env_files: Option>>, /// Additional data to pass to the target's /// [rustc_flags](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-rustc_flags) attribute. - pub rustc_flags: Option>>, + pub(crate) rustc_flags: Option>>, /// Additional dependencies to pass to a build script's /// [deps](https://bazelbuild.github.io/rules_rust/cargo.html#cargo_build_script-deps) attribute. - pub build_script_deps: Option>>, + pub(crate) build_script_deps: Option>>, /// Additional data to pass to a build script's /// [proc_macro_deps](https://bazelbuild.github.io/rules_rust/cargo.html#cargo_build_script-proc_macro_deps) attribute. - pub build_script_proc_macro_deps: Option>>, + pub(crate) build_script_proc_macro_deps: Option>>, /// Additional data to pass to a build script's /// [build_script_data](https://bazelbuild.github.io/rules_rust/cargo.html#cargo_build_script-data) attribute. - pub build_script_data: Option>>, + pub(crate) build_script_data: Option>>, /// Additional data to pass to a build script's /// [tools](https://bazelbuild.github.io/rules_rust/cargo.html#cargo_build_script-tools) attribute. - pub build_script_tools: Option>>, + pub(crate) build_script_tools: Option>>, /// An optional glob pattern to set on the /// [build_script_data](https://bazelbuild.github.io/rules_rust/cargo.html#cargo_build_script-build_script_env) attribute. - pub build_script_data_glob: Option>, + pub(crate) build_script_data_glob: Option>, /// Additional environment variables to pass to a build script's /// [build_script_env](https://bazelbuild.github.io/rules_rust/cargo.html#cargo_build_script-rustc_env) attribute. - pub build_script_env: Option>>, + pub(crate) build_script_env: Option>>, /// Additional rustc_env flags to pass to a build script's /// [rustc_env](https://bazelbuild.github.io/rules_rust/cargo.html#cargo_build_script-rustc_env) attribute. - pub build_script_rustc_env: Option>>, + pub(crate) build_script_rustc_env: Option>>, /// Additional labels to pass to a build script's /// [toolchains](https://bazel.build/reference/be/common-definitions#common-attributes) attribute. - pub build_script_toolchains: Option>, + pub(crate) build_script_toolchains: Option>, /// Directory to run the crate's build script in. If not set, will run in the manifest directory, otherwise a directory relative to the exec root. - pub build_script_rundir: Option>, + pub(crate) build_script_rundir: Option>, /// A scratch pad used to write arbitrary text to target BUILD files. - pub additive_build_file_content: Option, + pub(crate) additive_build_file_content: Option, /// For git sourced crates, this is a the /// [git_repository::shallow_since](https://docs.bazel.build/versions/main/repo/git.html#new_git_repository-shallow_since) attribute. - pub shallow_since: Option, + pub(crate) shallow_since: Option, /// The `patch_args` attribute of a Bazel repository rule. See /// [http_archive.patch_args](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_args) - pub patch_args: Option>, + pub(crate) patch_args: Option>, /// The `patch_tool` attribute of a Bazel repository rule. See /// [http_archive.patch_tool](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_tool) - pub patch_tool: Option, + pub(crate) patch_tool: Option, /// The `patches` attribute of a Bazel repository rule. See /// [http_archive.patches](https://docs.bazel.build/versions/main/repo/http.html#http_archive-patches) - pub patches: Option>, + pub(crate) patches: Option>, /// Extra targets the should be aliased during rendering. - pub extra_aliased_targets: Option>, + pub(crate) extra_aliased_targets: Option>, /// Transition rule to use instead of `native.alias()`. - pub alias_rule: Option, + pub(crate) alias_rule: Option, } macro_rules! joined_extra_member { @@ -440,25 +440,28 @@ impl Sum for CrateAnnotations { /// not specify a different value for the same annotation in their /// crates_repository attributes. #[derive(Debug, Deserialize)] -pub struct AnnotationsProvidedByPackage { - pub gen_build_script: Option, - pub data: Option>>, - pub data_glob: Option>, - pub deps: Option>>, - pub compile_data: Option>>, - pub compile_data_glob: Option>, - pub rustc_env: Option>>, - pub rustc_env_files: Option>>, - pub rustc_flags: Option>>, - pub build_script_env: Option>>, - pub build_script_rustc_env: Option>>, - pub build_script_rundir: Option>, - pub additive_build_file_content: Option, - pub extra_aliased_targets: Option>, +pub(crate) struct AnnotationsProvidedByPackage { + pub(crate) gen_build_script: Option, + pub(crate) data: Option>>, + pub(crate) data_glob: Option>, + pub(crate) deps: Option>>, + pub(crate) compile_data: Option>>, + pub(crate) compile_data_glob: Option>, + pub(crate) rustc_env: Option>>, + pub(crate) rustc_env_files: Option>>, + pub(crate) rustc_flags: Option>>, + pub(crate) build_script_env: Option>>, + pub(crate) build_script_rustc_env: Option>>, + pub(crate) build_script_rundir: Option>, + pub(crate) additive_build_file_content: Option, + pub(crate) extra_aliased_targets: Option>, } impl CrateAnnotations { - pub fn apply_defaults_from_package_metadata(&mut self, pkg_metadata: &serde_json::Value) { + pub(crate) fn apply_defaults_from_package_metadata( + &mut self, + pkg_metadata: &serde_json::Value, + ) { #[deny(unused_variables)] let AnnotationsProvidedByPackage { gen_build_script, @@ -524,7 +527,7 @@ pub struct CrateId { impl CrateId { /// Construct a new [CrateId] - pub fn new(name: String, version: semver::Version) -> Self { + pub(crate) fn new(name: String, version: semver::Version) -> Self { Self { name, version } } } @@ -592,7 +595,7 @@ impl std::fmt::Display for CrateId { } #[derive(Debug, Hash, Clone, PartialEq, Eq)] -pub enum GenBinaries { +pub(crate) enum GenBinaries { All, Some(BTreeSet), } @@ -652,30 +655,30 @@ impl<'de> Visitor<'de> for GenBinariesVisitor { /// Workspace specific settings to control how targets are generated #[derive(Debug, Default, Serialize, Deserialize, Clone)] #[serde(deny_unknown_fields)] -pub struct Config { +pub(crate) struct Config { /// Whether to generate `rust_binary` targets for all bins by default - pub generate_binaries: bool, + pub(crate) generate_binaries: bool, /// Whether or not to generate Cargo build scripts by default - pub generate_build_scripts: bool, + pub(crate) generate_build_scripts: bool, /// Additional settings to apply to generated crates #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub annotations: BTreeMap, + pub(crate) annotations: BTreeMap, /// Settings used to determine various render info - pub rendering: RenderConfig, + pub(crate) rendering: RenderConfig, /// The contents of a Cargo configuration file - pub cargo_config: Option, + pub(crate) cargo_config: Option, /// A set of platform triples to use in generated select statements #[serde(default, skip_serializing_if = "BTreeSet::is_empty")] - pub supported_platform_triples: BTreeSet, + pub(crate) supported_platform_triples: BTreeSet, } impl Config { - pub fn try_from_path>(path: T) -> Result { + pub(crate) fn try_from_path>(path: T) -> Result { let data = fs::read_to_string(path)?; Ok(serde_json::from_str(&data)?) } diff --git a/crate_universe/src/context.rs b/crate_universe/src/context.rs index a92c7361bf..f962afc46e 100644 --- a/crate_universe/src/context.rs +++ b/crate_universe/src/context.rs @@ -1,6 +1,6 @@ //! Convert annotated metadata into a renderable context -pub mod crate_context; +pub(crate) mod crate_context; mod platforms; use std::collections::{BTreeMap, BTreeSet}; @@ -18,42 +18,42 @@ use crate::metadata::{Annotations, Dependency}; use crate::select::Select; use crate::utils::target_triple::TargetTriple; -pub use self::crate_context::*; +pub(crate) use self::crate_context::*; /// A struct containing information about a Cargo dependency graph in an easily to consume /// format for rendering reproducible Bazel targets. #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] pub(crate) struct Context { /// The collective checksum of all inputs to the context - pub checksum: Option, + pub(crate) checksum: Option, /// The collection of all crates that make up the dependency graph - pub crates: BTreeMap, + pub(crate) crates: BTreeMap, /// A subset of only crates with binary targets - pub binary_crates: BTreeSet, + pub(crate) binary_crates: BTreeSet, /// A subset of workspace members mapping to their workspace /// path relative to the workspace root - pub workspace_members: BTreeMap, + pub(crate) workspace_members: BTreeMap, /// A mapping of `cfg` flags to platform triples supporting the configuration - pub conditions: BTreeMap>, + pub(crate) conditions: BTreeMap>, /// A list of crates visible to any bazel module. - pub direct_deps: BTreeSet, + pub(crate) direct_deps: BTreeSet, /// A list of crates visible to this bazel module. - pub direct_dev_deps: BTreeSet, + pub(crate) direct_dev_deps: BTreeSet, } impl Context { - pub fn try_from_path>(path: T) -> Result { + pub(crate) fn try_from_path>(path: T) -> Result { let data = fs::read_to_string(path.as_ref())?; Ok(serde_json::from_str(&data)?) } - pub fn new(annotations: Annotations) -> Result { + pub(crate) fn new(annotations: Annotations) -> Result { // Build a map of crate contexts let crates: BTreeMap = annotations .metadata @@ -192,7 +192,7 @@ impl Context { } /// Create a set of all direct dependencies of workspace member crates. - pub fn workspace_member_deps(&self) -> BTreeSet { + pub(crate) fn workspace_member_deps(&self) -> BTreeSet { self.workspace_members .keys() .map(move |id| &self.crates[id]) @@ -208,7 +208,7 @@ impl Context { .collect() } - pub fn has_duplicate_workspace_member_dep(&self, dep: &CrateDependency) -> bool { + pub(crate) fn has_duplicate_workspace_member_dep(&self, dep: &CrateDependency) -> bool { 1 < self .workspace_member_deps() .into_iter() @@ -216,7 +216,7 @@ impl Context { .count() } - pub fn has_duplicate_binary_crate(&self, bin: &CrateId) -> bool { + pub(crate) fn has_duplicate_binary_crate(&self, bin: &CrateId) -> bool { 1 < self .binary_crates .iter() diff --git a/crate_universe/src/context/crate_context.rs b/crate_universe/src/context/crate_context.rs index c36685d721..1f56e4d01e 100644 --- a/crate_universe/src/context/crate_context.rs +++ b/crate_universe/src/context/crate_context.rs @@ -27,7 +27,7 @@ pub struct CrateDependency { #[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Clone)] #[serde(default)] -pub struct TargetAttributes { +pub(crate) struct TargetAttributes { /// The module name of the crate (notably, not the package name). // // This must be the first field of `TargetAttributes` to make it the @@ -35,17 +35,17 @@ pub struct TargetAttributes { // by. The `Ord` impl controls the order of multiple rules of the same type // in the same BUILD file. In particular, this makes packages with multiple // bin crates generate those `rust_binary` targets in alphanumeric order. - pub crate_name: String, + pub(crate) crate_name: String, /// The path to the crate's root source file, relative to the manifest. - pub crate_root: Option, + pub(crate) crate_root: Option, /// A glob pattern of all source files required by the target - pub srcs: Glob, + pub(crate) srcs: Glob, } #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Clone)] -pub enum Rule { +pub(crate) enum Rule { /// `rust_library` Library(TargetAttributes), @@ -63,58 +63,58 @@ pub enum Rule { /// [core rules of `rules_rust`](https://bazelbuild.github.io/rules_rust/defs.html). #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(default)] -pub struct CommonAttributes { +pub(crate) struct CommonAttributes { #[serde(skip_serializing_if = "Select::is_empty")] - pub compile_data: Select>, + pub(crate) compile_data: Select>, #[serde(skip_serializing_if = "BTreeSet::is_empty")] - pub compile_data_glob: BTreeSet, + pub(crate) compile_data_glob: BTreeSet, #[serde(skip_serializing_if = "Select::is_empty")] - pub crate_features: Select>, + pub(crate) crate_features: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub data: Select>, + pub(crate) data: Select>, #[serde(skip_serializing_if = "BTreeSet::is_empty")] - pub data_glob: BTreeSet, + pub(crate) data_glob: BTreeSet, #[serde(skip_serializing_if = "Select::is_empty")] - pub deps: Select>, + pub(crate) deps: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub extra_deps: Select>, + pub(crate) extra_deps: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub deps_dev: Select>, + pub(crate) deps_dev: Select>, - pub edition: String, + pub(crate) edition: String, #[serde(skip_serializing_if = "Option::is_none")] - pub linker_script: Option, + pub(crate) linker_script: Option, #[serde(skip_serializing_if = "Select::is_empty")] - pub proc_macro_deps: Select>, + pub(crate) proc_macro_deps: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub extra_proc_macro_deps: Select>, + pub(crate) extra_proc_macro_deps: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub proc_macro_deps_dev: Select>, + pub(crate) proc_macro_deps_dev: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub rustc_env: Select>, + pub(crate) rustc_env: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub rustc_env_files: Select>, + pub(crate) rustc_env_files: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub rustc_flags: Select>, + pub(crate) rustc_flags: Select>, - pub version: String, + pub(crate) version: String, #[serde(skip_serializing_if = "Vec::is_empty")] - pub tags: Vec, + pub(crate) tags: Vec, } impl Default for CommonAttributes { @@ -147,21 +147,21 @@ impl Default for CommonAttributes { // https://bazelbuild.github.io/rules_rust/cargo.html#cargo_build_script #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(default)] -pub struct BuildScriptAttributes { +pub(crate) struct BuildScriptAttributes { #[serde(skip_serializing_if = "Select::is_empty")] - pub compile_data: Select>, + pub(crate) compile_data: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub data: Select>, + pub(crate) data: Select>, #[serde(skip_serializing_if = "BTreeSet::is_empty")] - pub data_glob: BTreeSet, + pub(crate) data_glob: BTreeSet, #[serde(skip_serializing_if = "Select::is_empty")] - pub deps: Select>, + pub(crate) deps: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub extra_deps: Select>, + pub(crate) extra_deps: Select>, // TODO: refactor a crate with a build.rs file from two into three bazel // rules in order to deduplicate link_dep information. Currently as the @@ -181,40 +181,40 @@ pub struct BuildScriptAttributes { // normal dependencies. This could be handled a special rule, or just using // a `filegroup`. #[serde(skip_serializing_if = "Select::is_empty")] - pub link_deps: Select>, + pub(crate) link_deps: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub extra_link_deps: Select>, + pub(crate) extra_link_deps: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub build_script_env: Select>, + pub(crate) build_script_env: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub rundir: Select, + pub(crate) rundir: Select, #[serde(skip_serializing_if = "Select::is_empty")] - pub extra_proc_macro_deps: Select>, + pub(crate) extra_proc_macro_deps: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub proc_macro_deps: Select>, + pub(crate) proc_macro_deps: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub rustc_env: Select>, + pub(crate) rustc_env: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub rustc_flags: Select>, + pub(crate) rustc_flags: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub rustc_env_files: Select>, + pub(crate) rustc_env_files: Select>, #[serde(skip_serializing_if = "Select::is_empty")] - pub tools: Select>, + pub(crate) tools: Select>, #[serde(skip_serializing_if = "Option::is_none")] - pub links: Option, + pub(crate) links: Option, #[serde(skip_serializing_if = "BTreeSet::is_empty")] - pub toolchains: BTreeSet