Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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"
43 changes: 30 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,26 @@ 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 = gcc::Config::new().get_compiler();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be using c_cfg and cxx_cfg from above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fixed that

let cxx_compiler = gcc::Config::new().get_compiler();

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