pybind / pybind11_bazel

Bazel wrapper around the pybind11 repository
Other
100 stars 54 forks source link

Added basic example of using pybind11 #86

Closed roceb closed 3 months ago

roceb commented 3 months ago

Created a working example of how to use Pybind11_bazel in an attempt to help solve issue #85 . This uses the example from pybind11 documentation here

laurentlb commented 3 months ago

or based on https://github.com/pybind/pybind11_bazel/issues/78#issuecomment-2016538967, the best would probably be:

bazel_dep(name = "pybind11_bazel", version = "2.12.0")
pybind11_configure = use_extension("@pybind11_bazel//:internal_configure.bzl", "internal_configure_extension")
use_repo(pybind11_configure, "pybind11")

But I'm not comfortable loading a file named internal. Should the file be renamed and be part of the API?

junyer commented 3 months ago

pybind11_bazel v2.12.0 should Just Work™ with nothing more than a bazel_dep() in the MODULE.bazel file. Which is to say, @pybind11 isn't needed, so the WORKSPACE file isn't needed. (The MODULE.bazel.lock file isn't needed either, BTW.)

laurentlb commented 3 months ago

Indeed, @pybind11 is not needed here. But it's sometimes needed and it would be useful to have an example with it.

For example, https://github.com/llvm/llvm-project/blob/66959ff8633684ec285d62ac244d38bfc8b263da/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel#L952 depends on @pybind11, so we need to use the internal_configure_extension function (or equivalent) to get it.

junyer commented 3 months ago

I haven't been able to identify the version of pybind11_bazel on which that build depends, but I will state with certainty that it predates v2.11.1.bzl.2 because that would have forced the removal of references to @local_config_python and @pybind11.

roceb commented 3 months ago

For some context. I had originally made this example while using a very old version pre module file. I saw the message on the issue and decided to move over to the latest. So its good to see that it Just Works™

roceb commented 3 months ago

I removed it. I think we are good to merge.

On Fri, Jun 21, 2024, 1:11 PM Paul Wankadia @.***> wrote:

@.**** commented on this pull request.

In examples/basic/BUILD.bazel https://github.com/pybind/pybind11_bazel/pull/86#discussion_r1649233190:

+py_library(

  • name = "add_py_lib",
  • data = [
  • "example.so",
  • ],
  • imports = ["."],
  • visibility = ["//visibility:public"], +)

I wouldn't bother setting it here, TBH, but if you do want to set it, then please set it on the py_library only.

— Reply to this email directly, view it on GitHub https://github.com/pybind/pybind11_bazel/pull/86#discussion_r1649233190, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFC4R2WBWQT4CRQCYAJOWO3ZIRNDFAVCNFSM6AAAAABJOPRJ6CVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCMZTGEYDAMJRGM . You are receiving this because you authored the thread.Message ID: @.***>