Skip to content

Commit dd291ff

Browse files
committed
Switch emscripten compilation to C (from C++)
1 parent 5be36b6 commit dd291ff

1 file changed

Lines changed: 2 additions & 32 deletions

File tree

src/lib.rs

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Build {
107107
let target = self.target.as_ref().ok_or("TARGET is not set")?;
108108
let out_dir = self.out_dir.as_ref().ok_or("OUT_DIR is not set")?;
109109
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
110-
let mut source_dir = manifest_dir.join(version.source_dir());
110+
let source_dir = manifest_dir.join(version.source_dir());
111111
let lib_dir = out_dir.join("lib");
112112
let include_dir = out_dir.join("include");
113113

@@ -158,37 +158,7 @@ impl Build {
158158
_ if target.ends_with("emscripten") => {
159159
config
160160
.define("LUA_USE_POSIX", None)
161-
.cpp(true)
162-
.flag("-fexceptions")
163-
.flag("-fwasm-exceptions"); // Enable exceptions to be caught
164-
165-
let cpp_source_dir = out_dir.join("cpp_source");
166-
if cpp_source_dir.exists() {
167-
fs::remove_dir_all(&cpp_source_dir)
168-
.context(|| format!("Cannot remove '{}'", cpp_source_dir.display()))?;
169-
}
170-
fs::create_dir_all(&cpp_source_dir)
171-
.context(|| format!("Cannot create '{}'", cpp_source_dir.display()))?;
172-
173-
for file in fs::read_dir(&source_dir)
174-
.context(|| format!("Cannot read '{}'", source_dir.display()))?
175-
{
176-
let file = file?;
177-
let filename = file.file_name();
178-
let filename = &*filename.to_string_lossy();
179-
let src_file = source_dir.join(file.file_name());
180-
let dst_file = cpp_source_dir.join(file.file_name());
181-
182-
let mut content = fs::read(&src_file)
183-
.context(|| format!("Cannot read '{}'", src_file.display()))?;
184-
if ["lauxlib.h", "lua.h", "lualib.h"].contains(&filename) {
185-
content.splice(0..0, b"extern \"C\" {\n".to_vec());
186-
content.extend(b"\n}".to_vec())
187-
}
188-
fs::write(&dst_file, content)
189-
.context(|| format!("Cannot write to '{}'", dst_file.display()))?;
190-
}
191-
source_dir = cpp_source_dir
161+
.flag("-sSUPPORT_LONGJMP=wasm"); // Enable setjmp/longjmp support (WASM-specific)
192162
}
193163
_ if target.contains("wasi") => {
194164
// WASI is posix-like, but further patches are needed to the Lua

0 commit comments

Comments
 (0)