@@ -34,8 +34,9 @@ def __init__(self, triple=None, cross_lib=None, linker=None, link_args=None):
34
34
self .linker = linker
35
35
self .link_args = link_args
36
36
37
+
37
38
class build_rust (RustCommand ):
38
- """ Command for building Rust crates via cargo. """
39
+ """Command for building Rust crates via cargo."""
39
40
40
41
description = "build Rust extensions (compile/link to build directory)"
41
42
@@ -72,7 +73,7 @@ def finalize_options(self):
72
73
super ().finalize_options ()
73
74
74
75
if self .plat_name is None :
75
- self .plat_name = self .get_finalized_command (' build' ).plat_name
76
+ self .plat_name = self .get_finalized_command (" build" ).plat_name
76
77
77
78
# Inherit settings from the `build_ext` command
78
79
self .set_undefined_options (
@@ -105,17 +106,17 @@ def get_nix_target_info(self):
105
106
# necessarily the same as the system we are running on. *NIX systems
106
107
# have more detailed information available in sysconfig. We need that
107
108
# because plat_name doesn't give us information on e.g., glibc vs musl.
108
- host_type = sysconfig .get_config_var (' HOST_GNU_TYPE' )
109
- build_type = sysconfig .get_config_var (' BUILD_GNU_TYPE' )
109
+ host_type = sysconfig .get_config_var (" HOST_GNU_TYPE" )
110
+ build_type = sysconfig .get_config_var (" BUILD_GNU_TYPE" )
110
111
111
112
if not host_type or host_type == build_type :
112
113
# not *NIX, or not cross compiling
113
114
return _TargetInfo ()
114
115
115
- stdlib = sysconfig .get_path (' stdlib' )
116
+ stdlib = sysconfig .get_path (" stdlib" )
116
117
cross_lib = os .path .dirname (stdlib )
117
118
118
- bldshared = sysconfig .get_config_var (' BLDSHARED' )
119
+ bldshared = sysconfig .get_config_var (" BLDSHARED" )
119
120
if not bldshared :
120
121
linker = None
121
122
linker_args = None
@@ -131,16 +132,17 @@ def get_nix_target_info(self):
131
132
132
133
# the vendor field can be ignored, so x86_64-pc-linux-gnu is compatible
133
134
# with x86_64-unknown-linux-gnu
134
- components = host_type .split ('-' )
135
+ components = host_type .split ("-" )
135
136
if len (components ) == 4 :
136
- components [1 ] = ' unknown'
137
- host_type2 = '-' .join (components )
137
+ components [1 ] = " unknown"
138
+ host_type2 = "-" .join (components )
138
139
if host_type2 in targets :
139
140
return _TargetInfo (host_type2 , cross_lib , linker , linker_args )
140
141
141
142
raise DistutilsPlatformError (
142
- "Don't know the correct rust target for system type %s. Please "
143
- "set the CARGO_BUILD_TARGET environment variable." % host_type )
143
+ "Don't know the correct rust target for system type %s. Please "
144
+ "set the CARGO_BUILD_TARGET environment variable." % host_type
145
+ )
144
146
145
147
def run_for_extension (self , ext : RustExtension ):
146
148
arch_flags = os .getenv ("ARCHFLAGS" )
@@ -151,9 +153,13 @@ def run_for_extension(self, ext: RustExtension):
151
153
arm64_dylib_paths = self .build_extension (ext , "aarch64-apple-darwin" )
152
154
x86_64_dylib_paths = self .build_extension (ext , "x86_64-apple-darwin" )
153
155
dylib_paths = []
154
- for (target_fname , arm64_dylib ), (_ , x86_64_dylib ) in zip (arm64_dylib_paths , x86_64_dylib_paths ):
156
+ for (target_fname , arm64_dylib ), (_ , x86_64_dylib ) in zip (
157
+ arm64_dylib_paths , x86_64_dylib_paths
158
+ ):
155
159
fat_dylib_path = arm64_dylib .replace ("aarch64-apple-darwin/" , "" )
156
- self .create_universal2_binary (fat_dylib_path , [arm64_dylib , x86_64_dylib ])
160
+ self .create_universal2_binary (
161
+ fat_dylib_path , [arm64_dylib , x86_64_dylib ]
162
+ )
157
163
dylib_paths .append ((target_fname , fat_dylib_path ))
158
164
else :
159
165
dylib_paths = self .build_extension (ext )
@@ -179,7 +185,9 @@ def build_extension(self, ext: RustExtension, target_triple=None):
179
185
# which causes pythonXX-sys to fall back to detecting the
180
186
# interpreter from the path.
181
187
"PATH" : os .path .join (bindir , os .environ .get ("PATH" , "" )),
182
- "PYTHON_SYS_EXECUTABLE" : os .environ .get ("PYTHON_SYS_EXECUTABLE" , sys .executable ),
188
+ "PYTHON_SYS_EXECUTABLE" : os .environ .get (
189
+ "PYTHON_SYS_EXECUTABLE" , sys .executable
190
+ ),
183
191
"PYO3_PYTHON" : os .environ .get ("PYO3_PYTHON" , sys .executable ),
184
192
}
185
193
)
@@ -212,7 +220,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
212
220
213
221
features = {
214
222
* ext .features ,
215
- * binding_features (ext , py_limited_api = self ._py_limited_api ())
223
+ * binding_features (ext , py_limited_api = self ._py_limited_api ()),
216
224
}
217
225
218
226
debug_build = ext .debug if ext .debug is not None else self .inplace
@@ -238,7 +246,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
238
246
args .append ("-q" )
239
247
elif self .verbose :
240
248
# cargo only have -vv
241
- verbose_level = 'v' * min (self .verbose , 2 )
249
+ verbose_level = "v" * min (self .verbose , 2 )
242
250
args .append (f"-{ verbose_level } " )
243
251
244
252
else :
@@ -254,7 +262,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
254
262
args .append ("-q" )
255
263
elif self .verbose :
256
264
# cargo only have -vv
257
- verbose_level = 'v' * min (self .verbose , 2 )
265
+ verbose_level = "v" * min (self .verbose , 2 )
258
266
args .append (f"-{ verbose_level } " )
259
267
260
268
args .extend (["--" , "--crate-type" , "cdylib" ])
@@ -293,9 +301,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
293
301
try :
294
302
output = subprocess .check_output (args , env = env , encoding = "latin-1" )
295
303
except subprocess .CalledProcessError as e :
296
- raise CompileError (
297
- f"cargo failed with code: { e .returncode } \n { e .output } "
298
- )
304
+ raise CompileError (f"cargo failed with code: { e .returncode } \n { e .output } " )
299
305
300
306
except OSError :
301
307
raise DistutilsExecError (
@@ -421,23 +427,18 @@ def install_extension(self, ext: RustExtension, dylib_paths):
421
427
mode |= (mode & 0o444 ) >> 2 # copy R bits to X
422
428
os .chmod (ext_path , mode )
423
429
424
- def get_dylib_ext_path (
425
- self ,
426
- ext : RustExtension ,
427
- target_fname : str
428
- ) -> str :
430
+ def get_dylib_ext_path (self , ext : RustExtension , target_fname : str ) -> str :
429
431
build_ext = self .get_finalized_command ("build_ext" )
430
432
431
433
filename = build_ext .get_ext_fullpath (target_fname )
432
434
433
- if (
434
- (ext .py_limited_api == "auto" and self ._py_limited_api ())
435
- or (ext .py_limited_api )
435
+ if (ext .py_limited_api == "auto" and self ._py_limited_api ()) or (
436
+ ext .py_limited_api
436
437
):
437
438
abi3_suffix = get_abi3_suffix ()
438
439
if abi3_suffix is not None :
439
- so_ext = get_config_var (' EXT_SUFFIX' )
440
- filename = filename [:- len (so_ext )] + get_abi3_suffix ()
440
+ so_ext = get_config_var (" EXT_SUFFIX" )
441
+ filename = filename [: - len (so_ext )] + get_abi3_suffix ()
441
442
442
443
return filename
443
444
@@ -451,9 +452,7 @@ def create_universal2_binary(output_path, input_paths):
451
452
output = e .output
452
453
if isinstance (output , bytes ):
453
454
output = e .output .decode ("latin-1" ).strip ()
454
- raise CompileError (
455
- "lipo failed with code: %d\n %s" % (e .returncode , output )
456
- )
455
+ raise CompileError ("lipo failed with code: %d\n %s" % (e .returncode , output ))
457
456
except OSError :
458
457
# lipo not found, try using the fat-macho library
459
458
try :
0 commit comments