Skip to content

Commit 33b915a

Browse files
committed
Add new type of process wrapper test
1 parent 1f3d27d commit 33b915a

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

rust/private/rust.bzl

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,12 +1355,22 @@ _rust_binary_without_process_wrapper_transition = transition(
13551355
],
13561356
)
13571357

1358+
_RustBuiltWithoutProcessWrapperInfo = provider(
1359+
doc = "A provider identifying the target having been built using a `*_without_process_wrapper` rule variant.",
1360+
fields = {},
1361+
)
1362+
1363+
def _rust_binary_without_process_wrapper_impl(ctx):
1364+
providers = _rust_binary_impl(ctx)
1365+
return providers + [_RustBuiltWithoutProcessWrapperInfo()]
1366+
13581367
# Provides an internal rust_{binary,library} to use that we can use to build the process
13591368
# wrapper, this breaks the dependency of rust_* on the process wrapper by
13601369
# setting it to None, which the functions in rustc detect and build accordingly.
13611370
rust_binary_without_process_wrapper = rule(
1362-
implementation = _rust_binary_impl,
1363-
provides = COMMON_PROVIDERS,
1371+
implementation = _rust_binary_without_process_wrapper_impl,
1372+
doc = "A variant of `rust_binary` that uses a minimal process wrapper for `Rustc` actions.",
1373+
provides = COMMON_PROVIDERS + [_RustBuiltWithoutProcessWrapperInfo],
13641374
attrs = _common_attrs_for_binary_without_process_wrapper(_common_attrs | _rust_binary_attrs),
13651375
cfg = _rust_binary_without_process_wrapper_transition,
13661376
executable = True,
@@ -1371,9 +1381,14 @@ rust_binary_without_process_wrapper = rule(
13711381
],
13721382
)
13731383

1384+
def _rust_library_without_process_wrapper_impl(ctx):
1385+
providers = _rust_library_impl(ctx)
1386+
return providers + [_RustBuiltWithoutProcessWrapperInfo()]
1387+
13741388
rust_library_without_process_wrapper = rule(
1375-
implementation = _rust_library_impl,
1376-
provides = COMMON_PROVIDERS,
1389+
implementation = _rust_library_without_process_wrapper_impl,
1390+
doc = "A variant of `rust_library` that uses a minimal process wrapper for `Rustc` actions.",
1391+
provides = COMMON_PROVIDERS + [_RustBuiltWithoutProcessWrapperInfo],
13771392
attrs = dict(_common_attrs_for_binary_without_process_wrapper(_common_attrs).items()),
13781393
fragments = ["cpp"],
13791394
toolchains = [
@@ -1382,6 +1397,39 @@ rust_library_without_process_wrapper = rule(
13821397
],
13831398
)
13841399

1400+
def _test_attrs_for_binary_without_process_wrapper(attrs):
1401+
new_attrs = {}
1402+
new_attrs.update(attrs)
1403+
1404+
# Require that `crate` has the correct internal provider.
1405+
new_attrs["crate"] = attr.label(
1406+
mandatory = False,
1407+
providers = [_RustBuiltWithoutProcessWrapperInfo],
1408+
doc = dedent("""\
1409+
Target inline tests declared in the given crate
1410+
1411+
These tests are typically those that would be held out under
1412+
`#[cfg(test)]` declarations.
1413+
"""),
1414+
)
1415+
1416+
return new_attrs
1417+
1418+
rust_test_without_process_wrapper_test = rule(
1419+
implementation = _rust_test_impl,
1420+
doc = "Unlike other `*_without_process_wrapper` rules, this rule does use the process wrapper but requires it's dependencies were not built with one.",
1421+
provides = COMMON_PROVIDERS,
1422+
attrs = _test_attrs_for_binary_without_process_wrapper(_common_attrs | _rust_test_attrs),
1423+
executable = True,
1424+
cfg = _rust_binary_without_process_wrapper_transition,
1425+
fragments = ["cpp"],
1426+
test = True,
1427+
toolchains = [
1428+
str(Label("//rust:toolchain_type")),
1429+
config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type", mandatory = False),
1430+
],
1431+
)
1432+
13851433
def _rust_test_transition_impl(settings, attr):
13861434
return {
13871435
"//command_line_option:platforms": str(attr.platform) if attr.platform else settings["//command_line_option:platforms"],

util/process_wrapper/BUILD.bazel

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
load("@bazel_skylib//lib:selects.bzl", "selects")
2-
load("//rust:defs.bzl", "rust_test")
32

43
# buildifier: disable=bzl-visibility
5-
load("//rust/private:rust.bzl", "rust_binary_without_process_wrapper")
4+
load("//rust/private:rust.bzl", "rust_binary_without_process_wrapper", "rust_test_without_process_wrapper_test")
65
load("//util/process_wrapper/private:bootstrap_process_wrapper.bzl", "bootstrap_process_wrapper")
76

87
config_setting(
@@ -50,7 +49,7 @@ rust_binary_without_process_wrapper(
5049
],
5150
)
5251

53-
rust_test(
52+
rust_test_without_process_wrapper_test(
5453
name = "process_wrapper_test",
5554
crate = ":process_wrapper",
5655
edition = "2018",

0 commit comments

Comments
 (0)