From 234f47a0181e8fa4c24c317f8601172bada99429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= Date: Mon, 1 Sep 2025 20:08:50 -0400 Subject: [PATCH] python/setup.py: use appropriate flags for windows build --- python/setup.py.in | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/python/setup.py.in b/python/setup.py.in index e61ff800..1e9dc733 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -14,11 +14,37 @@ # along with this program. If not, see . from setuptools import setup, Extension +from setuptools.command.build_ext import build_ext as _build_ext import os with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'README.md'), 'r', encoding='utf-8') as f: long_description = f.read() +extra_compile_args = { + 'msvc': ['/std:c++17', '/EHsc', '/utf-8'], + 'unix': ['-std=c++17'], +} + +extra_link_args = { + 'msvc': ['wsock32.lib', 'ws2_32.lib'], + 'unix': ['-std=c++17'] +} +extra_libraries = { + 'msvc': ['opendht_import', 'gnutls'], + 'unix': ['opendht'] +} + +class build_ext(_build_ext): + def build_extensions(self): + compile_args = extra_compile_args.get(self.compiler.compiler_type, []) + link_args = extra_link_args.get(self.compiler.compiler_type, []) + libraries = extra_libraries.get(self.compiler.compiler_type, ['opendht']) + for ext in self.extensions: + ext.extra_compile_args.extend(compile_args) + ext.extra_link_args.extend(link_args) + ext.libraries = libraries + super().build_extensions() + setup(name="opendht", version="@PACKAGE_VERSION@", description="OpenDHT: A lightweight Distributed Hash Table", @@ -36,12 +62,12 @@ setup(name="opendht", 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.9', ], + cmdclass=dict(build_ext=build_ext), ext_modules = [Extension( "opendht", ["@CURRENT_SOURCE_DIR@/opendht.pyx"], language="c++", - extra_compile_args=["-std=c++17", "-DMSGPACK_NO_BOOST", "-DMSGPACK_DISABLE_LEGACY_NIL", "-DMSGPACK_DISABLE_LEGACY_CONVERT", "-DOPENDHT_INDEXATION", "-Dopendht_EXPORTS"], - extra_link_args=["-std=c++17"], + extra_compile_args=["-DMSGPACK_NO_BOOST", "-DMSGPACK_DISABLE_LEGACY_NIL", "-DMSGPACK_DISABLE_LEGACY_CONVERT", "-DOPENDHT_INDEXATION", "-Dopendht_EXPORTS"], libraries=["opendht", "gnutls"], include_dirs = ['@PROJECT_SOURCE_DIR@/include'@OPENDHT_PYTHON_INCLUDE_DIRS@], library_dirs = ['@CURRENT_BINARY_DIR@', '@PROJECT_BINARY_DIR@'@OPENDHT_PYTHON_LIBRARY_DIRS@]