Skip to content

Commit

Permalink
Collect implementation_deps in graph node aspect
Browse files Browse the repository at this point in the history
This is needed for implementation_deps of cc_library targets to be linked into cc_binary targets with dynamic_deps and cc_shared_library targets.

Fixes #14731

Closes #14730.

PiperOrigin-RevId: 479253298
Change-Id: I933f2e9fc3171378cc95a50c59a426489b8724c3
  • Loading branch information
fmeum authored and copybara-github committed Oct 6, 2022
1 parent 801e01c commit 21904a9
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public AspectParameters apply(Rule rule) {
: null;
}
};
private static final ImmutableList<String> CC_DEPS_ATTRIBUTES =
ImmutableList.of("deps", "implementation_deps");

@Override
public AspectDefinition getDefinition(AspectParameters aspectParameters) {
Expand All @@ -67,9 +69,12 @@ public ConfiguredAspect create(
RepositoryName toolsRepository)
throws ActionConflictException, InterruptedException {
ImmutableList.Builder<GraphNodeInfo> children = ImmutableList.builder();
if (ruleContext.attributes().has("deps")) {
children.addAll(
AnalysisUtils.getProviders(ruleContext.getPrerequisites("deps"), GraphNodeInfo.class));
for (String depsAttribute : CC_DEPS_ATTRIBUTES) {
if (ruleContext.attributes().has(depsAttribute)) {
children.addAll(
AnalysisUtils.getProviders(
ruleContext.getPrerequisites(depsAttribute), GraphNodeInfo.class));
}
}
return new ConfiguredAspect.Builder(ruleContext)
.addProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ cc_shared_library(
"a_suffix",
],
static_deps = [
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:implementation_dep",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:qux",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:qux2",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:prebuilt",
Expand All @@ -110,6 +111,12 @@ cc_library(
hdrs = ["preloaded_dep.h"],
)

cc_library(
name = "implementation_dep",
srcs = ["implementation_dep.cc"],
hdrs = ["implementation_dep.h"],
)

cc_library(
name = "foo",
srcs = [
Expand All @@ -124,6 +131,7 @@ cc_library(
"//src/conditions:linux": ["IS_LINUX"],
"//conditions:default": [],
}),
implementation_deps = ["implementation_dep"],
deps = [
"preloaded_dep",
"bar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function test_shared_library_symbols() {
check_symbol_absent "$symbols" "_Z3quxv"
check_symbol_absent "$symbols" "_Z4bar3v"
check_symbol_absent "$symbols" "_Z4bar4v"
check_symbol_absent "$symbols" "_Z18implementation_depv"
}

function test_shared_library_user_link_flags() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/baz.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/direct_so_file_cc_lib.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/direct_so_file_cc_lib2.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/implementation_dep.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/preloaded_dep.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/qux.h"

int foo() {
bar();
baz();
implementation_dep();
qux();
#ifdef IS_LINUX
direct_so_file_cc_lib();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/implementation_dep.h"

int implementation_dep() { return 43; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef EXAMPLES_TEST_CC_SHARED_LIBRARY_IMPLEMENTATION_DEP_H_
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_IMPLEMENTATION_DEP_H_

int implementation_dep();

#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_IMPLEMENTATION_DEP_H_
3 changes: 2 additions & 1 deletion src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ EOF
--experimental_link_static_libraries_once \
--experimental_enable_target_export_check --experimental_cc_shared_library \
--experimental_builtins_injection_override=+cc_binary \
--experimental_cc_implementation_deps \
//src/main/starlark/tests/builtins_bzl/cc/... || fail "expected success"
}

run_suite "cc_* built starlark test"
run_suite "cc_* built starlark test"

0 comments on commit 21904a9

Please sign in to comment.