Skip to content

Commit

Permalink
Adding platform= option to build_ext command
Browse files Browse the repository at this point in the history
This new option should allow users to build the module in a
cross-compilation scenario, where the host's platform is not the
target's.

This is a different way of implementing the idea shown in #10.

Signed-off-by: Rodrigo Tobar <[email protected]>
  • Loading branch information
rtobar committed May 20, 2019
1 parent e0d8456 commit 42b8a15
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
language='c',
sources=['_crc32c.c', 'crc32c_sw.c'],
include_dirs=['.'])
is_intel = platform.machine() in ['x86_64', 'AMD64']

def get_extra_compile_args():
def get_extra_compile_args(is_intel):
# msvc is treated specially; otherwise we assume it's a unix compiler
comp = distutils.ccompiler.get_default_compiler()
if comp == 'msvc':
Expand All @@ -47,9 +46,18 @@ def get_extra_compile_args():

class _build_ext(build_ext):
"""Custom build_ext command that includes extra compilation arguments"""

user_options = build_ext.user_options + [
('platform=', None, 'The target platform name')]

def initialize_options(self):
build_ext.initialize_options(self)
self.platform = platform.machine()

def run(self):
assert(len(self.distribution.ext_modules) == 1)
self.distribution.ext_modules[0].extra_compile_args = get_extra_compile_args()
is_intel = self.platform in ['x86_64', 'AMD64']
self.distribution.ext_modules[0].extra_compile_args = get_extra_compile_args(is_intel)
if is_intel:
self.distribution.ext_modules[0].define_macros += [('IS_INTEL', None)]
self.distribution.ext_modules[0].sources += ['crc32c_adler.c', 'checksse42.c']
Expand Down

0 comments on commit 42b8a15

Please sign in to comment.