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.
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:
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:
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.