Skip to content

Explicitly set static crt #31

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

Merged
merged 3 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ A build dependency for running `cmake` to build a native library
"""

[dependencies]
gcc = "0.3.17"
gcc = "0.3.46"
42 changes: 29 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub struct Config {
build_args: Vec<OsString>,
cmake_target: Option<String>,
env: Vec<(OsString, OsString)>,
static_crt: Option<bool>,
}

/// Builds the native library rooted at `path` with the default cmake options.
Expand Down Expand Up @@ -112,6 +113,7 @@ impl Config {
build_args: Vec::new(),
cmake_target: None,
env: Vec::new(),
static_crt: None,
}
}

Expand Down Expand Up @@ -191,6 +193,14 @@ impl Config {
self
}

/// Configures whether the /MT flag or the /MD flag will be passed to msvc build tools.
///
/// This option defaults to `false`, and affect only msvc targets.
pub fn static_crt(&mut self, static_crt: bool) -> &mut Config {
self.static_crt = Some(static_crt);
self
}

/// Add an argument to the final `cmake` build step
pub fn build_arg<A: AsRef<OsStr>>(&mut self, arg: A) -> &mut Config {
self.build_args.push(arg.as_ref().to_owned());
Expand Down Expand Up @@ -227,19 +237,25 @@ impl Config {
getenv_unwrap("HOST")
});
let msvc = target.contains("msvc");
let c_compiler = gcc::Config::new().cargo_metadata(false)
.opt_level(0)
.debug(false)
.target(&target)
.host(&host)
.get_compiler();
let cxx_compiler = gcc::Config::new().cargo_metadata(false)
.cpp(true)
.opt_level(0)
.debug(false)
.target(&target)
.host(&host)
.get_compiler();
let mut c_cfg = gcc::Config::new();
c_cfg.cargo_metadata(false)
.opt_level(0)
.debug(false)
.target(&target)
.host(&host);
let mut cxx_cfg = gcc::Config::new();
cxx_cfg.cargo_metadata(false)
.cpp(true)
.opt_level(0)
.debug(false)
.target(&target)
.host(&host);
if let Some(static_crt) = self.static_crt {
c_cfg.static_crt(static_crt);
cxx_cfg.static_crt(static_crt);
}
let c_compiler = c_cfg.get_compiler();
let cxx_compiler = cxx_cfg.get_compiler();

let dst = self.out_dir.clone().unwrap_or_else(|| {
PathBuf::from(getenv_unwrap("OUT_DIR"))
Expand Down