Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back HNSWLIB_NO_NATIVE #493

Merged
merged 3 commits into from
Aug 19, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ def cpp_flag(compiler):

class BuildExt(build_ext):
"""A custom build extension for adding compiler-specific options."""
native_flag = '-march=native'
dyashuni marked this conversation as resolved.
Show resolved Hide resolved
c_opts = {
'msvc': ['/EHsc', '/openmp', '/O2'],
'unix': ['-O3', '-march=native'], # , '-w'
'unix': ['-O3', native_flag], # , '-w'
}
link_opts = {
'unix': [],
'msvc': [],
}

if os.environ.get("HNSWLIB_NO_NATIVE"):
c_opts['unix'].remove(native_flag)

if sys.platform == 'darwin':
c_opts['unix'] += ['-stdlib=libc++', '-mmacosx-version-min=10.7']
link_opts['unix'] += ['-stdlib=libc++', '-mmacosx-version-min=10.7']
Expand All @@ -97,23 +101,23 @@ def build_extensions(self):
opts.append(cpp_flag(self.compiler))
if has_flag(self.compiler, '-fvisibility=hidden'):
opts.append('-fvisibility=hidden')
# check that native flag is available
native_flag = '-march=native'
print('checking avalability of flag:', native_flag)
if not has_flag(self.compiler, native_flag):
print('removing unsupported compiler flag:', native_flag)
opts.remove(native_flag)
# for macos add apple-m1 flag if it's available
if sys.platform == 'darwin':
m1_flag = '-mcpu=apple-m1'
print('checking avalability of flag:', m1_flag)
if has_flag(self.compiler, m1_flag):
print('adding flag:', m1_flag)
opts.append(m1_flag)
else:
print(f'flag: {m1_flag} is not available')
else:
print(f'flag: {native_flag} is available')
if not os.environ.get("HNSWLIB_NO_NATIVE"):
# check that native flag is available
print('checking avalability of flag:', self.native_flag)
dyashuni marked this conversation as resolved.
Show resolved Hide resolved
if not has_flag(self.compiler, self.native_flag):
print('removing unsupported compiler flag:', self.native_flag)
opts.remove(self.native_flag)
# for macos add apple-m1 flag if it's available
if sys.platform == 'darwin':
m1_flag = '-mcpu=apple-m1'
print('checking avalability of flag:', m1_flag)
if has_flag(self.compiler, m1_flag):
print('adding flag:', m1_flag)
opts.append(m1_flag)
else:
print(f'flag: {m1_flag} is not available')
else:
print(f'flag: {self.native_flag} is available')
elif ct == 'msvc':
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())

Expand Down