Skip to content

Commit

Permalink
Fix dynamic_deps not working across packages
Browse files Browse the repository at this point in the history
The problem was that the code handling the feature
COPY_DYNAMIC_LIBRARIES_TO_BINARY in cc_binary wasn't modified to account for
dynamic dependencies.

RELNOTES:none
PiperOrigin-RevId: 507748909
Change-Id: I4c7c03d38274167110c4b4f068e79befaf1e7b17
  • Loading branch information
oquenchil authored and copybara-github committed Feb 7, 2023
1 parent ba9e2f8 commit 4ed6327
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def _create_transitive_linking_actions(
win_def_file = win_def_file,
)
cc_launcher_info = cc_internal.create_cc_launcher_info(cc_info = cc_info_without_extra_link_time_libraries, compilation_outputs = cc_compilation_outputs_with_only_objects)
return (cc_linking_outputs, cc_launcher_info, rule_impl_debug_files)
return (cc_linking_outputs, cc_launcher_info, rule_impl_debug_files, cc_linking_context)

def _use_pic(ctx, cc_toolchain, cpp_config, feature_configuration):
if _is_link_shared(ctx):
Expand Down Expand Up @@ -732,7 +732,7 @@ def cc_binary_impl(ctx, additional_linkopts):
if extra_link_time_libraries != None:
linker_inputs_extra, runtime_libraries_extra = extra_link_time_libraries.build_libraries(ctx = ctx, static_mode = linking_mode != linker_mode.LINKING_DYNAMIC, for_dynamic_library = _is_link_shared(ctx))

cc_linking_outputs_binary, cc_launcher_info, rule_impl_debug_files = _create_transitive_linking_actions(
cc_linking_outputs_binary, cc_launcher_info, rule_impl_debug_files, deps_cc_linking_context = _create_transitive_linking_actions(
ctx,
cc_toolchain,
feature_configuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ cc_shared_library(
],
"//conditions:default": [],
}),
dynamic_deps = ["bar_so"],
dynamic_deps = [
"bar_so",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:diff_pkg_so"
],
features = ["windows_export_all_symbols"],
preloaded_deps = ["preloaded_dep"],
deps = [
Expand Down Expand Up @@ -150,6 +153,7 @@ cc_library(
"qux",
"qux2",
"prebuilt",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:diff_pkg"
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#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/preloaded_dep.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/qux.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3/diff_pkg.h"

int foo() {
diff_pkg();
bar();
baz();
qux();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,16 @@ def _debug_files_test_impl(ctx):
actual_files = []
for debug_file in target_under_test[OutputGroupInfo].rule_impl_debug_files.to_list():
actual_files.append(debug_file.basename)
expected_files = ["bar_so_exports.txt", "bar_so_link_once_static_libs.txt", "foo_so_exports.txt", "foo_so_link_once_static_libs.txt", "binary_link_once_static_libs.txt"]

expected_files = [
"bar_so_exports.txt",
"bar_so_link_once_static_libs.txt",
"diff_pkg_so_exports.txt",
"diff_pkg_so_link_once_static_libs.txt",
"foo_so_exports.txt",
"foo_so_link_once_static_libs.txt",
"binary_link_once_static_libs.txt",
]
asserts.equals(env, expected_files, actual_files)

return analysistest.end(env)
Expand All @@ -166,8 +175,10 @@ def _runfiles_test_impl(ctx):
expected_suffixes = [
"libfoo_so.so",
"libbar_so.so",
"libdiff_pkg_so.so",
"Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary_Slibfoo_Uso.so",
"Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary_Slibbar_Uso.so",
"Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary3_Slibdiff_Upkg_Uso.so",
"Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary/renamed_so_file_copy.so",
"Smain_Sstarlark_Stests_Sbuiltins_Ubzl_Scc_Scc_Ushared_Ulibrary_Stest_Ucc_Ushared_Ulibrary/libdirect_so_file.so",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ cc_library(
hdrs = ["bar.h"],
)

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

cc_shared_library(
name = "diff_pkg_so",
features = ["windows_export_all_symbols"],
deps = [
":diff_pkg",
],
)

cc_shared_library_permissions(
name = "permissions",
targets = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 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_library3/diff_pkg.h"

int diff_pkg() { return 42; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2023 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_DIFF_PKG_H_
#define EXAMPLES_TEST_CC_SHARED_LIBRARY_DIFF_PKG_H_

int diff_pkg();

#endif // EXAMPLES_TEST_CC_SHARED_LIBRARY_DIFF_PKG_H_

0 comments on commit 4ed6327

Please sign in to comment.