Skip to content

Commit 6c3a4da

Browse files
authored
Merge pull request #31 from liranringel/explicitly-set-static-crt
Explicitly set static crt
2 parents d67e6ac + 59b49ef commit 6c3a4da

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ A build dependency for running `cmake` to build a native library
1414
"""
1515

1616
[dependencies]
17-
gcc = "0.3.17"
17+
gcc = "0.3.46"

src/lib.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub struct Config {
7272
build_args: Vec<OsString>,
7373
cmake_target: Option<String>,
7474
env: Vec<(OsString, OsString)>,
75+
static_crt: Option<bool>,
7576
}
7677

7778
/// Builds the native library rooted at `path` with the default cmake options.
@@ -112,6 +113,7 @@ impl Config {
112113
build_args: Vec::new(),
113114
cmake_target: None,
114115
env: Vec::new(),
116+
static_crt: None,
115117
}
116118
}
117119

@@ -191,6 +193,14 @@ impl Config {
191193
self
192194
}
193195

196+
/// Configures whether the /MT flag or the /MD flag will be passed to msvc build tools.
197+
///
198+
/// This option defaults to `false`, and affect only msvc targets.
199+
pub fn static_crt(&mut self, static_crt: bool) -> &mut Config {
200+
self.static_crt = Some(static_crt);
201+
self
202+
}
203+
194204
/// Add an argument to the final `cmake` build step
195205
pub fn build_arg<A: AsRef<OsStr>>(&mut self, arg: A) -> &mut Config {
196206
self.build_args.push(arg.as_ref().to_owned());
@@ -227,19 +237,25 @@ impl Config {
227237
getenv_unwrap("HOST")
228238
});
229239
let msvc = target.contains("msvc");
230-
let c_compiler = gcc::Config::new().cargo_metadata(false)
231-
.opt_level(0)
232-
.debug(false)
233-
.target(&target)
234-
.host(&host)
235-
.get_compiler();
236-
let cxx_compiler = gcc::Config::new().cargo_metadata(false)
237-
.cpp(true)
238-
.opt_level(0)
239-
.debug(false)
240-
.target(&target)
241-
.host(&host)
242-
.get_compiler();
240+
let mut c_cfg = gcc::Config::new();
241+
c_cfg.cargo_metadata(false)
242+
.opt_level(0)
243+
.debug(false)
244+
.target(&target)
245+
.host(&host);
246+
let mut cxx_cfg = gcc::Config::new();
247+
cxx_cfg.cargo_metadata(false)
248+
.cpp(true)
249+
.opt_level(0)
250+
.debug(false)
251+
.target(&target)
252+
.host(&host);
253+
if let Some(static_crt) = self.static_crt {
254+
c_cfg.static_crt(static_crt);
255+
cxx_cfg.static_crt(static_crt);
256+
}
257+
let c_compiler = c_cfg.get_compiler();
258+
let cxx_compiler = cxx_cfg.get_compiler();
243259

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

0 commit comments

Comments
 (0)