17
17
from subprocess import check_output
18
18
19
19
from .extension import RustExtension
20
- from .utils import Binding , Strip , cpython_feature , get_rust_version
20
+ from .utils import (
21
+ Binding , Strip , cpython_feature , get_rust_version , get_rust_target_info
22
+ )
21
23
22
24
23
25
class build_rust (Command ):
@@ -70,6 +72,8 @@ def finalize_options(self):
70
72
def build_extension (self , ext ):
71
73
executable = ext .binding == Binding .Exec
72
74
75
+ rust_target_info = get_rust_target_info ()
76
+
73
77
# Make sure that if pythonXX-sys is used, it builds against the current
74
78
# executing python interpreter.
75
79
bindir = os .path .dirname (sys .executable )
@@ -85,6 +89,7 @@ def build_extension(self, ext):
85
89
"PYO3_PYTHON" : sys .executable ,
86
90
}
87
91
)
92
+ rustflags = ""
88
93
89
94
# If we are on a 64-bit machine, but running a 32-bit Python, then
90
95
# we'll target a 32-bit Rust build.
@@ -162,12 +167,19 @@ def build_extension(self, ext):
162
167
args .extend (
163
168
["-C" , "link-arg=-undefined" , "-C" , "link-arg=dynamic_lookup" ]
164
169
)
170
+ # Tell musl targets not to statically link libc. See
171
+ # https://github.com/rust-lang/rust/issues/59302 for details.
172
+ if b'target_env="musl"' in rust_target_info :
173
+ rustflags += " -C target-feature=-crt-static"
165
174
166
175
if not quiet :
167
176
print (" " .join (args ), file = sys .stderr )
168
177
169
178
if ext .native :
170
- env ["RUSTFLAGS" ] = "-C target-cpu=native"
179
+ rustflags += " -C target-cpu=native"
180
+
181
+ if rustflags :
182
+ env ["RUSTFLAGS" ] = rustflags
171
183
172
184
# Execute cargo
173
185
try :
0 commit comments