1From c01e056ee845ae973ec36cc50125492ef8c02c12 Mon Sep 17 00:00:00 2001
2From: Conroy Cheers <conroy@corncheese.org>
3Date: Thu, 12 Jun 2025 17:45:27 +1000
4Subject: [PATCH] [Fix] find nanobind from Python module
5
6---
7 cpp/nanobind/CMakeLists.txt | 4 ++++
8 pyproject.toml | 2 +-
9 2 files changed, 5 insertions(+), 1 deletion(-)
10
11diff --git a/cpp/nanobind/CMakeLists.txt b/cpp/nanobind/CMakeLists.txt
12index 8ea5622..02500ac 100644
13--- a/cpp/nanobind/CMakeLists.txt
14+++ b/cpp/nanobind/CMakeLists.txt
15@@ -3,6 +3,10 @@ find_package(
16 COMPONENTS Interpreter Development.Module
17 REQUIRED
18 )
19+
20+execute_process(
21+ COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
22+ OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_DIR)
23 find_package(nanobind CONFIG REQUIRED)
24
25 # Compile this source file seperately. Nanobind suggests to optimize bindings code for size, but
26diff --git a/pyproject.toml b/pyproject.toml
27index 11fae7d..d2078b1 100644
28--- a/pyproject.toml
29+++ b/pyproject.toml
30@@ -44,7 +44,7 @@ provider = "scikit_build_core.metadata.regex"
31 input = "python/xgrammar/version.py"
32
33 [build-system]
34-requires = ["scikit-build-core>=0.10.0", "nanobind==2.5.0"]
35+requires = ["scikit-build-core>=0.10.0", "nanobind>=2.5.0"]
36 build-backend = "scikit_build_core.build"
37
38 [tool.scikit-build]
39--
402.49.0
41