@@ -141,19 +141,32 @@ def build_extension(self, ext):
141141 target_dir = os .path .join (
142142 os .path .dirname (ext .path ), "target/" , suffix )
143143
144+ dylib_paths = []
145+
144146 if executable :
145- # search executable
146- dylib_path = None
147- for name in os .listdir (target_dir ):
148- path = os .path .join (target_dir , name )
149- if name .startswith ("." ) or not os .path .isfile (path ):
150- continue
151-
152- if os .access (path , os .X_OK ):
153- dylib_path = path
154- break
155-
156- if dylib_path is None :
147+ for name , dest in ext .target .items ():
148+ if name :
149+ path = os .path .join (target_dir , name )
150+ if os .access (path , os .X_OK ):
151+ dylib_paths .append ((dest , path ))
152+ continue
153+ else :
154+ raise DistutilsExecError (
155+ 'rust build failed; '
156+ 'unable to find executable "%s" in %s' % (
157+ name , target_dir ))
158+ else :
159+ # search executable
160+ for name in os .listdir (target_dir ):
161+ path = os .path .join (target_dir , name )
162+ if name .startswith ("." ) or not os .path .isfile (path ):
163+ continue
164+
165+ if os .access (path , os .X_OK ):
166+ dylib_paths .append ((ext .name , path ))
167+ break
168+
169+ if not dylib_paths :
157170 raise DistutilsExecError (
158171 "rust build failed; unable to find executable in %s" %
159172 target_dir )
@@ -166,8 +179,9 @@ def build_extension(self, ext):
166179 wildcard_so = "*.so"
167180
168181 try :
169- dylib_path = glob .glob (
170- os .path .join (target_dir , wildcard_so ))[0 ]
182+ dylib_paths .append (
183+ (ext .name , glob .glob (
184+ os .path .join (target_dir , wildcard_so ))[0 ]))
171185 except IndexError :
172186 raise DistutilsExecError (
173187 "rust build failed; unable to find any %s in %s" %
@@ -177,47 +191,49 @@ def build_extension(self, ext):
177191 # then copy it there.
178192 build_ext = self .get_finalized_command ('build_ext' )
179193 build_ext .inplace = self .inplace
180- target_fname = ext .name
181- if target_fname is None :
182- target_fname = os .path .basename (os .path .splitext (
183- os .path .basename (dylib_path )[3 :])[0 ])
184194
185- if executable :
186- ext_path = build_ext .get_ext_fullpath (target_fname )
187- # remove .so extension
188- ext_path , _ = os .path .splitext (ext_path )
189- # remove python3 extension (i.e. cpython-36m)
190- ext_path , _ = os .path .splitext (ext_path )
195+ for target_fname , dylib_path in dylib_paths :
196+ if not target_fname :
197+ target_fname = os .path .basename (os .path .splitext (
198+ os .path .basename (dylib_path )[3 :])[0 ])
191199
192- ext .install_script (ext_path )
193- else :
194- ext_path = build_ext .get_ext_fullpath (target_fname )
200+ if executable :
201+ ext_path = build_ext .get_ext_fullpath (target_fname )
202+ # remove .so extension
203+ ext_path , _ = os .path .splitext (ext_path )
204+ # remove python3 extension (i.e. cpython-36m)
205+ ext_path , _ = os .path .splitext (ext_path )
195206
196- try :
197- os .makedirs (os .path .dirname (ext_path ))
198- except OSError :
199- pass
200- shutil .copyfile (dylib_path , ext_path )
201-
202- if not debug_build :
203- args = []
204- if ext .strip == Strip .All :
205- args .append ('-x' )
206- elif ext .strip == Strip .Debug :
207- args .append ('-S' )
208-
209- if args :
210- args .insert (0 , 'strip' )
211- args .append (ext_path )
212- try :
213- output = subprocess .check_output (args , env = env )
214- except subprocess .CalledProcessError as e :
215- pass
207+ ext .install_script (ext_path )
208+ else :
209+ ext_path = build_ext .get_ext_fullpath (target_fname )
216210
217- if executable :
218- mode = os .stat (ext_path ).st_mode
219- mode |= (mode & 0o444 ) >> 2 # copy R bits to X
220- os .chmod (ext_path , mode )
211+ try :
212+ os .makedirs (os .path .dirname (ext_path ))
213+ except OSError :
214+ pass
215+
216+ shutil .copyfile (dylib_path , ext_path )
217+
218+ if not debug_build :
219+ args = []
220+ if ext .strip == Strip .All :
221+ args .append ('-x' )
222+ elif ext .strip == Strip .Debug :
223+ args .append ('-S' )
224+
225+ if args :
226+ args .insert (0 , 'strip' )
227+ args .append (ext_path )
228+ try :
229+ output = subprocess .check_output (args , env = env )
230+ except subprocess .CalledProcessError as e :
231+ pass
232+
233+ if executable :
234+ mode = os .stat (ext_path ).st_mode
235+ mode |= (mode & 0o444 ) >> 2 # copy R bits to X
236+ os .chmod (ext_path , mode )
221237
222238 def run (self ):
223239 if not self .extensions :
0 commit comments