How to pass cc_binary defines to all cc_libraries

已查看 88 次
跳至第一个未读帖子

Shareef Jalloq

未读,
2022年11月25日 07:32:562022/11/25
收件人 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

未读,
2022年11月25日 11:55:262022/11/25
收件人 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

未读,
2022年11月25日 17:27:412022/11/25
收件人 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

未读,
2022年11月25日 19:12:482022/11/25
收件人 bazel-discuss
Thanks.  I'll take a look at this option.
回复全部
回复作者
转发
0 个新帖子