Skip to content

A rule to link with -force_load for direct deps#358

Merged
jerrymarino merged 3 commits intomasterfrom
jmarino/force_load
Nov 24, 2021
Merged

A rule to link with -force_load for direct deps#358
jerrymarino merged 3 commits intomasterfrom
jmarino/force_load

Conversation

@jerrymarino
Copy link
Contributor

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 )

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 )
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"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we only force load swift_library?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope we need to force load c++/objc too

@jerrymarino jerrymarino enabled auto-merge (squash) November 24, 2021 20:30
@jerrymarino jerrymarino merged commit da7f206 into master Nov 24, 2021
@jerrymarino jerrymarino deleted the jmarino/force_load branch November 24, 2021 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants