diff --git a/Cargo.toml b/Cargo.toml index 796b9f0c8..a11749ea2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ default = ["std", "cxxbridge-flags/default"] # c++11 "c++14" = ["cxxbridge-flags/c++14"] "c++17" = ["cxxbridge-flags/c++17"] "c++20" = ["cxxbridge-flags/c++20"] +"no_exceptions" = ["cxxbridge-flags/no_exceptions"] alloc = [] std = ["alloc"] diff --git a/build.rs b/build.rs index a6c89ccc0..db964617e 100644 --- a/build.rs +++ b/build.rs @@ -11,6 +11,7 @@ fn main() { .cpp(true) .cpp_link_stdlib(None) // linked via link-cplusplus crate .std(cxxbridge_flags::STD) + .define(cxxbridge_flags::EXCEPTIONS, None) .warnings_into_errors(cfg!(deny_warnings)) .compile("cxxbridge1"); diff --git a/flags/Cargo.toml b/flags/Cargo.toml index 56b7828d0..537893148 100644 --- a/flags/Cargo.toml +++ b/flags/Cargo.toml @@ -14,6 +14,7 @@ default = [] # c++11 "c++14" = [] "c++17" = [] "c++20" = [] +"no_exceptions" = [] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/flags/src/impl.rs b/flags/src/impl.rs index 4cf0713ed..2cbcef950 100644 --- a/flags/src/impl.rs +++ b/flags/src/impl.rs @@ -1,4 +1,4 @@ -#[allow(unused_assignments, unused_mut, unused_variables)] +#![allow(unused_assignments, unused_mut, unused_variables)] pub const STD: &str = { let mut flag = "c++11"; @@ -13,3 +13,12 @@ pub const STD: &str = { flag }; + +pub const EXCEPTIONS: &str = { + let mut flag = "RUST_CXX_ALLOW_EXCEPTIONS"; + + #[cfg(feature = "no_exceptions")] + (flag = "RUST_CXX_NO_EXCEPTIONS"); + + flag +};