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,17 @@ def build_extension(self, ext):
162
167
args .extend (
163
168
["-C" , "link-arg=-undefined" , "-C" , "link-arg=dynamic_lookup" ]
164
169
)
170
+ if b'target_env="musl"' in rust_target_info :
171
+ rustflags += " -C target-feature=-crt-static"
165
172
166
173
if not quiet :
167
174
print (" " .join (args ), file = sys .stderr )
168
175
169
176
if ext .native :
170
- env ["RUSTFLAGS" ] = "-C target-cpu=native"
177
+ rustflags += " -C target-cpu=native"
178
+
179
+ if rustflags :
180
+ env ["RUSTFLAGS" ] = rustflags
171
181
172
182
# Execute cargo
173
183
try :
0 commit comments