A rule to link with -force_load for direct deps#358
Merged
jerrymarino merged 3 commits intomasterfrom Nov 24, 2021
Merged
Conversation
ld has different behavior when loading members of a static library VS objects as far as visibility. Under `-dynamic` - linked _swift object files_ can have public visibility - symbols from _swift static libraries_ are omitted unless used, and not visible otherwise By using `-force_load`, we can load static libraries in the attributes of an application's direct depenencies. These args need go at the _front_ of the linker invocation otherwise these arguments don't work with lds logic. Why not put it into `rules_apple`? Ideally it could be, and perhaps consider a PR to there .The underlying java rule, `AppleBinary.linkMultiArchBinary` places `extraLinkopts` at the end of the linker invocation. At the time of writing these args need to go into the current rule context where `AppleBinary.linkMultiArchBinary` is called. One use case of this is that iOS developers want to load above mentioned symbols from applications. Another alternate could be to create an aspect, that actually generates a different application and linker invocation instead of force loading symbols. This could be more complicated from an integration perspective so it isn't used. Another case is present in dynamic frameworks in rules_apple ( bazelbuild/rules_apple#332 )
c62dc24 to
6745788
Compare
thiagohmcruz
approved these changes
Nov 24, 2021
congt
reviewed
Nov 24, 2021
rules/app.bzl
Outdated
| application_kwargs["families"] = application_kwargs.pop("families", ["iphone", "ipad"]) | ||
|
|
||
| import_middleman(name = name + ".import_middleman", deps = library.deps, tags = ["manual"]) | ||
| force_load_direct_deps(name = name + ".__internal__.force_load_direct_deps", deps = library.deps, tags = ["manual"]) |
Contributor
There was a problem hiding this comment.
Should we only force load swift_library?
Contributor
Author
There was a problem hiding this comment.
Nope we need to force load c++/objc too
Plus misc cleanups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ld has different behavior when loading members of a static library VS objects
as far as visibility. Under
-dynamicBy using
-force_load, we can load static libraries in the attributes of anapplication's direct depenencies. These args need go at the front of the
linker invocation otherwise these arguments don't work with lds logic.
Why not put it into
rules_apple? Ideally it could be, and perhaps consider aPR to there .The underlying java rule,
AppleBinary.linkMultiArchBinaryplaces
extraLinkoptsat the end of the linker invocation. At the time ofwriting these args need to go into the current rule context where
AppleBinary.linkMultiArchBinaryis called.One use case of this is that iOS developers want to load above mentioned
symbols from applications. Another alternate could be to create an aspect, that
actually generates a different application and linker invocation instead of
force loading symbols. This could be more complicated from an integration
perspective so it isn't used. Another case is present in dynamic frameworks in
rules_apple ( bazelbuild/rules_apple#332 )