Skip to content

Commit

Permalink
CcModuleApi: expose dwo_outputs and pic_dwo_outputs to starlark, behi…
Browse files Browse the repository at this point in the history
…nd an allowlist

We need this to implement --fission support for Rust, but don't want to burden
the blaze team with an imperfect API long-term. This should be enough to
unblock us without too much risk.

PiperOrigin-RevId: 575161892
Change-Id: I144a09a83159084a0aafd8fc13e7945bdd3f4b16
  • Loading branch information
durin42 authored and copybara-github committed Oct 20, 2023
1 parent 859e54d commit 9772f03
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2854,6 +2854,8 @@ public CcCompilationOutputs createCompilationOutputsFromStarlark(
Object objectsObject,
Object picObjectsObject,
Object ltoCompilationContextObject,
Object dwoObjectsObject,
Object picDwoObjectsObject,
StarlarkThread thread)
throws EvalException {
isCalledFromStarlarkCcCommon(thread);
Expand All @@ -2880,6 +2882,16 @@ public CcCompilationOutputs createCompilationOutputsFromStarlark(
if (ltoCompilationContext != null) {
ccCompilationOutputsBuilder.addLtoCompilationContext(ltoCompilationContext);
}
NestedSet<Artifact> dwoObjects =
convertToNestedSet(dwoObjectsObject, Artifact.class, "dwo_objects");
for (Artifact dwoFile : dwoObjects.toList()) {
ccCompilationOutputsBuilder.addDwoFile(dwoFile);
}
NestedSet<Artifact> picDwoObjects =
convertToNestedSet(picDwoObjectsObject, Artifact.class, "pic_dwo_objects");
for (Artifact picDwoFile : picDwoObjects.toList()) {
ccCompilationOutputsBuilder.addPicDwoFile(picDwoFile);
}
return ccCompilationOutputsBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,31 @@ FeatureConfigurationT configureFeatures(
positional = false,
named = true,
defaultValue = "unbound"),
@Param(
name = "dwo_objects",
documented = false,
doc = "Compilation outputs containing dwo files of debuginfo for fission builds.",
positional = false,
named = true,
allowedTypes = {
@ParamType(type = Depset.class),
}),
@Param(
name = "pic_dwo_objects",
doc = "Compilation outputs containing dwo files of debuginfo for pic fission builds.",
documented = false,
positional = false,
named = true,
allowedTypes = {
@ParamType(type = Depset.class),
}),
})
CompilationOutputsT createCompilationOutputsFromStarlark(
Object objectsObject,
Object picObjectsObject,
Object ltoCopmilationContextObject,
Object dwoObjectsObject,
Object picDwoObjectsObject,
StarlarkThread thread)
throws EvalException;

Expand Down
10 changes: 8 additions & 2 deletions src/main/starlark/builtins_bzl/common/cc/cc_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,21 @@ def _link(
build_config = build_config,
)

def _create_compilation_outputs(*, objects = None, pic_objects = None, lto_compilation_context = _UNBOUND):
if lto_compilation_context != _UNBOUND:
def _create_compilation_outputs(*, objects = None, pic_objects = None, lto_compilation_context = _UNBOUND, dwo_objects = _UNBOUND, pic_dwo_objects = _UNBOUND):
if lto_compilation_context != _UNBOUND or dwo_objects != _UNBOUND or pic_dwo_objects != _UNBOUND:
cc_common_internal.check_private_api(allowlist = _PRIVATE_STARLARKIFICATION_ALLOWLIST)
if lto_compilation_context == _UNBOUND:
lto_compilation_context = None
if dwo_objects == _UNBOUND:
dwo_objects = depset()
if pic_dwo_objects == _UNBOUND:
pic_dwo_objects = depset()
return cc_common_internal.create_compilation_outputs(
objects = objects,
pic_objects = pic_objects,
lto_compilation_context = lto_compilation_context,
dwo_objects = dwo_objects,
pic_dwo_objects = pic_dwo_objects,
)

def _merge_compilation_outputs(*, compilation_outputs = []):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8135,6 +8135,64 @@ public void testCheckPrivateApiAllowlistAllowsPrivateParameter() throws Exceptio
getConfiguredTarget("//tools/build_defs/android:custom");
}

@Test
public void testDwoObjectsAllowlistBlocksPrivateParameter() throws Exception {
scratch.file(
"foo/BUILD", "load(':custom_rule.bzl', 'custom_rule')", "custom_rule(name = 'custom')");
scratch.file(
"foo/custom_rule.bzl",
"def _impl(ctx):",
" cc_common.create_compilation_outputs(dwo_objects = depset())",
" return []",
"custom_rule = rule(",
" implementation = _impl,",
")");

AssertionError e =
assertThrows(AssertionError.class, () -> getConfiguredTarget("//foo:custom"));

assertThat(e).hasMessageThat().contains("cannot use private API");
}

@Test
public void testPicDwoObjectsAllowlistBlocksPrivateParameter() throws Exception {
scratch.file(
"foo/BUILD", "load(':custom_rule.bzl', 'custom_rule')", "custom_rule(name = 'custom')");
scratch.file(
"foo/custom_rule.bzl",
"def _impl(ctx):",
" cc_common.create_compilation_outputs(pic_dwo_objects = depset())",
" return []",
"custom_rule = rule(",
" implementation = _impl,",
")");

AssertionError e =
assertThrows(AssertionError.class, () -> getConfiguredTarget("//foo:custom"));

assertThat(e).hasMessageThat().contains("cannot use private API");
}

@Test
public void testPicDwoObjectsAllowlistAllowsPrivateParameter() throws Exception {
scratch.file(
"bazel_internal/test_rules/cc/BUILD",
"load(':custom_rule.bzl', 'custom_rule')",
"custom_rule(name = 'custom')");
scratch.file(
"bazel_internal/test_rules/cc/custom_rule.bzl",
"def _impl(ctx):",
" cc_common.create_compilation_outputs(",
" dwo_objects = depset(),",
" pic_dwo_objects = depset(),",
")",
" return []",
"custom_rule = rule(",
" implementation = _impl,",
")");
getConfiguredTarget("//bazel_internal/test_rules/cc:custom");
}

// grep_includes is not supported by Bazel.
@Test
public void testGrepIncludesIsSetToNullInsideCcToolchain() throws Exception {
Expand Down

0 comments on commit 9772f03

Please sign in to comment.