wide-midnight-78598
12/06/2022, 5:27 AMexamples/cc/core/src/greeter.c
- the cc
backend knows how to discover the associated public header (via some dep inference rules, using a common C++ convention).
However, if I'm discovering that public header from another module (e.g. the "app" module), it discovers the header file correctly, but from the header, the dep inference doesn't currently know that is has to compile the associated C/C++ source file to actually be useful (nor does there necessarily need to be an associated source file, for a given header).
I guess what I'm asking is whether dep inference should be something that is more "targeted" in nature (we need exactly this header, so try to figure out which are the associated source files), or if it should follow a kitchen sink approach (find a source root, enumerate ALL source files and headers below that, mash it all together, and try to make something useful)?
The "easy" solution which I already have is to ensure the "app" module has an explicit dependency on the "core" cc_library
target, which knows how to package the library and public headers correctly.
That feels like a cop-out, since compiling dependencies from source is a valid workflow.wide-midnight-78598
12/06/2022, 5:28 AMgreeter.h
which is inside the core
module, so inspect the core BUILD
and see if there are any cc_library
targets present, and then take a dep on those"?
Still feels cop-outy, but š¤·wide-midnight-78598
12/06/2022, 5:30 AMwide-midnight-78598
12/06/2022, 5:41 AMcc_library
your header is a part of, and make sure you use that - as it might have special link/compile flaghappy-kitchen-89482
12/06/2022, 7:03 AM#include path/to/greeter.h
?happy-kitchen-89482
12/06/2022, 7:04 AMpath/to/greeter.cc
?happy-kitchen-89482
12/06/2022, 7:06 AM<http://greeter.cc|greeter.cc>
implied by a dep on greeter.h
. That is the whole point of header files! You can compile translation units completely independently.happy-kitchen-89482
12/06/2022, 7:06 AMwide-midnight-78598
12/06/2022, 1:08 PMcc_library
targets, and pulling that in. But, it already doesn't account for a whole host of workflows I think (even some of my workflows own, for that matter, between test and production code).
I could probably make the argument that if there isn't a cc_library
, this could be a use case for a synthetic target? Might not be needed though.wide-midnight-78598
12/06/2022, 1:15 PMthe question is how to do the right thing at link timeI didn't really think about compiling the missing files at link time, that feels like a weird time to do it - but I don't see why not actually. C++ is a great case for the visibility code too, which will need to be adhered to. In my brain, I treat each of my
core
/ app
/ whatever modules as standalone "things". That might not be the Pants way, but it's definitely the SJ's brain way.
From that perspective, not importing a cc_library
would be weird, because you're potentially trying to grab an unfinished "thing".
However, I can validly see someone using multiple source roots, and just wanting to compile codewide-midnight-78598
12/06/2022, 1:16 PMwide-midnight-78598
12/06/2022, 1:20 PMhappy-kitchen-89482
12/06/2022, 6:34 PMwide-midnight-78598
12/06/2022, 6:39 PMhappy-kitchen-89482
12/06/2022, 7:31 PMcareful-address-89803
12/08/2022, 12:01 AMsource_code
of "app/main.c" depends on the `exported_symbols`of "core/greeter.h"; but you can use different rules to infer that the binary
of "app/main.c" depends on the exported_symbols
of "core/greeter.h" so Pants knows it needs to find the translation_unit
that includes those symbols and its associated source_code