Skip to content

Commit 2f23a9a

Browse files
committed
fix python binding build with static python
1 parent 19a92e1 commit 2f23a9a

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools"]
2+
requires = ["setuptools>=64"]
33
build-backend = "setuptools.build_meta"
44

55
[project]

xmake.lua

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
add_rules("mode.debug", "mode.release")
22
add_requires("boost", {configs = {stacktrace = true}})
3-
add_requires("pybind11")
43

54
-- Define color codes
65
local GREEN = '\27[0;32m'
@@ -570,7 +569,26 @@ target("_infinicore")
570569

571570
set_default(false)
572571
add_rules("python.library", {soabi = true})
573-
add_packages("pybind11")
572+
-- Use the active Python environment; xmake's pybind11 package self-test
573+
-- links libpython and breaks when Python is built as a static library.
574+
on_load(function (target)
575+
local script = table.concat({
576+
"import sysconfig",
577+
"import pybind11",
578+
"print(sysconfig.get_path('include'))",
579+
"print(pybind11.get_include())",
580+
}, "; ")
581+
582+
local includedirs = os.iorunv("python3", {"-c", script})
583+
assert(includedirs ~= "", "pybind11 is required in the active Python environment to build the Python bindings")
584+
585+
for _, includedir in ipairs(includedirs:split("\n")) do
586+
includedir = includedir:trim()
587+
if includedir ~= "" and includedir ~= "None" then
588+
target:add("includedirs", includedir)
589+
end
590+
end
591+
end)
574592
set_languages("cxx17")
575593

576594
add_deps("infinicore_cpp_api")

0 commit comments

Comments
 (0)