Skip to content

Create constructor allowing user to set c_cfg and cxx_cfg #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub struct Config {
verbose_cmake: bool,
verbose_make: bool,
pic: Option<bool>,
c_cfg: Option<cc::Build>,
cxx_cfg: Option<cc::Build>,
}

/// Builds the native library rooted at `path` with the default cmake options.
Expand All @@ -103,6 +105,16 @@ impl Config {
/// Creates a new blank set of configuration to build the project specified
/// at the path `path`.
pub fn new<P: AsRef<Path>>(path: P) -> Config {
Config::new_with_configs(path, None, None)
}

/// Creates a new blank set of configuration to build the project specified
/// at the path `path`.
pub fn new_with_configs<P: AsRef<Path>>(
path: P,
c_cfg: Option<cc::Build>,
cxx_cfg: Option<cc::Build>,
) -> Config {
Config {
path: env::current_dir().unwrap().join(path),
generator: None,
Expand All @@ -125,6 +137,8 @@ impl Config {
verbose_cmake: false,
verbose_make: false,
pic: None,
c_cfg,
cxx_cfg,
}
}

Expand Down Expand Up @@ -326,7 +340,11 @@ impl Config {
let host = self.host.clone().unwrap_or_else(|| getenv_unwrap("HOST"));
let msvc = target.contains("msvc");
let ndk = self.uses_android_ndk();
let mut c_cfg = cc::Build::new();
let mut c_cfg = if let Some(cfg) = self.c_cfg.take() {
cfg
} else {
cc::Build::new()
};
c_cfg
.cargo_metadata(false)
.opt_level(0)
Expand All @@ -337,7 +355,12 @@ impl Config {
if !ndk {
c_cfg.target(&target);
}
let mut cxx_cfg = cc::Build::new();

let mut cxx_cfg = if let Some(cfg) = self.cxx_cfg.take() {
cfg
} else {
cc::Build::new()
};
cxx_cfg
.cargo_metadata(false)
.cpp(true)
Expand Down