Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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"
12 changes: 12 additions & 0 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 @@ -232,13 +242,15 @@ impl Config {
.debug(false)
.target(&target)
.host(&host)
.static_crt(self.static_crt.unwrap_or(false))
Copy link
Member

Choose a reason for hiding this comment

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

For maximal safety to trigger the None fallback logic in gcc-rs, could this only be configured if static_crt is explicitly set in cmake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right!

.get_compiler();
let cxx_compiler = gcc::Config::new().cargo_metadata(false)
.cpp(true)
.opt_level(0)
.debug(false)
.target(&target)
.host(&host)
.static_crt(self.static_crt.unwrap_or(false))
.get_compiler();

let dst = self.out_dir.clone().unwrap_or_else(|| {
Expand Down