Skip to content

Commit 838ffb2

Browse files
authored
Add build_with for custom cc::Build setups (#112)
* Add build_with for custom cc::Build setups * Switch initial cc::Build configs to Config options Removed build_with in favour of configuration options in Config which can be set using init_c_cfg and init_cxx_cfg.
1 parent 22407b2 commit 838ffb2

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/lib.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ pub struct Config {
7777
verbose_cmake: bool,
7878
verbose_make: bool,
7979
pic: Option<bool>,
80+
c_cfg: Option<cc::Build>,
81+
cxx_cfg: Option<cc::Build>,
8082
}
8183

8284
/// Builds the native library rooted at `path` with the default cmake options.
@@ -196,6 +198,8 @@ impl Config {
196198
verbose_cmake: false,
197199
verbose_make: false,
198200
pic: None,
201+
c_cfg: None,
202+
cxx_cfg: None,
199203
}
200204
}
201205

@@ -378,6 +382,18 @@ impl Config {
378382
})
379383
}
380384

385+
/// Initializes the C build configuration.
386+
pub fn init_c_cfg(&mut self, c_cfg: cc::Build) -> &mut Config {
387+
self.c_cfg = Some(c_cfg);
388+
self
389+
}
390+
391+
/// Initializes the C++ build configuration.
392+
pub fn init_cxx_cfg(&mut self, cxx_cfg: cc::Build) -> &mut Config {
393+
self.cxx_cfg = Some(cxx_cfg);
394+
self
395+
}
396+
381397
/// Run this configuration, compiling the library with all the configured
382398
/// options.
383399
///
@@ -397,9 +413,10 @@ impl Config {
397413
let host = self.host.clone().unwrap_or_else(|| getenv_unwrap("HOST"));
398414
let msvc = target.contains("msvc");
399415
let ndk = self.uses_android_ndk();
400-
let mut c_cfg = cc::Build::new();
416+
let mut c_cfg = self.c_cfg.clone().unwrap_or_default();
401417
c_cfg
402418
.cargo_metadata(false)
419+
.cpp(false)
403420
.opt_level(0)
404421
.debug(false)
405422
.warnings(false)
@@ -408,7 +425,7 @@ impl Config {
408425
if !ndk {
409426
c_cfg.target(&target);
410427
}
411-
let mut cxx_cfg = cc::Build::new();
428+
let mut cxx_cfg = self.c_cfg.clone().unwrap_or_default();
412429
cxx_cfg
413430
.cargo_metadata(false)
414431
.cpp(true)

0 commit comments

Comments
 (0)