Determine the python version we're supposed to be building from the features passed via the environment. The environment variable can choose to omit a minor version if the user doesn't care.
()
| 412 | /// The environment variable can choose to omit a minor |
| 413 | /// version if the user doesn't care. |
| 414 | fn version_from_env() -> Result<PythonVersion, String> { |
| 415 | let re = Regex::new(r"CARGO_FEATURE_PYTHON_(\d+)(_(\d+))?").unwrap(); |
| 416 | // sort env::vars so we get more explicit version specifiers first |
| 417 | // so if the user passes e.g. the python-3 feature and the python-3-5 |
| 418 | // feature, python-3-5 takes priority. |
| 419 | let mut vars = env::vars().collect::<Vec<_>>(); |
| 420 | vars.sort_by(|a, b| b.cmp(a)); |
| 421 | for (key, _) in vars { |
| 422 | if let Some(cap) = re.captures(&key) { |
| 423 | return Ok(PythonVersion { |
| 424 | major: cap.get(1).unwrap().as_str().parse().unwrap(), |
| 425 | minor: cap.get(3).map(|s| s.as_str().parse().unwrap()), |
| 426 | }); |
| 427 | } |
| 428 | } |
| 429 | Err( |
| 430 | "Python version feature was not found. At least one python version \ |
| 431 | feature must be enabled." |
| 432 | .to_owned(), |
| 433 | ) |
| 434 | } |
| 435 | |
| 436 | fn main() { |
| 437 | // 1. Setup cfg variables so we can do conditional compilation in this |