Skip to content

Commit

Permalink
Merge pull request #3310 from rcurtin/python_compilation_flags
Browse files Browse the repository at this point in the history
Optimize and strip Cython compiled libraries
  • Loading branch information
rcurtin committed Nov 14, 2022
2 parents c86c1d3 + 1b6e585 commit 3fdb791
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/mlpack/bindings/python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,29 @@ else:
extra_cxx_flags = re.sub(' +', ' ', cxx_flags)
cxx_flags += ' '
cxx_flags += extra_cxx_flags
extra_args = ['-DBINDING_TYPE=BINDING_TYPE_PYX', '-std=c++14']

extra_args = []
if platform.system() == 'Windows':
# Argument specification is different on MSVC, and also use C++17.
extra_args.extend(['/DBINDING_TYPE=BINDING_TYPE_PYX', '/std:c++17', '/MD',
'/O2', '/Ob2', '/DNDEBUG'])
elif platform.system() == 'Darwin':
extra_args.append('-DBINDING_TYPE=BINDING_TYPE_PYX')
extra_args.append('-std=c++17')
# On OS X and Linux, we try to reduce the size of the generated libraries
# by removing debugging symbols and stripping.
extra_args.append('-g0')
else:
extra_args.append('-DBINDING_TYPE=BINDING_TYPE_PYX')
extra_args.append('-std=c++17')
extra_args.append('-g0')
extra_link_args.append('-Wl,--strip-all')

if '${OpenMP_CXX_FLAGS}' != '':
extra_args.append('${OpenMP_CXX_FLAGS}')
if cxx_flags:
extra_args.extend(cxx_flags.split(' '))

# Extra options for MSVC compiler.
if platform.system() == 'Windows':
extra_args.extend(['/MD', '/O2', '/Ob2', '/DNDEBUG'])

# This is used for parallel builds; CMake will set PYX_TO_BUILD accordingly.
if module is not None:
modules=[\
Expand Down

0 comments on commit 3fdb791

Please sign in to comment.