diff --git a/src/lib.rs b/src/lib.rs index c27daed..819d4b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +#![feature(if_let)] + use std::os; use std::io::Command; use std::io::process::InheritFd; @@ -7,12 +9,15 @@ use std::default::Default; pub struct Config { /// Directories where gcc will look for header files. pub include_directories: Vec, + /// Additional definitions (`-DKEY` or `-DKEY=VALUE`). + pub definitions: Vec<(String, Option)>, } impl Default for Config { fn default() -> Config { Config { include_directories: Vec::new(), + definitions: Vec::new(), } } } @@ -59,6 +64,14 @@ pub fn compile_library(output: &str, config: &Config, files: &[&str]) { cmd.arg("-I").arg(directory); } + for &(ref key, ref value) in config.definitions.iter() { + if let &Some(ref value) = value { + cmd.arg(format!("-D{}={}", key, value)); + } else { + cmd.arg(format!("-D{}", key)); + } + } + let src = Path::new(os::getenv("CARGO_MANIFEST_DIR").unwrap()); let dst = Path::new(os::getenv("OUT_DIR").unwrap()); let mut objects = Vec::new();