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

Link-Time Substitution: Native Support #200

Open
cramertj opened this issue Sep 27, 2023 · 0 comments
Open

Link-Time Substitution: Native Support #200

cramertj opened this issue Sep 27, 2023 · 0 comments
Labels
P3 Accepted issue. Team is likely to fix this issue in the future, but no short-term promises are made. type: feature request Request for new, generally useful functionality that is missing

Comments

@cramertj
Copy link

Description of the problem / feature request:

I'm using link-time substitution in order to provide different implementations of the same function in different binaries (e.g. test targets, or targets with different features enabled) within the same overall build.

When working a large codebase, it's easy to either:

  • Forget to depend on a target which defines an implementation of an interface, resulting in a linker error about missing functions.
  • Accidentally depend on more than one implementation of an interface, resulting in an ODR violation.

I would like to be able to tag the targets which declare the interface with e.g. a declares_symbols = [ ... ] argument, and the targets which define it with e.g. defines_symbols = [ ... ] such that I get a bazel error if I try to build a target which depends on a symbol declaration which does not have exactly one definition in its dependency tree.

For example:

cc_library(
   name = "what_color_declaration"
   hdrs = [ "what_color_declaration.h" ]
   declares_symbols = [ "what_color" ]
)

cc_library(
   name = "what_color_returns_blue"
   srcs = [ "what_color_returns_blue.cc" ]
   defines_symbols = [ "what_color" ]
)

cc_binary(
   name = "binary_a"
   srcs = [ "binary_a.cc" ]
    // ERROR: must provide definition of `what_color`,
    // declared by dep `what_color_declaration`.
   deps = [ ":what_color_declaration" ]
)

Feature requests: what underlying problem are you trying to solve with this feature?

I want to swap out the implementation of certain functions in different link targets (e.g. binary, test, static library) without rebuilding all dependencies.

@comius comius added type: feature request Request for new, generally useful functionality that is missing P3 Accepted issue. Team is likely to fix this issue in the future, but no short-term promises are made. labels Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Accepted issue. Team is likely to fix this issue in the future, but no short-term promises are made. type: feature request Request for new, generally useful functionality that is missing
Projects
None yet
Development

No branches or pull requests

2 participants