piratf
piratf

Reputation: 107

Can I set different macro value in cc_library depend on different cc_binary?

There is a cc_library target named 'L', and cc_binary targets 'A', 'B', 'C' depend on it.

Library L implements a transaction framework, contains an plain char array with length 100 for example, and lots of complicated logic on the array.

Now target B need a larger data size, but target A and C want smaller size to hold more transactions at the same time.

When using makefile, a doable way is using #ifdef/#else in L to set different macro values for the length. Then loop A, B, C, build them with different -D=A, -D=B and -D=C. So the lib L will have different array length in three different binary.

Is there a better way to implement it? Can I do the same thing in bazel?

Upvotes: 0

Views: 484

Answers (1)

rds
rds

Reputation: 26984

You can follow exactly the same approach:

  • using define on a cc_library to define multiple versions of the library (such as "L_complex_transactions" on which A depends and "L_many_transactions" on which B and C depend).

  • and better use config_setting on the binaries, and a select statement on the cc_library to select the appropriate define.

Upvotes: 1

Related Questions