Skip to content

Commit

Permalink
Make cc_toolchain.(static|dynamic)_runtime_libs attributes optional
Browse files Browse the repository at this point in the history
Issue for the --incompatible_disable_runtimes_filegroups incompatible flag
(which this cl is a step towards to): #6942
Tracking issue for legacy crosstool fields removal: #5883

RELNOTES: cc_toolchain.(static|dynamic)_runtime_libs attributes are now optional
PiperOrigin-RevId: 225990391
  • Loading branch information
hlopko authored and Copybara-Service committed Dec 18, 2018
1 parent 0d5d3a5 commit d42c2a5
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ static CcToolchainProvider getCcToolchainProvider(
final NestedSet<Artifact> staticRuntimeLinkInputs;
final Artifact staticRuntimeLinkMiddleman;
if (toolchainInfo.supportsEmbeddedRuntimes()) {
if (staticRuntimeLibDep == null) {
throw ruleContext.throwWithRuleError(
"Toolchain supports embedded runtimes, but didn't "
+ "provide static_runtime_libs attribute.");
}
staticRuntimeLinkInputs =
staticRuntimeLibDep.getProvider(FileProvider.class).getFilesToBuild();
} else {
Expand Down Expand Up @@ -505,6 +510,11 @@ static CcToolchainProvider getCcToolchainProvider(
List<Artifact> dynamicRuntimeLinkInputs = new ArrayList<>();
Artifact dynamicRuntimeLinkMiddleman;
if (toolchainInfo.supportsEmbeddedRuntimes()) {
if (dynamicRuntimeLibDep == null) {
throw ruleContext.throwWithRuleError(
"Toolchain supports embedded runtimes, but didn't "
+ "provide dynamic_runtime_libs attribute.");
}
NestedSetBuilder<Artifact> dynamicRuntimeLinkSymlinksBuilder = NestedSetBuilder.stableOrder();
for (Artifact artifact :
dynamicRuntimeLibDep.getProvider(FileProvider.class).getFilesToBuild()) {
Expand Down Expand Up @@ -835,6 +845,9 @@ private static CppModuleMap createCrosstoolModuleMap(CcToolchainAttributesProvid

static TransitiveInfoCollection selectDep(
ImmutableList<? extends TransitiveInfoCollection> deps, Label label) {
if (deps.isEmpty()) {
return null;
}
for (TransitiveInfoCollection dep : deps) {
if (dep.getLabel().equals(label)) {
return dep;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ Currently unused (<a href="https://github.com/bazelbuild/bazel/issues/6928">#692
<p>cc_toolchain will select one of these libraries based on the label from
crosstool_proto.static_runtimes_filegroup field.</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("static_runtime_libs", LABEL_LIST).legacyAllowAnyFileType().mandatory())
.add(attr("static_runtime_libs", LABEL_LIST).legacyAllowAnyFileType())
/* <!-- #BLAZE_RULE(cc_toolchain).ATTRIBUTE(dynamic_runtime_libs) -->
A collection of artifacts for dynamic libraries for the C++ runtime library
(e.g. libstdc++.so).
<p>cc_toolchain will select one of these libraries based on the label from
crosstool_proto.dynamic_runtimes_filegroup field.</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("dynamic_runtime_libs", LABEL_LIST).legacyAllowAnyFileType().mandatory())
.add(attr("dynamic_runtime_libs", LABEL_LIST).legacyAllowAnyFileType())
/* <!-- #BLAZE_RULE(cc_toolchain).ATTRIBUTE(module_map) -->
Module map artifact to be used for modular builds.
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,107 @@ public void testFissionConfigWithMissingDwp() throws Exception {
getConfiguredTarget("//a:a");
assertContainsEvent("Tool path for 'dwp' is missing");
}

@Test
public void testRuntimeLibsAttributesAreNotObligatory() throws Exception {
scratch.file(
"a/BUILD",
"filegroup(name='empty') ",
"cc_toolchain_suite(",
" name = 'a',",
" toolchains = { 'k8': ':b' },",
")",
"cc_toolchain(",
" name = 'b',",
" cpu = 'banana',",
" all_files = ':empty',",
" ar_files = ':empty',",
" as_files = ':empty',",
" compiler_files = ':empty',",
" dwp_files = ':empty',",
" linker_files = ':empty',",
" strip_files = ':empty',",
" objcopy_files = ':empty',",
" proto = \"\"\"",
" toolchain_identifier: \"a\"",
" host_system_name: \"a\"",
" target_system_name: \"a\"",
" target_cpu: \"a\"",
" target_libc: \"a\"",
" compiler: \"a\"",
" abi_version: \"a\"",
" abi_libc_version: \"a\"",
"\"\"\")");
reporter.removeHandler(failFastHandler);
useConfiguration("--cpu=k8", "--host_cpu=k8");
getConfiguredTarget("//a:a");
assertNoEvents();
}

@Test
public void testWhenRuntimeLibsAtttributesMandatoryWhenSupportsEmbeddedRuntimes()
throws Exception {
scratch.file(
"a/BUILD",
"filegroup(name='empty') ",
"cc_toolchain_suite(",
" name = 'a',",
" toolchains = { 'k8': ':b', 'k9': ':c' },",
")",
"cc_toolchain(",
" name = 'b',",
" cpu = 'banana',",
" all_files = ':empty',",
" ar_files = ':empty',",
" as_files = ':empty',",
" compiler_files = ':empty',",
" dwp_files = ':empty',",
" linker_files = ':empty',",
" strip_files = ':empty',",
" objcopy_files = ':empty',",
" proto = \"\"\"",
" toolchain_identifier: \"a\"",
" host_system_name: \"a\"",
" target_system_name: \"a\"",
" target_cpu: \"a\"",
" target_libc: \"a\"",
" compiler: \"a\"",
" abi_version: \"a\"",
" abi_libc_version: \"a\"",
" supports_embedded_runtimes: true,",
"\"\"\")",
"cc_toolchain(",
" name = 'c',",
" cpu = 'banana',",
" all_files = ':empty',",
" ar_files = ':empty',",
" as_files = ':empty',",
" compiler_files = ':empty',",
" dwp_files = ':empty',",
" linker_files = ':empty',",
" strip_files = ':empty',",
" objcopy_files = ':empty',",
" static_runtime_libs = [ ':yolo' ],",
" proto = \"\"\"",
" toolchain_identifier: \"a\"",
" host_system_name: \"a\"",
" target_system_name: \"a\"",
" target_cpu: \"a\"",
" target_libc: \"a\"",
" compiler: \"a\"",
" abi_version: \"a\"",
" abi_libc_version: \"a\"",
" supports_embedded_runtimes: true,",
"\"\"\")");
reporter.removeHandler(failFastHandler);
useConfiguration("--cpu=k8", "--host_cpu=k8");
getConfiguredTarget("//a:a");
assertContainsEvent(
"Toolchain supports embedded runtimes, but didn't provide static_runtime_libs attribute.");

useConfiguration("--cpu=k9", "--host_cpu=k9");
getConfiguredTarget("//a:a");
assertContainsEvent(
"Toolchain supports embedded runtimes, but didn't provide dynamic_runtime_libs attribute.");
}
}

0 comments on commit d42c2a5

Please sign in to comment.