Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.4.1] Revert "[7.4.0] Propagate linkopts of header-only libraries to cc_shared_library" #24087

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/main/starlark/builtins_bzl/common/cc/cc_shared_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,7 @@ def _filter_inputs(
continue
linker_inputs_seen[stringified_linker_input] = True
owner = str(linker_input.owner)
if semantics.is_bazel and not linker_input.libraries:
# Linker inputs that only provide flags, no code, are considered
# safe to link statically multiple times.
# TODO(bazel-team): semantics.should_create_empty_archive() should be
# cleaned up and return False in every case. cc_libraries shouldn't
# produce empty archives. For now issue #19920 is only fixed in Bazel.
_add_linker_input_to_dict(linker_input.owner, linker_input)
linker_inputs_count += 1
elif owner in targets_to_be_linked_dynamically_set:
if owner in targets_to_be_linked_dynamically_set:
unused_dynamic_linker_inputs[transitive_exports[owner].owner] = None

# Link the library in this iteration dynamically,
Expand All @@ -463,6 +455,11 @@ def _filter_inputs(
_add_linker_input_to_dict(linker_input.owner, transitive_exports[owner])
linker_inputs_count += 1
elif owner in targets_to_be_linked_statically_map:
if semantics.is_bazel and not linker_input.libraries:
# TODO(bazel-team): semantics.should_create_empty_archive() should be
# cleaned up and return False in every case. cc_libraries shouldn't
# produce empty archives. For now issue #19920 is only fixed in Bazel.
continue
if owner in link_once_static_libs_map:
# We are building a dictionary that will allow us to give
# proper errors for libraries that have been linked multiple
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ NO_BUILD_TAGS = [
licenses(["notice"])

package(
default_visibility = ["//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:__subpackages__"],
default_visibility = ["//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:__subpackages__"],
)

py_test(
Expand Down Expand Up @@ -119,7 +119,7 @@ cc_shared_library(
}),
dynamic_deps = [
"bar_so",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test3:diff_pkg_so",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:diff_pkg_so",
"private_lib_so",
],
exports_filter = [
Expand Down Expand Up @@ -176,7 +176,7 @@ cc_library(
# Not exported.
"qux",
"prebuilt",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test3:diff_pkg"
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:diff_pkg"
],
)

Expand Down Expand Up @@ -275,7 +275,7 @@ cc_shared_library(
}),
exports_filter = [
"bar3", # Exported transitive dependency
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test3:bar",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:bar",
],
features = ["windows_export_all_symbols"],
user_link_flags = select({
Expand Down Expand Up @@ -330,7 +330,7 @@ cc_library(
srcs = ["bar3.cc"],
hdrs = ["bar3.h"],
deps = [
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test3:bar",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3:bar",
],
)

Expand Down Expand Up @@ -371,17 +371,17 @@ additional_inputs_test(
build_failure_test(
name = "link_once_repeated_test_binary",
messages = [
"cc_shared_library/test:barX\",",
"cc_shared_library/test_cc_shared_library:barX\",",
],
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/failing_targets:should_fail_binary",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets:should_fail_binary",
)

build_failure_test(
name = "link_once_repeated_test_shared_lib",
messages = [
"cc_shared_library/test:barX\",",
"cc_shared_library/test_cc_shared_library:barX\",",
],
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/failing_targets:should_fail_shared_lib",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets:should_fail_shared_lib",
)

paths_test(
Expand Down Expand Up @@ -473,9 +473,6 @@ genrule(
cc_library(
name = "hdr_only",
hdrs = [":hdr_only_hdr"],
linkopts = [
"-Wl,-rpath,hdr_only",
],
)

cc_library(
Expand All @@ -489,7 +486,6 @@ cc_library(
cc_shared_library(
name = "external_export_so",
exports_filter = ["@my_test_repo//:__pkg__"],
tags = ["bazel_only"],
deps = [
":external_export",
],
Expand All @@ -498,13 +494,13 @@ cc_shared_library(
build_failure_test(
name = "two_dynamic_deps_same_export_in_so_test",
message = "Two shared libraries in dependencies export the same symbols",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/failing_targets:two_dynamic_deps_same_export_in_so",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets:two_dynamic_deps_same_export_in_so",
)

build_failure_test(
name = "two_dynamic_deps_same_export_in_binary_test",
message = "Two shared libraries in dependencies link the same library statically",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/failing_targets:two_dynamic_deps_same_export_in_binary",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets:two_dynamic_deps_same_export_in_binary",
)

interface_library_output_group_test(
Expand Down Expand Up @@ -535,36 +531,36 @@ check_linking_action_lib_parameters_test(
build_failure_test(
name = "shared_library_without_deps",
message = "'cc_shared_library' must have at least one dependency in 'deps' (or 'roots')",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/failing_targets:failing_with_no_deps_so",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets:failing_with_no_deps_so",
)

build_failure_test(
name = "direct_dep_with_only_shared_lib_file",
message = "Do not place libraries which only contain a precompiled dynamic library",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/failing_targets:failing_only_dynamic_lib",
target = "//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/failing_targets:failing_only_dynamic_lib",
)

exports_test(
name = "exports_foo_test",
target = ":foo_so",
targets_that_should_be_claimed_to_be_exported = [
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:indirect_dep2",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:baz",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:foo",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:cc_lib_with_no_srcs",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:nocode_cc_lib",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:should_not_be_linked_cc_lib",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:a_suffix",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:indirect_dep2",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:baz",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:foo",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:cc_lib_with_no_srcs",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:nocode_cc_lib",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:should_not_be_linked_cc_lib",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:a_suffix",
],
)

exports_test(
name = "external_export_exports_test",
bazel_only = True,
target = "external_export_so",
bazel_only = True,
targets_that_should_be_claimed_to_be_exported = [
"@@test_repo~//:bar",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:external_export",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:external_export",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// 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/a_suffix.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/a_suffix.h"

int a_suffix() { return 42; }
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// 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/bar.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/bar.h"

int bar() { return 42; }
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// 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/bar2.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/bar2.h"

int bar2() { return 42; }
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// 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/bar3.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/bar3.h"

int bar3() { return 42; }
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// 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/barX.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/barX.h"

int barX() { return 42; }
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// 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/baz.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/baz.h"

int baz() { return 42; }
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
// 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/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_lib.h"
int direct_so_file_cc_lib() { return 0; }
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
// 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/direct_so_file_cc_lib2.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/direct_so_file_cc_lib2.h"
int direct_so_file_cc_lib2() { return 0; }
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ TAGS = [

cc_binary(
name = "should_fail_binary",
dynamic_deps = ["//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:bar_so"],
dynamic_deps = ["//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:bar_so"],
tags = TAGS,
deps = [
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:barX",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:barX",
],
)

cc_shared_library(
name = "should_fail_shared_lib",
dynamic_deps = ["//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:bar_so"],
dynamic_deps = ["//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:bar_so"],
deps = [
":intermediate",
],
Expand All @@ -28,7 +28,7 @@ cc_shared_library(
cc_library(
name = "intermediate",
deps = [
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test:barX",
"//src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library:barX",
],
)

Expand Down Expand Up @@ -112,3 +112,4 @@ genrule(
outs = ["libabc.so"],
cmd = "touch \"$@\"",
)

Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
// 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/bar.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/baz.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/direct_so_file_cc_lib.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/direct_so_file_cc_lib2.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/qux.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test3/diff_pkg.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/bar.h"
#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/qux.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library3/diff_pkg.h"

int foo() {
diff_pkg();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
#include <iostream>

#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test/foo.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/foo.h"

int main() {
std::cout << "hello " << foo() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// 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/bar.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/bar.h"

int foo() {
bar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// 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/qux.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/qux.h"

int qux() { return 42; }
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// 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/qux2.h"
#include "src/main/starlark/tests/builtins_bzl/cc/cc_shared_library/test_cc_shared_library/qux2.h"

int qux2() { return 42; }
Loading
Loading