Skip to content

Commit

Permalink
[crate_universe] add an annotation for disabling pipelining
Browse files Browse the repository at this point in the history
The recent support for pipelined compilation (bazelbuild#1275) is great. There are some situations, however, where we need to disable pipelining for specific crates, e.g. bazelbuild#1584. This PR adds a crate annotation option to disable pipelining for rust_library targets generated by cargo_bazel.
  • Loading branch information
Calsign committed Jan 14, 2023
1 parent a52041f commit 794e216
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crate_universe/private/crate.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def _annotation(
data_glob = None,
deps = None,
gen_binaries = [],
disable_pipelining = False,
gen_build_script = None,
patch_args = None,
patch_tool = None,
Expand Down Expand Up @@ -118,6 +119,7 @@ def _annotation(
deps (list, optional): A list of labels to add to a crate's `rust_library::deps` attribute.
gen_binaries (list or bool, optional): As a list, the subset of the crate's bins that should get `rust_binary`
targets produced. Or `True` to generate all, `False` to generate none.
disable_pipelining (bool, optional): If True, disables pipelining for library targets for this crate.
gen_build_script (bool, optional): An authorative flag to determine whether or not to produce
`cargo_build_script` targets for the current crate.
patch_args (list, optional): The `patch_args` attribute of a Bazel repository rule. See
Expand Down Expand Up @@ -164,6 +166,7 @@ def _annotation(
data_glob = data_glob,
deps = deps,
gen_binaries = gen_binaries,
disable_pipelining = disable_pipelining,
gen_build_script = gen_build_script,
patch_args = patch_args,
patch_tool = patch_tool,
Expand Down
4 changes: 4 additions & 0 deletions crate_universe/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ pub struct CrateAnnotations {
/// [compile_data](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-compile_data) attribute.
pub compile_data_glob: Option<BTreeSet<String>>,

/// If true, disables pipelining for library targets generated for this crate.
pub 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<BTreeMap<String, String>>,
Expand Down Expand Up @@ -278,6 +281,7 @@ impl Add for CrateAnnotations {
crate_features: joined_extra_member!(self.crate_features, rhs.crate_features, BTreeSet::new, BTreeSet::extend),
data: joined_extra_member!(self.data, rhs.data, BTreeSet::new, BTreeSet::extend),
data_glob: joined_extra_member!(self.data_glob, rhs.data_glob, BTreeSet::new, BTreeSet::extend),
disable_pipelining: self.disable_pipelining || rhs.disable_pipelining,
compile_data: joined_extra_member!(self.compile_data, rhs.compile_data, BTreeSet::new, BTreeSet::extend),
compile_data_glob: joined_extra_member!(self.compile_data_glob, rhs.compile_data_glob, BTreeSet::new, BTreeSet::extend),
rustc_env: joined_extra_member!(self.rustc_env, rhs.rustc_env, BTreeMap::new, BTreeMap::extend),
Expand Down
10 changes: 10 additions & 0 deletions crate_universe/src/context/crate_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ pub struct CrateContext {
/// Additional text to add to the generated BUILD file.
#[serde(skip_serializing_if = "Option::is_none")]
pub additive_build_file_content: Option<String>,

/// If true, disables pipelining for library targets generated for this crate
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub disable_pipelining: bool,
}

impl CrateContext {
Expand Down Expand Up @@ -394,6 +398,7 @@ impl CrateContext {
build_script_attrs,
license,
additive_build_file_content: None,
disable_pipelining: false,
}
.with_overrides(extras)
}
Expand Down Expand Up @@ -446,6 +451,11 @@ impl CrateContext {
self.common_attrs.data_glob.extend(extra.clone());
}

// Disable pipelining
if crate_extra.disable_pipelining {
self.disable_pipelining = true;
}

// Rustc flags
if let Some(extra) = &crate_extra.rustc_flags {
self.common_attrs.rustc_flags.append(&mut extra.clone());
Expand Down
1 change: 1 addition & 0 deletions crate_universe/src/rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ impl Renderer {
.make_aliases(krate, false, false)
.remap_configurations(platforms),
common: self.make_common_attrs(platforms, krate, target)?,
disable_pipelining: krate.disable_pipelining,
})
}

Expand Down
2 changes: 2 additions & 0 deletions crate_universe/src/utils/starlark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ pub struct RustLibrary {
pub aliases: SelectDict<WithOriginalConfigurations<String>>,
#[serde(flatten)]
pub common: CommonAttrs,
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub disable_pipelining: bool,
}

#[derive(Serialize)]
Expand Down

0 comments on commit 794e216

Please sign in to comment.