bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Can't spawn builtin actions from a rule implementation

Open zrlk opened this issue 11 years ago • 5 comments

I'd like to be able to use the builtin version of the C++ compilation action in a custom rule. Right now it seems like this is impossible and the only thing I'm able to do is cons up a string to pass to the shell, maybe referring to $(CC) and friends, and explicitly walking through ctx.targets.deps to figure out my includes and copts.

zrlk avatar Apr 13 '15 16:04 zrlk

Supposing you're writing this in Skylark, does creating native.cc_binary help?

laszlocsomor avatar Apr 14 '15 07:04 laszlocsomor

Are you writing a "macro" (a function that expands at BUILD loading time and emits existing rules), or a native rule? If the latter, can you post a snippet or a more detailed explanation of what you are trying to do?

hanwen avatar Apr 15 '15 08:04 hanwen

The macro and rule we're using is https://github.com/google/kythe/blob/master/tools/build_rules/genproto.bzl ; for Java, this is based on genproto from Bazel's build_rules. Since we started the latter has grown a java_compile_command--why doesn't/shouldn't this use the builtin Java compile action?

zrlk avatar Apr 15 '15 19:04 zrlk

Java genproto is a bit of a special case. Since the output file names depend on the contents of the .proto file, it can't easily be fitted in as a normal Java compile (for normal Java compiles, you have to specify file names upfront.)

hanwen avatar Apr 17 '15 13:04 hanwen

I'm going to mark this as WAI.

If you want to depend on C++ artifacts, use a macro. If you want to interoperate with C++ code in rules, https://github.com/google/bazel/issues/146 is the right bug.

hanwen avatar Aug 13 '15 16:08 hanwen