euler314 commited on
Commit
bdb714e
·
verified ·
1 Parent(s): 91471db

Update setup.py

Browse files
Files changed (1) hide show
  1. setup.py +32 -2
setup.py CHANGED
@@ -1,14 +1,42 @@
1
  from setuptools import setup, Extension
 
 
 
2
  import pybind11
3
  import numpy as np
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  ext_modules = [
6
  Extension(
7
  'cubic_cpp',
8
  ['cubic_cpp.cpp'],
9
- include_dirs=[pybind11.get_include(), np.get_include()],
 
 
 
10
  language='c++',
11
- extra_compile_args=['-std=c++11', '-O3'],
12
  ),
13
  ]
14
 
@@ -16,8 +44,10 @@ setup(
16
  name="cubic_cpp",
17
  version="0.1",
18
  ext_modules=ext_modules,
 
19
  install_requires=[
20
  'pybind11>=2.6.0',
21
  'numpy>=1.19.0',
22
  ],
 
23
  )
 
1
  from setuptools import setup, Extension
2
+ from setuptools.command.build_ext import build_ext
3
+ import sys
4
+ import os
5
  import pybind11
6
  import numpy as np
7
 
8
+ class BuildExt(build_ext):
9
+ """Custom build extension for pybind11."""
10
+ def build_extensions(self):
11
+ # Print debug info
12
+ print(f"Python {sys.version}")
13
+ print(f"Building extension with {self.compiler.compiler_type}")
14
+
15
+ # Apply relevant compiler flags based on compiler
16
+ if self.compiler.compiler_type == 'unix':
17
+ opts = ['-std=c++11', '-O3', '-fvisibility=hidden']
18
+ if sys.platform == 'darwin':
19
+ opts.append('-stdlib=libc++')
20
+ elif self.compiler.compiler_type == 'msvc':
21
+ opts = ['/EHsc', '/O2']
22
+ else:
23
+ opts = []
24
+
25
+ # Apply options to all extensions
26
+ for ext in self.extensions:
27
+ ext.extra_compile_args = opts
28
+
29
+ build_ext.build_extensions(self)
30
+
31
  ext_modules = [
32
  Extension(
33
  'cubic_cpp',
34
  ['cubic_cpp.cpp'],
35
+ include_dirs=[
36
+ pybind11.get_include(),
37
+ np.get_include(),
38
+ ],
39
  language='c++',
 
40
  ),
41
  ]
42
 
 
44
  name="cubic_cpp",
45
  version="0.1",
46
  ext_modules=ext_modules,
47
+ cmdclass={'build_ext': BuildExt},
48
  install_requires=[
49
  'pybind11>=2.6.0',
50
  'numpy>=1.19.0',
51
  ],
52
+ zip_safe=False, # Required for pybind11
53
  )