File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,24 @@ fn main() {
9
9
let manifest_dir_opt = env:: var_os ( "CARGO_MANIFEST_DIR" ) . map ( PathBuf :: from) ;
10
10
let manifest_dir = manifest_dir_opt. as_deref ( ) . unwrap_or ( Path :: new ( "" ) ) ;
11
11
12
- cc:: Build :: new ( )
12
+ let mut builder = cc:: Build :: new ( ) ;
13
+ builder
13
14
. file ( manifest_dir. join ( "src/cxx.cc" ) )
14
15
. cpp ( true )
15
16
. cpp_link_stdlib ( None ) // linked via link-cplusplus crate
16
17
. std ( cxxbridge_flags:: STD )
17
- . warnings_into_errors ( cfg ! ( deny_warnings) )
18
- . compile ( "cxxbridge1" ) ;
18
+ . warnings_into_errors ( cfg ! ( deny_warnings) ) ;
19
+
20
+ // If we are building for WASM then ensure that RUST_CXX_NO_EXCEPTIONS is defined
21
+ // otherwise the crate can fail to build for WASM targets
22
+ //
23
+ // Note that this could also be done via `target_family = "wasm"`
24
+ // but instead we are copying how the `cc` crate detects WASM
25
+ // https://github.com/rust-lang/cc-rs/blob/a0441c3bca087c6457824d05857e00d8e8b06753/src/lib.rs#L2016
26
+ #[ cfg( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ]
27
+ builder. define ( "RUST_CXX_NO_EXCEPTIONS" , None ) ;
28
+
29
+ builder. compile ( "cxxbridge1" ) ;
19
30
20
31
println ! ( "cargo:rerun-if-changed=src/cxx.cc" ) ;
21
32
println ! ( "cargo:rerun-if-changed=include/cxx.h" ) ;
You can’t perform that action at this time.
0 commit comments