MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / configure_from_path

Function configure_from_path

python3-sys/build.rs:339–404  ·  view source on GitHub ↗

Deduce configuration from the 'python' in the current PATH and print cargo vars to stdout. Note that if the python doesn't satisfy expected_version, this will error.

(expected_version: &PythonVersion)

Source from the content-addressed store, hash-verified

337///
338/// Note that if the python doesn't satisfy expected_version, this will error.
339fn configure_from_path(expected_version: &PythonVersion) -> Result<String, String> {
340 let (interpreter_version, interpreter_path, lines) =
341 find_interpreter_and_get_config(expected_version)?;
342 let libpath: &str = &lines[0];
343 let enable_shared: &str = &lines[1];
344 let ld_version: &str = &lines[2];
345 let exec_prefix: &str = &lines[3];
346
347 let is_extension_module = watched_var_os("CARGO_FEATURE_EXTENSION_MODULE").is_some();
348 let mut link_mode_default = watched_var_os("CARGO_FEATURE_LINK_MODE_DEFAULT").is_some();
349 let link_mode_unresolved_static =
350 watched_var_os("CARGO_FEATURE_LINK_MODE_UNRESOLVED_STATIC").is_some();
351
352 if link_mode_default && link_mode_unresolved_static {
353 return Err(
354 "link-mode-default and link-mode-unresolved-static are mutually exclusive".to_owned(),
355 );
356 }
357
358 if !link_mode_default && !link_mode_unresolved_static {
359 link_mode_default = true;
360 }
361
362 if link_mode_default {
363 if !is_extension_module || cfg!(target_os = "windows") {
364 println!(
365 "{}",
366 get_rustc_link_lib(&interpreter_version, ld_version, enable_shared == "1").unwrap()
367 );
368 if libpath != "None" {
369 println!("cargo:rustc-link-search=native={}", libpath);
370 } else if cfg!(target_os = "windows") {
371 println!("cargo:rustc-link-search=native={}\\libs", exec_prefix);
372 }
373 }
374 } else if link_mode_unresolved_static && cfg!(target_os = "windows") {
375 // static-nobundle requires a Nightly rustc up to at least
376 // Rust 1.39 (https://github.com/rust-lang/rust/issues/37403).
377 //
378 // We need to use static linking on Windows to prevent symbol
379 // name mangling. Otherwise Rust will prefix extern {} symbols
380 // with __imp_. But if we used normal "static," we need a
381 // pythonXY.lib at build time to package into the rlib.
382 //
383 // static-nobundle removes the build-time library requirement,
384 // allowing a downstream consumer to provide the pythonXY library.
385 println!("cargo:rustc-link-lib=static-nobundle=pythonXY");
386 }
387
388 if let PythonVersion {
389 major: 3,
390 minor: some_minor,
391 } = interpreter_version
392 {
393 if watched_var_os("CARGO_FEATURE_PEP_384").is_some() {
394 println!("cargo:rustc-cfg=Py_LIMITED_API");
395 }
396 if let Some(minor) = some_minor {

Callers 1

mainFunction · 0.70

Calls 2

watched_var_osFunction · 0.70

Tested by

no test coverage detected