@@ -56,7 +56,7 @@ impl Build {
56
56
let include_dir = out_dir. join ( "include" ) ;
57
57
58
58
let source_dir_base = Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
59
- let source_dir = match version {
59
+ let mut source_dir = match version {
60
60
Lua51 => source_dir_base. join ( "lua-5.1.5" ) ,
61
61
Lua52 => source_dir_base. join ( "lua-5.2.4" ) ,
62
62
Lua53 => source_dir_base. join ( "lua-5.3.6" ) ,
@@ -105,7 +105,33 @@ impl Build {
105
105
config. define ( "LUA_USE_WINDOWS" , None ) ;
106
106
}
107
107
_ if target. ends_with ( "emscripten" ) => {
108
- config. define ( "LUA_USE_POSIX" , None ) ;
108
+ config
109
+ . define ( "LUA_USE_POSIX" , None )
110
+ . cpp ( true )
111
+ . flag ( "-fexceptions" ) ; // Enable exceptions to be caught
112
+
113
+ let cpp_source_dir = out_dir. join ( "cpp_source" ) ;
114
+ if cpp_source_dir. exists ( ) {
115
+ fs:: remove_dir_all ( & cpp_source_dir) . unwrap ( ) ;
116
+ }
117
+ fs:: create_dir_all ( & cpp_source_dir) . unwrap ( ) ;
118
+
119
+ for file in fs:: read_dir ( & source_dir) . unwrap ( ) {
120
+ let file = file. unwrap ( ) ;
121
+ let filename = file. file_name ( ) . to_string_lossy ( ) . to_string ( ) ;
122
+ let src_file = source_dir. join ( file. file_name ( ) ) ;
123
+ let dst_file = cpp_source_dir. join ( file. file_name ( ) ) ;
124
+
125
+ let mut content = fs:: read ( src_file) . unwrap ( ) ;
126
+ // ljumptab.h only contains definitions and will cause errors when wrapping with
127
+ // 'extern "C"'
128
+ if filename. ends_with ( ".h" ) && ![ "ljumptab.h" ] . contains ( & filename. as_str ( ) ) {
129
+ content. splice ( 0 ..0 , b"extern \" C\" {\n " . to_vec ( ) ) ;
130
+ content. extend ( b"\n }" . to_vec ( ) )
131
+ }
132
+ fs:: write ( dst_file, content) . unwrap ( ) ;
133
+ }
134
+ source_dir = cpp_source_dir
109
135
}
110
136
_ => panic ! ( "don't know how to build Lua for {}" , target) ,
111
137
} ;
0 commit comments