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

Python: If headeronly is set, links is not needed #5403

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/p/pybind11/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ package("pybind11")
add_versions("v2.12.0", "411f77380c43798506b39ec594fc7f2b532a13c4db674fcf2b1ca344efaefb68")
add_versions("v2.13.1", "a3c9ea1225cb731b257f2759a0c12164db8409c207ea5cf851d4b95679dda072")

add_deps("cmake", "python 3.x")
-- https://peps.python.org/pep-0513/#libpythonx-y-so-1
myuanz marked this conversation as resolved.
Show resolved Hide resolved
myuanz marked this conversation as resolved.
Show resolved Hide resolved
add_configs("python_headeronly", {description = "Enable headeronly for Python", default = false, type = "boolean"})

add_deps("cmake")
myuanz marked this conversation as resolved.
Show resolved Hide resolved

myuanz marked this conversation as resolved.
Show resolved Hide resolved
on_load(function (package)
local python_headeronly = package:config("python_headeronly")
if is_host("windows") then
wprint("Python headeronly is not supported on Windows")
python_headeronly = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 windows 不支持,应该 add_configs 时候,直接设置为 readonly = true, default = false 锁定住,原本就会自动给 warning 。。不用额外检测

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我不太清楚怎么做到,add_configs能对不同的操作系统限制吗?Linux 下,如果想要嵌入,还是要 link Python 的

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考下。

    if is_plat("windows", "mingw") then
        -- Do not build static library for window.
        add_configs("shared", {description = "Build shared library.", default = true, type = "boolean", readonly = true})
        add_configs("vs_runtime", {description = "Set vs compiler runtime.", default = "MD", readonly = true})
    end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我改好了,请看以下这样可否

end

package:add("deps", "python 3.x", {configs = {headeronly = python_headeronly}})
end)

on_install("windows|native", "macosx", "linux", function (package)
import("package.tools.cmake").install(package, {"-DPYBIND11_TEST=OFF"})
end)
Expand Down
23 changes: 14 additions & 9 deletions packages/p/python/fetch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,20 @@ function _find_library(package, opt)
includepath = find_path("Python.h", { path.directory(exepath), out }, { suffixes = { "include/python" .. pyver } })
end

if libpath and includepath then
local result = {
version = version,
includedirs = includepath
}
if not package:config("headeronly") then
result.links = libpath.link
result.linkdirs = libpath.linkdir
end
if not includepath then
return
end
local result = {
version = version,
includedirs = includepath
}

if package:config("headeronly") then
return result
end
if libpath then
result.links = libpath.link
result.linkdirs = libpath.linkdir
return result
end
end
Expand Down
Loading