Skip to content

Commit 098551e

Browse files
committed
[crate_universe] add an annotation for disabling pipelining
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.
1 parent f651cd1 commit 098551e

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

crate_universe/private/crate.bzl

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def _annotation(
7979
data_glob = None,
8080
deps = None,
8181
gen_binaries = [],
82+
disable_pipelining = False,
8283
gen_build_script = None,
8384
patch_args = None,
8485
patch_tool = None,
@@ -118,6 +119,7 @@ def _annotation(
118119
deps (list, optional): A list of labels to add to a crate's `rust_library::deps` attribute.
119120
gen_binaries (list or bool, optional): As a list, the subset of the crate's bins that should get `rust_binary`
120121
targets produced. Or `True` to generate all, `False` to generate none.
122+
disable_pipelining (bool, optional): If True, disables pipelining for library targets for this crate.
121123
gen_build_script (bool, optional): An authorative flag to determine whether or not to produce
122124
`cargo_build_script` targets for the current crate.
123125
patch_args (list, optional): The `patch_args` attribute of a Bazel repository rule. See
@@ -164,6 +166,7 @@ def _annotation(
164166
data_glob = data_glob,
165167
deps = deps,
166168
gen_binaries = gen_binaries,
169+
disable_pipelining = disable_pipelining,
167170
gen_build_script = gen_build_script,
168171
patch_args = patch_args,
169172
patch_tool = patch_tool,

crate_universe/src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ pub struct CrateAnnotations {
178178
/// [compile_data](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-compile_data) attribute.
179179
pub compile_data_glob: Option<BTreeSet<String>>,
180180

181+
/// If true, disables pipelining for library targets generated for this crate.
182+
pub disable_pipelining: bool,
183+
181184
/// Additional data to pass to the target's
182185
/// [rustc_env](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-rustc_env) attribute.
183186
pub rustc_env: Option<BTreeMap<String, String>>,
@@ -278,6 +281,7 @@ impl Add for CrateAnnotations {
278281
crate_features: joined_extra_member!(self.crate_features, rhs.crate_features, BTreeSet::new, BTreeSet::extend),
279282
data: joined_extra_member!(self.data, rhs.data, BTreeSet::new, BTreeSet::extend),
280283
data_glob: joined_extra_member!(self.data_glob, rhs.data_glob, BTreeSet::new, BTreeSet::extend),
284+
disable_pipelining: self.disable_pipelining || rhs.disable_pipelining,
281285
compile_data: joined_extra_member!(self.compile_data, rhs.compile_data, BTreeSet::new, BTreeSet::extend),
282286
compile_data_glob: joined_extra_member!(self.compile_data_glob, rhs.compile_data_glob, BTreeSet::new, BTreeSet::extend),
283287
rustc_env: joined_extra_member!(self.rustc_env, rhs.rustc_env, BTreeMap::new, BTreeMap::extend),

crate_universe/src/context/crate_context.rs

+10
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ pub struct CrateContext {
247247
/// Additional text to add to the generated BUILD file.
248248
#[serde(skip_serializing_if = "Option::is_none")]
249249
pub additive_build_file_content: Option<String>,
250+
251+
/// If true, disables pipelining for library targets generated for this crate
252+
#[serde(skip_serializing_if = "std::ops::Not::not")]
253+
pub disable_pipelining: bool,
250254
}
251255

252256
impl CrateContext {
@@ -394,6 +398,7 @@ impl CrateContext {
394398
build_script_attrs,
395399
license,
396400
additive_build_file_content: None,
401+
disable_pipelining: false,
397402
}
398403
.with_overrides(extras)
399404
}
@@ -446,6 +451,11 @@ impl CrateContext {
446451
self.common_attrs.data_glob.extend(extra.clone());
447452
}
448453

454+
// Disable pipelining
455+
if crate_extra.disable_pipelining {
456+
self.disable_pipelining = true;
457+
}
458+
449459
// Rustc flags
450460
if let Some(extra) = &crate_extra.rustc_flags {
451461
self.common_attrs.rustc_flags.append(&mut extra.clone());

crate_universe/src/rendering.rs

+1
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ impl Renderer {
436436
.make_aliases(krate, false, false)
437437
.remap_configurations(platforms),
438438
common: self.make_common_attrs(platforms, krate, target)?,
439+
disable_pipelining: krate.disable_pipelining,
439440
})
440441
}
441442

crate_universe/src/utils/starlark.rs

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ pub struct RustLibrary {
175175
pub aliases: SelectDict<WithOriginalConfigurations<String>>,
176176
#[serde(flatten)]
177177
pub common: CommonAttrs,
178+
#[serde(skip_serializing_if = "std::ops::Not::not")]
179+
pub disable_pipelining: bool,
178180
}
179181

180182
#[derive(Serialize)]

0 commit comments

Comments
 (0)