Skip to content

Commit c71b01b

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 d4e5586 commit c71b01b

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

crate_universe/private/crate.bzl

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def _annotation(
7878
data = None,
7979
data_glob = None,
8080
deps = None,
81+
disable_pipelining = False,
8182
gen_build_script = None,
8283
patch_args = None,
8384
patch_tool = None,
@@ -115,6 +116,7 @@ def _annotation(
115116
data (list, optional): A list of labels to add to a crate's `rust_library::data` attribute.
116117
data_glob (list, optional): A list of glob patterns to add to a crate's `rust_library::data` attribute.
117118
deps (list, optional): A list of labels to add to a crate's `rust_library::deps` attribute.
119+
disable_pipelining (bool, optional): If True, disables pipelining for library targets for this crate.
118120
gen_build_script (bool, optional): An authorative flag to determine whether or not to produce
119121
`cargo_build_script` targets for the current crate.
120122
patch_args (list, optional): The `patch_args` attribute of a Bazel repository rule. See
@@ -160,6 +162,7 @@ def _annotation(
160162
data = data,
161163
data_glob = data_glob,
162164
deps = deps,
165+
disable_pipelining = disable_pipelining,
163166
gen_build_script = gen_build_script,
164167
patch_args = patch_args,
165168
patch_tool = patch_tool,

crate_universe/src/config.rs

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

177+
/// If true, disables pipelining for library targets generated for this crate.
178+
pub disable_pipelining: bool,
179+
177180
/// Additional data to pass to the target's
178181
/// [rustc_env](https://bazelbuild.github.io/rules_rust/defs.html#rust_library-rustc_env) attribute.
179182
pub rustc_env: Option<BTreeMap<String, String>>,
@@ -297,6 +300,7 @@ impl Add for CrateAnnotations {
297300
crate_features: joined_extra_member!(self.crate_features, rhs.crate_features, BTreeSet::new, BTreeSet::extend),
298301
data: joined_extra_member!(self.data, rhs.data, BTreeSet::new, BTreeSet::extend),
299302
data_glob: joined_extra_member!(self.data_glob, rhs.data_glob, BTreeSet::new, BTreeSet::extend),
303+
disable_pipelining: self.disable_pipelining || rhs.disable_pipelining,
300304
compile_data: joined_extra_member!(self.compile_data, rhs.compile_data, BTreeSet::new, BTreeSet::extend),
301305
compile_data_glob: joined_extra_member!(self.compile_data_glob, rhs.compile_data_glob, BTreeSet::new, BTreeSet::extend),
302306
rustc_env: joined_extra_member!(self.rustc_env, rhs.rustc_env, BTreeMap::new, BTreeMap::extend),

crate_universe/src/context/crate_context.rs

+9
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ pub struct CrateContext {
241241
/// Additional text to add to the generated BUILD file.
242242
#[serde(skip_serializing_if = "Option::is_none")]
243243
pub additive_build_file_content: Option<String>,
244+
245+
/// If true, disables pipelining for library targets generated for this crate
246+
pub disable_pipelining: bool,
244247
}
245248

246249
impl CrateContext {
@@ -368,6 +371,7 @@ impl CrateContext {
368371
build_script_attrs,
369372
license,
370373
additive_build_file_content: None,
374+
disable_pipelining: false,
371375
}
372376
.with_overrides(extras)
373377
}
@@ -420,6 +424,11 @@ impl CrateContext {
420424
self.common_attrs.data_glob.extend(extra.clone());
421425
}
422426

427+
// Disable pipelining
428+
if crate_extra.disable_pipelining {
429+
self.disable_pipelining = true;
430+
}
431+
423432
// Rustc flags
424433
if let Some(extra) = &crate_extra.rustc_flags {
425434
self.common_attrs.rustc_flags.append(&mut extra.clone());

crate_universe/src/rendering/templates/partials/crate/library.j2

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ rust_library(
1111
{%- endfor %}
1212
] + {% set deps = crate.common_attrs | get(key="proc_macro_deps", default=Null) %}{% include "partials/crate/deps.j2" %},
1313
aliases = {% set selectable = common_aliases %}{% include "partials/crate/aliases.j2" -%},
14+
{% if crate.disable_pipelining %}disable_pipelining = True,{% endif %}
1415
{% include "partials/crate/common_attrs.j2" %}
1516
)

0 commit comments

Comments
 (0)