from setuptools import setup, Extension
import pybind11

# 定义扩展模块
ext_modules = [
    Extension(
        'my_extension',
        sources=['my_extension.cpp'],
        include_dirs=[
            pybind11.get_include(),  # pybind11 头文件路径
        ],
        language='c++',
        # 编译参数
        extra_compile_args=[
            '-std=c++17',
            '-O3',
            '-fvisibility=hidden'
        ],
        # 启用有限 API，支持 Python 3.10+
        py_limited_api=True,
        define_macros=[
            ('Py_LIMITED_API', '0x030a0000'),  # Python 3.10
            ('PYBIND11_LIMITED_API', '1'),     # 启用 pybind11 的有限 API 支持
        ]
    ),
]

setup(
    name='my_simple_extension',
    version='0.1.0',
    description='A simple hello world C++ extension with limited API',
    ext_modules=ext_modules,
    install_requires=['pybind11>=2.6'],
    setup_requires=['pybind11>=2.6'],
    zip_safe=False,
    python_requires='>=3.10',
    # 指定生成 abi3 兼容的 wheel 包
    options={
        "bdist_wheel": {
            "py_limited_api": "cp310"  # 基于 CPython 3.10 ABI
        }
    },
)