pyo3/build.rs
James Salter b1eca56ec3 Python 3 build support
* Add python3-sys to rust-cpython as an optional feature, and
  make python27-sys also optional, but still the default
* Parametrise python27-sys/build.rs so that it is python
  version independent, and clone it into python3-sys/build.rs.
  Hopefully this can continue to be maintained as an identical
  file.
* python27-sys and python3-sys gain features for explicitly
  selecting a python version to link to. for python27-sys,
  there's currently only python27; for python3-sys there's
  python 3.4 and 3.5.
* explicitly tell travis to use nightlies (seems to have
  started trying to use 1.0.0)
2015-05-23 15:23:08 +01:00

39 lines
1.3 KiB
Rust

use std::env;
use std::io::Write;
const CFG_KEY: &'static str = "py_sys_config";
#[cfg(feature="python27-sys")]
const PYTHONSYS_ENV_VAR: &'static str = "DEP_PYTHON27_PYTHON_FLAGS";
#[cfg(feature="python3-sys")]
const PYTHONSYS_ENV_VAR: &'static str = "DEP_PYTHON3_PYTHON_FLAGS";
fn main() {
// python{27,3.x}-sys/build.rs passes python interpreter compile flags via
// environment variable (using the 'links' mechanism in the cargo.toml).
let flags = match env::var(PYTHONSYS_ENV_VAR) {
Ok(flags) => flags,
Err(_) => {
writeln!(std::io::stderr(),
"Environment variable {} not found - this is supposed to be \
exported from the pythonXX-sys dependency, so the build chain is broken",
PYTHONSYS_ENV_VAR).unwrap();
std::process::exit(1);
}
};
for f in flags.split(",") {
// write out flags as --cfg so that the same #cfg blocks can be used
// in rust-cpython as in the -sys libs
let key_and_val: Vec<&str> = f.split("=").collect();
let key = key_and_val[0];
let val = key_and_val[1];
if key.starts_with("FLAG") {
println!("cargo:rustc-cfg={}=\"{}\"", CFG_KEY, &key[5..])
} else {
println!("cargo:rustc-cfg={}=\"{}_{}\"", CFG_KEY, &key[4..], val);
}
}
}