@@ -73,15 +73,19 @@ def cpp_flag(compiler):
7373
7474class BuildExt (build_ext ):
7575 """A custom build extension for adding compiler-specific options."""
76+ native_flag = '-march=native'
7677 c_opts = {
7778 'msvc' : ['/EHsc' , '/openmp' , '/O2' ],
78- 'unix' : ['-O3' , '-march=native' ], # , '-w'
79+ 'unix' : ['-O3' , native_flag ], # , '-w'
7980 }
8081 link_opts = {
8182 'unix' : [],
8283 'msvc' : [],
8384 }
8485
86+ if os .environ .get ("HNSWLIB_NO_NATIVE" ):
87+ c_opts ['unix' ].remove (native_flag )
88+
8589 if sys .platform == 'darwin' :
8690 c_opts ['unix' ] += ['-stdlib=libc++' , '-mmacosx-version-min=10.7' ]
8791 link_opts ['unix' ] += ['-stdlib=libc++' , '-mmacosx-version-min=10.7' ]
@@ -97,23 +101,23 @@ def build_extensions(self):
97101 opts .append (cpp_flag (self .compiler ))
98102 if has_flag (self .compiler , '-fvisibility=hidden' ):
99103 opts .append ('-fvisibility=hidden' )
100- # check that native flag is available
101- native_flag = '-march= native'
102- print ('checking avalability of flag:' , native_flag )
103- if not has_flag (self .compiler , native_flag ):
104- print ('removing unsupported compiler flag:' , native_flag )
105- opts .remove (native_flag )
106- # for macos add apple-m1 flag if it's available
107- if sys .platform == 'darwin' :
108- m1_flag = '-mcpu=apple-m1'
109- print ('checking avalability of flag:' , m1_flag )
110- if has_flag (self .compiler , m1_flag ):
111- print ('adding flag:' , m1_flag )
112- opts .append (m1_flag )
113- else :
114- print (f'flag: { m1_flag } is not available' )
115- else :
116- print (f'flag: { native_flag } is available' )
104+ if not os . environ . get ( "HNSWLIB_NO_NATIVE" ):
105+ # check that native flag is available
106+ print ('checking avalability of flag:' , native_flag )
107+ if not has_flag (self .compiler , native_flag ):
108+ print ('removing unsupported compiler flag:' , native_flag )
109+ opts .remove (native_flag )
110+ # for macos add apple-m1 flag if it's available
111+ if sys .platform == 'darwin' :
112+ m1_flag = '-mcpu=apple-m1'
113+ print ('checking avalability of flag:' , m1_flag )
114+ if has_flag (self .compiler , m1_flag ):
115+ print ('adding flag:' , m1_flag )
116+ opts .append (m1_flag )
117+ else :
118+ print (f'flag: { m1_flag } is not available' )
119+ else :
120+ print (f'flag: { native_flag } is available' )
117121 elif ct == 'msvc' :
118122 opts .append ('/DVERSION_INFO=\\ "%s\\ "' % self .distribution .get_version ())
119123
0 commit comments