From 0188766f4ed9c16bf064e486bb74493f057404ce Mon Sep 17 00:00:00 2001 From: Liran Date: Thu, 11 May 2017 23:43:09 +0200 Subject: [PATCH 1/3] Explicitly set static crt --- Cargo.toml | 2 +- src/lib.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 86f259c..6462922 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,4 @@ A build dependency for running `cmake` to build a native library """ [dependencies] -gcc = "0.3.17" +gcc = "0.3.46" diff --git a/src/lib.rs b/src/lib.rs index 8420026..672d5a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,6 +72,7 @@ pub struct Config { build_args: Vec, cmake_target: Option, env: Vec<(OsString, OsString)>, + static_crt: Option, } /// Builds the native library rooted at `path` with the default cmake options. @@ -112,6 +113,7 @@ impl Config { build_args: Vec::new(), cmake_target: None, env: Vec::new(), + static_crt: None, } } @@ -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>(&mut self, arg: A) -> &mut Config { self.build_args.push(arg.as_ref().to_owned()); @@ -232,6 +242,7 @@ impl Config { .debug(false) .target(&target) .host(&host) + .static_crt(self.static_crt.unwrap_or(false)) .get_compiler(); let cxx_compiler = gcc::Config::new().cargo_metadata(false) .cpp(true) @@ -239,6 +250,7 @@ impl Config { .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(|| { From 9208781581453673c20a9151fdfa9798e6138732 Mon Sep 17 00:00:00 2001 From: Liran Date: Fri, 12 May 2017 00:25:26 +0200 Subject: [PATCH 2/3] Set `static_crt` to `gcc::Config` only if it was set to `cmake::Config` --- src/lib.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 672d5a0..4e13a09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -237,21 +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) - .static_crt(self.static_crt.unwrap_or(false)) - .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 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(); + let cxx_compiler = gcc::Config::new().get_compiler(); let dst = self.out_dir.clone().unwrap_or_else(|| { PathBuf::from(getenv_unwrap("OUT_DIR")) From 59b49ef89d95e14baa177cc45dcd9fd91bc443ff Mon Sep 17 00:00:00 2001 From: Liran Date: Fri, 12 May 2017 13:46:27 +0200 Subject: [PATCH 3/3] Use `c_cfg` instead of new `gcc::Config` --- src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4e13a09..e4e72fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -254,9 +254,8 @@ impl Config { c_cfg.static_crt(static_crt); cxx_cfg.static_crt(static_crt); } - - let c_compiler = gcc::Config::new().get_compiler(); - let cxx_compiler = gcc::Config::new().get_compiler(); + 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"))