@@ -135,13 +135,29 @@ fn patch_sysconfigdata(mut data: SysconfigData, real_prefix: &Path) -> Sysconfig
135135 . join ( " " )
136136 }
137137
138+ /// Remove any references to `-isysroot` in a whitespace-separated string.
139+ fn remove_isysroot ( s : & str ) -> String {
140+ // If we see `-isysroot`, drop it and the next part.
141+ let mut parts = s. split_whitespace ( ) . peekable ( ) ;
142+ let mut result = Vec :: with_capacity ( parts. size_hint ( ) . 0 ) ;
143+ while let Some ( part) = parts. next ( ) {
144+ if part == "-isysroot" {
145+ parts. next ( ) ;
146+ } else {
147+ result. push ( part) ;
148+ }
149+ }
150+ result. join ( " " )
151+ }
152+
138153 // Patch each value, as needed.
139154 let mut count = 0 ;
140155 for ( key, value) in data. iter_mut ( ) {
141156 let Value :: String ( value) = value else {
142157 continue ;
143158 } ;
144159 let patched = update_prefix ( value, real_prefix) ;
160+ let patched = remove_isysroot ( & patched) ;
145161 if * value != patched {
146162 trace ! ( "Updated `{key}` from `{value}` to `{patched}`" ) ;
147163 count += 1 ;
@@ -184,6 +200,9 @@ mod tests {
184200 fn update_real_prefix ( ) -> Result < ( ) , Error > {
185201 let sysconfigdata = [
186202 ( "BASEMODLIBS" , "" ) ,
203+ ( "BINDIR" , "/install/bin" ) ,
204+ ( "BINLIBDEST" , "/install/lib/python3.10" ) ,
205+ ( "BLDLIBRARY" , "-L. -lpython3.10" ) ,
187206 ( "BUILDPYTHON" , "python.exe" ) ,
188207 ( "prefix" , "/install/prefix" ) ,
189208 ( "exec_prefix" , "/install/exec_prefix" ) ,
@@ -200,6 +219,9 @@ mod tests {
200219 # system configuration generated and used by the sysconfig module
201220 build_time_vars = {
202221 "BASEMODLIBS": "",
222+ "BINDIR": "/real/prefix/bin",
223+ "BINLIBDEST": "/real/prefix/lib/python3.10",
224+ "BLDLIBRARY": "-L. -lpython3.10",
203225 "BUILDPYTHON": "python.exe",
204226 "PYTHON_BUILD_STANDALONE": 1,
205227 "base": "/real/prefix/base",
@@ -210,4 +232,27 @@ mod tests {
210232
211233 Ok ( ( ) )
212234 }
235+
236+ #[ test]
237+ fn remove_isysroot ( ) -> Result < ( ) , Error > {
238+ let sysconfigdata = [
239+ ( "BLDSHARED" , "clang -bundle -undefined dynamic_lookup -arch arm64 -isysroot /Applications/MacOSX14.2.sdk" ) ,
240+ ]
241+ . into_iter ( )
242+ . map ( |( k, v) | ( k. to_string ( ) , Value :: String ( v. to_string ( ) ) ) )
243+ . collect :: < SysconfigData > ( ) ;
244+
245+ let real_prefix = Path :: new ( "/real/prefix" ) ;
246+ let data = patch_sysconfigdata ( sysconfigdata, real_prefix) ;
247+
248+ insta:: assert_snapshot!( data. to_string_pretty( ) ?, @r###"
249+ # system configuration generated and used by the sysconfig module
250+ build_time_vars = {
251+ "BLDSHARED": "clang -bundle -undefined dynamic_lookup -arch arm64",
252+ "PYTHON_BUILD_STANDALONE": 1
253+ }
254+ "### ) ;
255+
256+ Ok ( ( ) )
257+ }
213258}
0 commit comments