@@ -167,8 +167,12 @@ pub struct InterpreterConfig {
167
167
///
168
168
/// Serialized to multiple `extra_build_script_line` values.
169
169
pub extra_build_script_lines : Vec < String > ,
170
+
170
171
/// macOS Python3.framework requires special rpath handling
171
172
pub python_framework_prefix : Option < String > ,
173
+
174
+ /// Relocatable Python installations require special rpath handling
175
+ pub relocatable : bool ,
172
176
}
173
177
174
178
impl InterpreterConfig {
@@ -265,6 +269,7 @@ print("calcsize_pointer", struct.calcsize("P"))
265
269
print("mingw", get_platform().startswith("mingw"))
266
270
print("ext_suffix", get_config_var("EXT_SUFFIX"))
267
271
print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
272
+ print_if_set("python_build_standalone", get_config_var("PYTHON_BUILD_STANDALONE"))
268
273
"# ;
269
274
let output = run_python_script ( interpreter. as_ref ( ) , SCRIPT ) ?;
270
275
let map: HashMap < String , String > = parse_script_output ( & output) ;
@@ -315,6 +320,13 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
315
320
_ => panic ! ( "Unknown Py_GIL_DISABLED value" ) ,
316
321
} ;
317
322
323
+ let relocatable = match map. get ( "python_build_standalone" ) . map ( String :: as_str) {
324
+ None => false ,
325
+ Some ( "0" ) => false ,
326
+ Some ( "1" ) => true ,
327
+ _ => panic ! ( "Unknown PYTHON_BUILD_STANDALONE value" ) ,
328
+ } ;
329
+
318
330
let lib_name = if cfg ! ( windows) {
319
331
default_lib_name_windows (
320
332
version,
@@ -365,6 +377,7 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
365
377
suppress_build_script_link_lines : false ,
366
378
extra_build_script_lines : vec ! [ ] ,
367
379
python_framework_prefix,
380
+ relocatable,
368
381
} )
369
382
}
370
383
@@ -410,6 +423,10 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
410
423
Some ( value) => value == "1" ,
411
424
None => false ,
412
425
} ;
426
+ let relocatable = match sysconfigdata. get_value ( "python_build_standalone" ) {
427
+ Some ( value) => value == "1" ,
428
+ None => false ,
429
+ } ;
413
430
let lib_name = Some ( default_lib_name_unix (
414
431
version,
415
432
implementation,
@@ -434,6 +451,7 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
434
451
suppress_build_script_link_lines : false ,
435
452
extra_build_script_lines : vec ! [ ] ,
436
453
python_framework_prefix,
454
+ relocatable,
437
455
} )
438
456
}
439
457
@@ -511,6 +529,7 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
511
529
let mut suppress_build_script_link_lines = None ;
512
530
let mut extra_build_script_lines = vec ! [ ] ;
513
531
let mut python_framework_prefix = None ;
532
+ let mut relocatable = None ;
514
533
515
534
for ( i, line) in lines. enumerate ( ) {
516
535
let line = line. context ( "failed to read line from config" ) ?;
@@ -540,6 +559,7 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
540
559
extra_build_script_lines. push ( value. to_string ( ) ) ;
541
560
}
542
561
"python_framework_prefix" => parse_value ! ( python_framework_prefix, value) ,
562
+ "relocatable" => parse_value ! ( relocatable, value) ,
543
563
unknown => warn ! ( "unknown config key `{}`" , unknown) ,
544
564
}
545
565
}
@@ -571,6 +591,7 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
571
591
suppress_build_script_link_lines : suppress_build_script_link_lines. unwrap_or ( false ) ,
572
592
extra_build_script_lines,
573
593
python_framework_prefix,
594
+ relocatable : relocatable. unwrap_or ( false ) ,
574
595
} )
575
596
}
576
597
@@ -663,12 +684,13 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
663
684
write_option_line ! ( executable) ?;
664
685
write_option_line ! ( pointer_width) ?;
665
686
write_line ! ( build_flags) ?;
666
- write_option_line ! ( python_framework_prefix) ?;
667
687
write_line ! ( suppress_build_script_link_lines) ?;
668
688
for line in & self . extra_build_script_lines {
669
689
writeln ! ( writer, "extra_build_script_line={}" , line)
670
690
. context ( "failed to write extra_build_script_line" ) ?;
671
691
}
692
+ write_option_line ! ( python_framework_prefix) ?;
693
+ write_line ! ( relocatable) ?;
672
694
Ok ( ( ) )
673
695
}
674
696
@@ -1601,7 +1623,10 @@ fn default_cross_compile(cross_compile_config: &CrossCompileConfig) -> Result<In
1601
1623
build_flags : BuildFlags :: default ( ) ,
1602
1624
suppress_build_script_link_lines : false ,
1603
1625
extra_build_script_lines : vec ! [ ] ,
1626
+ // Because this is only used for extensions, we know we do not
1627
+ // need any rpath handling.
1604
1628
python_framework_prefix : None ,
1629
+ relocatable : false ,
1605
1630
} )
1606
1631
}
1607
1632
@@ -1644,7 +1669,10 @@ fn default_abi3_config(host: &Triple, version: PythonVersion) -> Result<Interpre
1644
1669
build_flags : BuildFlags :: default ( ) ,
1645
1670
suppress_build_script_link_lines : false ,
1646
1671
extra_build_script_lines : vec ! [ ] ,
1672
+ // Because this is only used for extensions, we know we do not
1673
+ // need any rpath handling.
1647
1674
python_framework_prefix : None ,
1675
+ relocatable : false ,
1648
1676
} )
1649
1677
}
1650
1678
@@ -2028,6 +2056,7 @@ mod tests {
2028
2056
suppress_build_script_link_lines : true ,
2029
2057
extra_build_script_lines : vec ! [ "cargo:test1" . to_string( ) , "cargo:test2" . to_string( ) ] ,
2030
2058
python_framework_prefix : None ,
2059
+ relocatable : false ,
2031
2060
} ;
2032
2061
let mut buf: Vec < u8 > = Vec :: new ( ) ;
2033
2062
config. to_writer ( & mut buf) . unwrap ( ) ;
@@ -2057,6 +2086,7 @@ mod tests {
2057
2086
suppress_build_script_link_lines : false ,
2058
2087
extra_build_script_lines : vec ! [ ] ,
2059
2088
python_framework_prefix : None ,
2089
+ relocatable : true ,
2060
2090
} ;
2061
2091
let mut buf: Vec < u8 > = Vec :: new ( ) ;
2062
2092
config. to_writer ( & mut buf) . unwrap ( ) ;
@@ -2079,6 +2109,7 @@ mod tests {
2079
2109
suppress_build_script_link_lines : true ,
2080
2110
extra_build_script_lines : vec ! [ "cargo:test1" . to_string( ) , "cargo:test2" . to_string( ) ] ,
2081
2111
python_framework_prefix : None ,
2112
+ relocatable : false ,
2082
2113
} ;
2083
2114
let mut buf: Vec < u8 > = Vec :: new ( ) ;
2084
2115
config. to_writer ( & mut buf) . unwrap ( ) ;
@@ -2106,6 +2137,7 @@ mod tests {
2106
2137
suppress_build_script_link_lines: false ,
2107
2138
extra_build_script_lines: vec![ ] ,
2108
2139
python_framework_prefix: None ,
2140
+ relocatable: false ,
2109
2141
}
2110
2142
)
2111
2143
}
@@ -2129,6 +2161,7 @@ mod tests {
2129
2161
suppress_build_script_link_lines: false ,
2130
2162
extra_build_script_lines: vec![ ] ,
2131
2163
python_framework_prefix: None ,
2164
+ relocatable: false ,
2132
2165
}
2133
2166
)
2134
2167
}
@@ -2232,6 +2265,7 @@ mod tests {
2232
2265
suppress_build_script_link_lines: false ,
2233
2266
extra_build_script_lines: vec![ ] ,
2234
2267
python_framework_prefix: None ,
2268
+ relocatable: false ,
2235
2269
}
2236
2270
) ;
2237
2271
}
@@ -2262,6 +2296,7 @@ mod tests {
2262
2296
suppress_build_script_link_lines: false ,
2263
2297
extra_build_script_lines: vec![ ] ,
2264
2298
python_framework_prefix: None ,
2299
+ relocatable: false ,
2265
2300
}
2266
2301
) ;
2267
2302
@@ -2289,6 +2324,37 @@ mod tests {
2289
2324
suppress_build_script_link_lines: false ,
2290
2325
extra_build_script_lines: vec![ ] ,
2291
2326
python_framework_prefix: None ,
2327
+ relocatable: false ,
2328
+ }
2329
+ ) ;
2330
+ }
2331
+
2332
+ #[ test]
2333
+ fn config_from_sysconfigdata_relocatable ( ) {
2334
+ let mut sysconfigdata = Sysconfigdata :: new ( ) ;
2335
+ sysconfigdata. insert ( "SOABI" , "cpython-37m-x86_64-linux-gnu" ) ;
2336
+ sysconfigdata. insert ( "VERSION" , "3.7" ) ;
2337
+ sysconfigdata. insert ( "Py_ENABLE_SHARED" , "1" ) ;
2338
+ sysconfigdata. insert ( "LIBDIR" , "/home/xyz/Downloads/python/lib" ) ;
2339
+ sysconfigdata. insert ( "LDVERSION" , "3.7m" ) ;
2340
+ sysconfigdata. insert ( "SIZEOF_VOID_P" , "8" ) ;
2341
+ sysconfigdata. insert ( "PYTHON_BUILD_STANDALONE" , "1" ) ;
2342
+ assert_eq ! (
2343
+ InterpreterConfig :: from_sysconfigdata( & sysconfigdata) . unwrap( ) ,
2344
+ InterpreterConfig {
2345
+ abi3: false ,
2346
+ build_flags: BuildFlags :: from_sysconfigdata( & sysconfigdata) ,
2347
+ pointer_width: Some ( 64 ) ,
2348
+ executable: None ,
2349
+ implementation: PythonImplementation :: CPython ,
2350
+ lib_dir: Some ( "/home/xyz/Downloads/python/lib" . into( ) ) ,
2351
+ lib_name: Some ( "python3.7m" . into( ) ) ,
2352
+ shared: true ,
2353
+ version: PythonVersion :: PY37 ,
2354
+ suppress_build_script_link_lines: false ,
2355
+ extra_build_script_lines: vec![ ] ,
2356
+ python_framework_prefix: None ,
2357
+ relocatable: true ,
2292
2358
}
2293
2359
) ;
2294
2360
}
@@ -2313,6 +2379,7 @@ mod tests {
2313
2379
suppress_build_script_link_lines: false ,
2314
2380
extra_build_script_lines: vec![ ] ,
2315
2381
python_framework_prefix: None ,
2382
+ relocatable: false ,
2316
2383
}
2317
2384
) ;
2318
2385
}
@@ -2337,6 +2404,7 @@ mod tests {
2337
2404
suppress_build_script_link_lines: false ,
2338
2405
extra_build_script_lines: vec![ ] ,
2339
2406
python_framework_prefix: None ,
2407
+ relocatable: false ,
2340
2408
}
2341
2409
) ;
2342
2410
}
@@ -2372,6 +2440,7 @@ mod tests {
2372
2440
suppress_build_script_link_lines: false ,
2373
2441
extra_build_script_lines: vec![ ] ,
2374
2442
python_framework_prefix: None ,
2443
+ relcoatable: false ,
2375
2444
}
2376
2445
) ;
2377
2446
}
@@ -2407,6 +2476,7 @@ mod tests {
2407
2476
suppress_build_script_link_lines: false ,
2408
2477
extra_build_script_lines: vec![ ] ,
2409
2478
python_framework_prefix: None ,
2479
+ relocatable: false ,
2410
2480
}
2411
2481
) ;
2412
2482
}
@@ -2442,6 +2512,7 @@ mod tests {
2442
2512
suppress_build_script_link_lines: false ,
2443
2513
extra_build_script_lines: vec![ ] ,
2444
2514
python_framework_prefix: None ,
2515
+ relocatable; false ,
2445
2516
}
2446
2517
) ;
2447
2518
}
@@ -2479,6 +2550,7 @@ mod tests {
2479
2550
suppress_build_script_link_lines: false ,
2480
2551
extra_build_script_lines: vec![ ] ,
2481
2552
python_framework_prefix: None ,
2553
+ relocatable: false ,
2482
2554
}
2483
2555
) ;
2484
2556
}
@@ -2827,6 +2899,7 @@ mod tests {
2827
2899
suppress_build_script_link_lines : false ,
2828
2900
extra_build_script_lines : vec ! [ ] ,
2829
2901
python_framework_prefix : None ,
2902
+ relocatable : false ,
2830
2903
} ;
2831
2904
2832
2905
config
@@ -2850,6 +2923,7 @@ mod tests {
2850
2923
suppress_build_script_link_lines : false ,
2851
2924
extra_build_script_lines : vec ! [ ] ,
2852
2925
python_framework_prefix : None ,
2926
+ relocatable : false ,
2853
2927
} ;
2854
2928
2855
2929
assert ! ( config
@@ -2915,6 +2989,7 @@ mod tests {
2915
2989
suppress_build_script_link_lines: false ,
2916
2990
extra_build_script_lines: vec![ ] ,
2917
2991
python_framework_prefix: None ,
2992
+ relocatable: false ,
2918
2993
}
2919
2994
)
2920
2995
}
@@ -3040,6 +3115,7 @@ mod tests {
3040
3115
suppress_build_script_link_lines : false ,
3041
3116
extra_build_script_lines : vec ! [ ] ,
3042
3117
python_framework_prefix : None ,
3118
+ relocatable : false ,
3043
3119
} ;
3044
3120
assert_eq ! (
3045
3121
interpreter_config. build_script_outputs( ) ,
@@ -3080,6 +3156,7 @@ mod tests {
3080
3156
suppress_build_script_link_lines : false ,
3081
3157
extra_build_script_lines : vec ! [ ] ,
3082
3158
python_framework_prefix : None ,
3159
+ relocatable : false ,
3083
3160
} ;
3084
3161
3085
3162
assert_eq ! (
@@ -3128,6 +3205,7 @@ mod tests {
3128
3205
suppress_build_script_link_lines : false ,
3129
3206
extra_build_script_lines : vec ! [ ] ,
3130
3207
python_framework_prefix : None ,
3208
+ relocatable : false ,
3131
3209
} ;
3132
3210
3133
3211
assert_eq ! (
@@ -3162,6 +3240,7 @@ mod tests {
3162
3240
suppress_build_script_link_lines : false ,
3163
3241
extra_build_script_lines : vec ! [ ] ,
3164
3242
python_framework_prefix : None ,
3243
+ relocatable : false ,
3165
3244
} ;
3166
3245
3167
3246
assert_eq ! (
0 commit comments