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

Function main

python27-sys/build.rs:436–496  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

434}
435
436fn main() {
437 // 1. Setup cfg variables so we can do conditional compilation in this
438 // library based on the python interpeter's compilation flags. This is
439 // necessary for e.g. matching the right unicode and threading interfaces.
440 //
441 // This locates the python interpreter based on the PATH, which should
442 // work smoothly with an activated virtualenv.
443 //
444 // If you have troubles with your shell accepting '.' in a var name,
445 // try using 'env' (sorry but this isn't our fault - it just has to
446 // match the pkg-config package name, which is going to have a . in it).
447 let version = version_from_env().unwrap();
448 let python_interpreter_path = configure_from_path(&version).unwrap();
449 let mut config_map = get_config_vars(&python_interpreter_path).unwrap();
450 if is_not_none_or_zero(config_map.get("Py_DEBUG")) {
451 config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned()); // Py_DEBUG implies Py_TRACE_REFS.
452 }
453 if is_not_none_or_zero(config_map.get("Py_TRACE_REFS")) {
454 config_map.insert("Py_REF_DEBUG".to_owned(), "1".to_owned()); // Py_TRACE_REFS implies Py_REF_DEBUG.
455 }
456 for (key, val) in &config_map {
457 if let Some(line) = cfg_line_for_var(key, val) {
458 println!("{}", line);
459 }
460 }
461
462 // 2. Export python interpreter compilation flags as cargo variables that
463 // will be visible to dependents. All flags will be available to dependent
464 // build scripts in the environment variable DEP_PYTHON27_PYTHON_FLAGS as
465 // comma separated list; each item in the list looks like
466 //
467 // {VAL,FLAG}_{flag_name}=val;
468 //
469 // FLAG indicates the variable is always 0 or 1
470 // VAL indicates it can take on any value
471 //
472 // rust-cypthon/build.rs contains an example of how to unpack this data
473 // into cfg flags that replicate the ones present in this library, so
474 // you can use the same cfg syntax.
475 let flags: String = config_map.iter().fold("".to_owned(), |memo, (key, val)| {
476 if is_value(key) {
477 memo + format!("VAL_{}={},", key, val).as_ref()
478 } else if val != "0" {
479 memo + format!("FLAG_{}={},", key, val).as_ref()
480 } else {
481 memo
482 }
483 });
484 println!(
485 "cargo:python_flags={}",
486 if !flags.is_empty() {
487 &flags[..flags.len() - 1]
488 } else {
489 ""
490 }
491 );
492
493 // 3. Export Python interpreter path as a Cargo variable so dependent build

Callers

nothing calls this directly

Calls 9

insertMethod · 0.80
version_from_envFunction · 0.70
configure_from_pathFunction · 0.70
get_config_varsFunction · 0.70
is_not_none_or_zeroFunction · 0.70
cfg_line_for_varFunction · 0.70
is_valueFunction · 0.70
getMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected