Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alias forwarding internal @nanobind to users #49

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

nicholasjng
Copy link
Owner

@nicholasjng nicholasjng commented Dec 18, 2024

This enables users to consume the internal nanobind library for their own purposes, exposing it as @nanobind_bazel//:nanobind.

Related to #48.

@nicholasjng
Copy link
Owner Author

cc @hawkinsp

I was able to use this to build a target off the nanobind example's bazel branch with this patch:

diff --git a/MODULE.bazel b/MODULE.bazel
index e1f5903..a15a36b 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -1,6 +1,10 @@
 module(name = "nanobind_example", version = "0.1.0")
 
-bazel_dep(name = "nanobind_bazel", version = "2.2.0")
+bazel_dep(name = "nanobind_bazel", version = "")
+local_path_override(
+    module_name = "nanobind_bazel",
+    path = "../nanobind-bazel",
+)
 bazel_dep(name = "rules_python", version = "1.0.0")
 
 python = use_extension("@rules_python//python/extensions:python.bzl", "python")
diff --git a/setup.py b/setup.py
index 6584bab..82a9d25 100644
--- a/setup.py
+++ b/setup.py
@@ -58,7 +58,7 @@ class BuildBazelExtension(build_ext.build_ext):
 
         bazel_argv = [
             "bazel",
-            "run",
+            "build",
             ext.bazel_target,
             f"--symlink_prefix={temp_path / 'bazel-'}",
             f"--compilation_mode={'dbg' if self.debug else 'opt'}",
@@ -115,7 +115,7 @@ setuptools.setup(
     ext_modules=[
         BazelExtension(
             name="nanobind_example.nanobind_example_ext",
-            bazel_target="//src:nanobind_example_ext_stubgen",
+            bazel_target="//src:foo",
             free_threaded=free_threaded,
             py_limited_api=py_limited_api,
         )
diff --git a/src/BUILD b/src/BUILD
index 5562dca..70b6a60 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -20,6 +20,12 @@ nanobind_stubgen(
     name = "nanobind_example_ext_stubgen",
     module = ":nanobind_example_ext",
     marker_file = "src/py.typed",
-    output_directory = "src",
-    recursive = True,
+#    output_directory = "src",
+#    recursive = True,
 )
+
+cc_library(
+    name = "foo",
+    srcs = ["nanobind_example_ext.cpp"],
+    deps = ["@nanobind_bazel//:nanobind"],
+)

Assuming that you have a local nanobind_bazel checked out on the same directory level as the nanobind_example.

This enables users to consume the internal nanobind library for their own
purposes.
@nicholasjng
Copy link
Owner Author

I'm going to merge this now, so that you can already use the alias e.g. by declaring nanobind_bazel as a git_override.

The label flag feature is still pending, in case you would like to use a completely custom @nanobind repo at some point in the future (you could also just patch the nanobind.BUILD, though).

@nicholasjng nicholasjng merged commit 7d1bb7c into master Dec 18, 2024
19 checks passed
@nicholasjng nicholasjng deleted the add-nanobind-alias branch December 18, 2024 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant