pybind11_bazel icon indicating copy to clipboard operation
pybind11_bazel copied to clipboard

pybind_libraries get compiled twice

Open matte1 opened this issue 2 years ago • 3 comments

    Compiling foo/bar/target__pybind.cc; 1s remote-cache, linux-sandbox
    Compiling foo/bar/target__pybind.cc; 1s remote-cache, linux-sandbox

I'm not sure if I'm using the rule correctly or if this is intended behavior but I seem to be getting two compilations for my pybind targets w/ very slightly different compiler options.

19,21c19,20
< bazel-out/k8-opt/bin/foo/bar/target__pybind.pic.d
< '-frandom-seed=bazel-out/k8-opt/bin/foo/bar/target__pybind_cc/target__pybind.pic.o'
< -fPIC
---
> bazel-out/k8-opt/bin/foo/bar/target__pybind_cc/target__pybind.d
> '-frandom-seed=bazel-out/k8-opt/foo/bar/target__pybind_cc/target__pybind.o'
163c162
< bazel-out/k8-opt/bin/foo/bar/target__pybind_cc/target__pybind.pic.o)
---
> bazel-out/k8-opt/bin/foo/bar/target__pybind_cc/target__pybind.o)

matte1 avatar Dec 08 '22 19:12 matte1

How much trouble is it to provide a reproducer (something that I could git clone unzip or similar, then run some commands you give me)?

I'm not a blaze expert myself, but I'm pretty sure there are valid situations in which there are multiple compilations for the same sources, but without a reproducer it's difficult to tell if that's a situation you have. It could also happen by accident.

rwgk avatar Dec 08 '22 22:12 rwgk

Hmmm it seems like this might be on me. I'm using pybind_library and then using that as a srcs in pybind_extension. If I just use the pybind_extension it seems like things only get compiled once. Sorry I don't have a good reproduction for you, this is pretty tightly embedded in our code base and would be non-trivial to get a minimal reproduction. Happy to close it though as this seems to solve my issue.

matte1 avatar Dec 09 '22 04:12 matte1

pybind_library and then using that as a srcs in pybind_extension

Did you already try using that as deps?

That's how we do it internally. I'm not very familiar with the external side myself, which is a lot less developed than the internal adaption of the same core tool.

For reasons I don't know, here cc_binary is used instead of pybind_extension:

https://github.com/pybind/pybind11_abseil/blob/d5d078954491d227bfbb4c528e0645453ef4032c/pybind11_abseil/BUILD

What I know though is that that works.

rwgk avatar Dec 09 '22 05:12 rwgk