Skip to content

Commit

Permalink
Change nanobind linkage to response file approach
Browse files Browse the repository at this point in the history
This change needs bazelbuild/bazel#18952 to be
merged first. Fixes macOS linkage of GBM's nanobind bindings on macOS by
supplying a linker response file instead of `-undefined dynamic_lookup`.

The latter has since been deprecated on macOS.
  • Loading branch information
nicholasjng committed Jul 20, 2023
1 parent 27d64a2 commit 2fe54cf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
17 changes: 9 additions & 8 deletions bazel/benchmark_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ def benchmark_deps():
if "bazel_skylib" not in native.existing_rules():
http_archive(
name = "bazel_skylib",
sha256 = "f7be3474d42aae265405a592bb7da8e171919d74c16f082a5457840f06054728",
sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa ",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.2.1/bazel-skylib-1.2.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
],
)

if "rules_foreign_cc" not in native.existing_rules():
http_archive(
name = "rules_foreign_cc",
sha256 = "bcd0c5f46a49b85b384906daae41d277b3dc0ff27c7c752cc51e43048a58ec83",
strip_prefix = "rules_foreign_cc-0.7.1",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.7.1.tar.gz",
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
strip_prefix = "rules_foreign_cc-0.9.0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.9.0.tar.gz",
)

if "rules_python" not in native.existing_rules():
http_archive(
name = "rules_python",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
sha256 = "0a8003b044294d7840ac7d9d73eef05d6ceb682d7516781a4ec62eeb34702578",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.24.0/rules_python-0.24.0.tar.gz",
strip_prefix = "rules_python-0.24.0",
)

if "com_google_absl" not in native.existing_rules():
Expand Down
18 changes: 17 additions & 1 deletion bindings/python/nanobind.BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
licenses(["notice"])

package(default_visibility = ["//visibility:public"])

filegroup(
name = "symboltable",
srcs = ["cmake/darwin-ld-cpython.sym"],
)

cc_library(
name = "nanobind",
srcs = glob([
Expand All @@ -12,6 +21,13 @@ cc_library(
"ext/robin_map/include/tsl/*.h",
],
),
linkopts = select({
"@platforms//os:macos": ["-Wl,@$(location :cmake/darwin-ld-cpython.sym)"],
"//conditions:default": [],
}),
additional_linker_inputs = select({
"@platforms//os:macos": [":cmake/darwin-ld-cpython.sym"],
"//conditions:default": [],
}),
deps = ["@python_headers"],
visibility = ["//visibility:public"],
)
4 changes: 4 additions & 0 deletions bindings/python/python_headers.BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
licenses(["notice"])

package(default_visibility = ["//visibility:public"])

cc_library(
name = "python_headers",
hdrs = glob(["**/*.h"]),
Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class BuildBazelExtension(build_ext.build_ext):
def run(self):
for ext in self.extensions:
self.bazel_build(ext)
build_ext.build_ext.run(self)
super().run()
# explicitly call `bazel shutdown` for graceful exit
self.spawn(["bazel", "shutdown"])

def bazel_build(self, ext: BazelExtension):
"""Runs the bazel build to create the package."""
Expand Down Expand Up @@ -98,9 +100,6 @@ def bazel_build(self, ext: BazelExtension):
ext_dest_path = Path(self.get_ext_fullpath(ext.name))
shutil.copyfile(ext_bazel_bin_path, ext_dest_path)

# explicitly call `bazel shutdown` for graceful exit
self.spawn(["bazel", "shutdown"])


setuptools.setup(
cmdclass=dict(build_ext=BuildBazelExtension),
Expand Down

0 comments on commit 2fe54cf

Please sign in to comment.