From 3f22490d23183fc1a0367b387146e73d558b9d7c Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Mon, 4 Nov 2024 12:58:04 +0000 Subject: [PATCH] Expose cc-rs no_default_flags for hassle-free cross-compilation --- src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d3fa035..35ce4cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,6 +77,7 @@ pub struct Config { uses_cxx11: bool, always_configure: bool, no_build_target: bool, + no_default_flags: bool, verbose_cmake: bool, verbose_make: bool, pic: Option, @@ -184,6 +185,7 @@ impl Config { path: env::current_dir().unwrap().join(path), generator: None, generator_toolset: None, + no_default_flags: false, cflags: OsString::new(), cxxflags: OsString::new(), asmflags: OsString::new(), @@ -297,6 +299,13 @@ impl Config { self } + /// Disables the generation of default compiler flags. The default compiler + /// flags may cause conflicts in some cross compiling scenarios. + pub fn no_default_flags(&mut self, no_default_flags: bool) -> &mut Config { + self.no_default_flags = no_default_flags; + self + } + /// Sets the host triple for this compilation. /// /// This is automatically scraped from `$HOST` which is set for Cargo @@ -515,7 +524,7 @@ impl Config { .debug(false) .warnings(false) .host(&host) - .no_default_flags(ndk); + .no_default_flags(ndk || self.no_default_flags); if !ndk { c_cfg.target(&target); } @@ -527,7 +536,7 @@ impl Config { .debug(false) .warnings(false) .host(&host) - .no_default_flags(ndk); + .no_default_flags(ndk || self.no_default_flags); if !ndk { cxx_cfg.target(&target); }