Skip to content

Commit 58c8c46

Browse files
ian-h-chamberlainogoffart
authored andcommitted
impl From<cc::Build> for cpp_build::Config
1 parent 9eda55b commit 58c8c46

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

cpp_build/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,22 @@ impl Default for Config {
400400
}
401401
}
402402

403+
/// Convert from a preconfigured [`cc::Build`] object to [`Config`].
404+
/// Note that this will ensure C++ is enabled and add the proper include
405+
/// directories to work with `cpp`.
406+
impl From<cc::Build> for Config {
407+
fn from(mut cc: cc::Build) -> Self {
408+
cc.cpp(true).include(&*CARGO_MANIFEST_DIR);
409+
Self { cc, std_flag_set: false }
410+
}
411+
}
412+
403413
impl Config {
404414
/// Create a new `Config` object. This object will hold the configuration
405415
/// options which control the build. If you don't need to make any changes,
406416
/// `cpp_build::build` is a wrapper function around this interface.
407417
pub fn new() -> Config {
408-
let mut cc = cc::Build::new();
409-
cc.cpp(true).include(&*CARGO_MANIFEST_DIR);
410-
Config { cc, std_flag_set: false }
418+
cc::Build::new().into()
411419
}
412420

413421
/// Add a directory to the `-I` or include path for headers

0 commit comments

Comments
 (0)