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

Function configure_from_path

python27-sys/build.rs:342–407  ·  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

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

Callers 1

mainFunction · 0.70

Calls 2

watched_var_osFunction · 0.70

Tested by

no test coverage detected