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

provide cmake python3_add_library #1896

Closed
xq114 opened this issue Dec 8, 2021 · 11 comments
Closed

provide cmake python3_add_library #1896

xq114 opened this issue Dec 8, 2021 · 11 comments

Comments

@xq114
Copy link
Contributor

xq114 commented Dec 8, 2021

你在什么场景下需要该功能?

https://cmake.org/cmake/help/latest/module/FindPython3.html#commands

提供cmake的python3_add_library功能

  • 使用python特征的后缀名:不带soabi的so/pyd,带soabi的从distutils或者sysconfig获取
    image

  • 类型为动态链接库

描述可能的解决方案

用一个rule python_library来模拟:

add_rules("python_library", {soabi=true})

之前的swig.python没考虑soabi的事情,这里也可以加上

@xq114
Copy link
Contributor Author

xq114 commented Dec 8, 2021

@waruqi waruqi added this to the v2.6.3 milestone Dec 18, 2021
@waruqi
Copy link
Member

waruqi commented Dec 23, 2021

这个跟 swig 的py模块命名一样? _xxx.so? win 上 _xxx.pyd

能给个完整 linux/macos/win 下模块命名规范么

@waruqi
Copy link
Member

waruqi commented Dec 23, 2021

➜ ~ python -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
None
➜ ~ python3 -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
.cpython-39-darwin.so

为啥 python2 和 python3 结果还不一样?

@waruqi
Copy link
Member

waruqi commented Dec 23, 2021

是因为这个 soabi 只有 python3 支持?

@waruqi
Copy link
Member

waruqi commented Dec 23, 2021

我加上了

add_rules("mode.release", "mode.debug")
add_requires("pybind11")

target("example")
    add_rules("python.library")
    add_files("src/*.cpp")
    add_packages("pybind11")
    set_languages("c++11")

With soabi

add_rules("mode.release", "mode.debug")
add_requires("pybind11")

target("example")
    add_rules("python.library", {soabi = true})
    add_files("src/*.cpp")
    add_packages("pybind11")
    set_languages("c++11")

Swig with soabi

add_rules("mode.release", "mode.debug")
add_requires("python 3.x")

target("example")
    add_rules("swig.c", {moduletype = "python", soabi = true})
    add_files("src/example.i", {scriptdir = "share"})
    add_files("src/example.c")
    add_packages("python")

@xq114
Copy link
Contributor Author

xq114 commented Dec 23, 2021

是因为这个 soabi 只有 python3 支持?

cmake对soabi的探测是有几种不同方法的,原话是

Python3_SOABI
New in version 3.17.

Extension suffix for modules.

Information returned by distutils.sysconfig.get_config_var('SOABI') or computed from distutils.sysconfig.get_config_var('EXT_SUFFIX') or python3-config --extension-suffix. If package distutils.sysconfig is not available, sysconfig.get_config_var('SOABI') or sysconfig.get_config_var('EXT_SUFFIX') are used.

可能以前soabi是存在distutils里面?我这没有python2环境,没办法确认,windows上python3我实测只有sysconfig.get_config_var('EXT_SUFFIX')有效,其他都不行

@waruqi
Copy link
Member

waruqi commented Dec 23, 2021

python2 下 distutils 没 sysconfig 这个对象

@xq114
Copy link
Contributor Author

xq114 commented Dec 23, 2021

sysconfig.get_config_var('SOABI')也不行的话应该就是python2不支持了

@waruqi
Copy link
Member

waruqi commented Dec 23, 2021

sysconfig.get_config_var('SOABI')

返回也是 None

@waruqi
Copy link
Member

waruqi commented Dec 23, 2021

我看 cmake 也只有 FindPython3 提到了 soabi ,,FindPython 文档里面也没提到

@waruqi
Copy link
Member

waruqi commented Dec 23, 2021

估计就 py3 支持,那目前这样差不多了,你试试呢 dev 上,没问题的话,我就 close 了

@waruqi waruqi closed this as completed Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants