How to pass cc_binary defines to all cc_libraries

76 views
Skip to first unread message

Shareef Jalloq

unread,
Nov 25, 2022, 7:32:56 AM11/25/22
to bazel-discuss
Hi,

sorry, new to bazel and am struggling to understand the nuances of how defines are passed to libraries.  I thought the documentation states that cc_binary.defines are passed to all cc_library dependents but that doesn't seem true.

I have a simple application that looks like:

cc_binary(name="top", deps=["lib_a", "lib_b"], defines=["MYDEF=value"], ...)
cc_library(name="lib_a", srcs = [*.cc, *.h], hdrs=[*.h])
cc_library(name="lib_b", srcs = [*.cc, *.h], hdrs=[*.h])

When building lib_b, bazel doesn't set MYDEF.  How do I do that?

Shareef.

Austin Schuh

unread,
Nov 25, 2022, 11:55:26 AM11/25/22
to Shareef Jalloq, bazel-discuss
The arrow flows the other way.  If you put your defines in lib_a, you will see them in the cc_binary.

Austin

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/f7378a3b-4949-4fc9-913c-786bd6c5df88n%40googlegroups.com.

Austin Schuh

unread,
Nov 25, 2022, 5:27:41 PM11/25/22
to Shareef Jalloq, bazel-discuss
That would work. If you want to propagate information the other way
(build those files multiple times with different parameters),
configuration transitions are what you want. They let you change
flags for a target and all its dependencies. You could then use those
different parameters with a select call to change the defines. But,
that's quite a bit more complicated.

Austin

On Fri, Nov 25, 2022 at 10:36 AM Shareef Jalloq <sha...@jalloq.co.uk> wrote:
>
> Hmm, so I need to set those defines based on which top level cc_binary is being built. So perhaps using cc_library is the wrong thing to do here? Perhaps I should just be including those library files directly in my top level cc_binary?

Shareef Jalloq

unread,
Nov 25, 2022, 7:12:48 PM11/25/22
to bazel-discuss
Thanks.  I'll take a look at this option.
Reply all
Reply to author
Forward
0 new messages