Skip to content

Commit 6fd317b

Browse files
katzdmcopybara-github
authored andcommitted
Avoid deduplicating linkopts of cc_shared_library dependencies.
Linker inputs for dependencies of `cc_shared_library` are currently passing their `linkopts` as a `depset`, which leads to deduplication of the flags thereby passed. Consequently, a sequence of well-formed flags like `-framework Security -framework IOKit` gets collapsed to `-framework Security IOKit`; the linker then interprets `IOKit` as an object file that it's unable to locate, which yields a malformed link line. Passing `linkopts` directly rather than wrapping it in `depset` appears to resolve the issue. I've added a test that replicates the original issue; since `-framework` isn't meaningful on all platforms, I've only enabled it for MacOS. Note that the tests in this repository utilize the `rules_cc` repository rather than the built-in rules; therefore, I don't think the new test can be expected to pass until the change has been propagated there, and the controlling [`MODULE.bazel.lock` entry](https://github.com/bazelbuild/bazel/blob/HEAD/src/test/tools/bzlmod/MODULE.bazel.lock#L113) has been updated. I've tested it locally by `cat`ing a `local_path_override` directive to the `MODULE.bazel` file that [gets synthesized](https://github.com/bazelbuild/bazel/blob/e887cfbfd641f57a3cdd950249daf9b568ebaeb5/src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh#L49) for these tests, in order to point the tests towards a local fork of `rules_cc` with this same change applied; under these conditions, the test passes. Closes #27735. Closes #27755. PiperOrigin-RevId: 845984933 Change-Id: I866456d29e851d24984b7d91f4613bc2df6ae2ad
1 parent 34f61b4 commit 6fd317b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cc/private/rules_impl/cc_shared_library.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def _wrap_static_library_with_alwayslink(ctx, feature_configuration, cc_toolchai
287287
return cc_common.create_linker_input(
288288
owner = linker_input.owner,
289289
libraries = depset(direct = new_libraries_to_link),
290-
user_link_flags = depset(direct = linker_input.user_link_flags),
290+
user_link_flags = linker_input.user_link_flags,
291291
additional_inputs = depset(direct = linker_input.additional_inputs),
292292
)
293293

0 commit comments

Comments
 (0)