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

objc_library sdk_dylibs not propagated to cc_binary rules, only apple_binary rules #13205

Closed
warriorstar-orion opened this issue Mar 11, 2021 · 6 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) platform: apple stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: feature request

Comments

@warriorstar-orion
Copy link

warriorstar-orion commented Mar 11, 2021

Description of the problem / feature request:

I'm no C++ or linking expert so I have no idea if this should work or not, but I believe it should. The documentation for objc_library.sdk_dylibs states:

When linking a binary, all libraries named in that binary's transitive dependency graph are used.

However, this is only the case for apple_binary rules, not cc_binary rules. The repo https://github.com/warriorstar-orion/bazel_objc_dylibs is a bare minimum demonstration and should allow you to reproduce the issue.

A sample run:

% clang -v
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% xcrun --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
% xcrun --show-sdk-version
11.1

% bazel build :thing_apple_binary
INFO: Analyzed target //:thing_apple_binary (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:thing_apple_binary up-to-date:
  bazel-out/apl-darwin_x86_64-fastbuild/bin/thing_apple_binary_lipobin
INFO: Elapsed time: 0.136s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

% bazel build :thing_cc_binary
INFO: Analyzed target //:thing_cc_binary (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /Users/orion/ExternalRepos/bazel_objc_dylibs/BUILD.bazel:15:10: Linking thing_cc_binary failed: (Exit 1): cc_wrapper.sh failed: error executing command external/local_config_cc/cc_wrapper.sh @bazel-out/darwin-fastbuild/bin/thing_cc_binary-2.params

Use --sandbox_debug to see verbose messages from the sandbox cc_wrapper.sh failed: error executing command external/local_config_cc/cc_wrapper.sh @bazel-out/darwin-fastbuild/bin/thing_cc_binary-2.params

Use --sandbox_debug to see verbose messages from the sandbox
Undefined symbols for architecture x86_64:
  "_iconv", referenced from:
      _main in liblibthing.a(main.o)
  "_iconv_close", referenced from:
      _main in liblibthing.a(main.o)
  "_iconv_open", referenced from:
      _main in liblibthing.a(main.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Target //:thing_cc_binary failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.239s, Critical Path: 0.10s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
%

bazel aquery confirms the lack of an added linker option:

% bazel aquery :thing_apple_binary 2> /dev/null | grep -i iconv
    -liconv \
% bazel aquery :thing_cc_binary 2> /dev/null | grep -i iconv
%

What operating system are you running Bazel on?

% uname -a
Darwin ophelia.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64
% sw_vers -productVersion
11.2

What's the output of bazel info release?

release 4.0.0-homebrew

Have you found anything relevant by searching the web?

Nothing stands out

@warriorstar-orion
Copy link
Author

I should add the practical effect of this is that if an objc_library which uses sdk_dylibs is far down the dependency chain, a cc_binary won't properly link everything unless it itself has a e.g. linkopts = ["-liconv"], which is very spooky-action-at-a-distance, and also pushes logic about platform-specific attributes in a place where the given library may have already (and most likely if a library is multi-platform) taken care of.

@aiuto aiuto added team-Rules-CPP Issues for C++ rules untriaged labels Mar 31, 2021
@oquenchil oquenchil added P3 We're not considering working on this, but happy to review a PR. (No assignee) platform: apple type: feature request and removed untriaged labels May 10, 2021
@cpsauer
Copy link
Contributor

cpsauer commented Mar 10, 2022

Just ran into this one, too. Heads that there seems to be a much more general problem with linkopt interoperability here, so I filed #10738

@cpsauer
Copy link
Contributor

cpsauer commented Apr 15, 2022

Note, this issue seems likely fixed in the latest bazel rolling release. See #15014 (comment)

@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Jun 20, 2023
@github-actions
Copy link

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2023
@keith
Copy link
Member

keith commented Sep 19, 2023

I agree this is probably fixed but I haven't tested either

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) platform: apple stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: feature request
Projects
None yet
Development

No branches or pull requests

5 participants