Compile to WASM using emscripten
This commit is contained in:
parent
8fe36f6102
commit
76d485b68a
1 changed files with 27 additions and 4 deletions
|
@ -62,25 +62,48 @@ fn main() {
|
||||||
.include(&lv_config_dir)
|
.include(&lv_config_dir)
|
||||||
.compile("lvgl");
|
.compile("lvgl");
|
||||||
|
|
||||||
let cc_args = [
|
let mut cc_args = vec![
|
||||||
"-DLV_CONF_INCLUDE_SIMPLE=1",
|
"-DLV_CONF_INCLUDE_SIMPLE=1",
|
||||||
"-I",
|
"-I",
|
||||||
lv_config_dir.to_str().unwrap(),
|
lv_config_dir.to_str().unwrap(),
|
||||||
"-I",
|
"-I",
|
||||||
vendor.to_str().unwrap(),
|
vendor.to_str().unwrap(),
|
||||||
|
"-fvisibility=default",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Set correct target triple for bindgen when cross-compiling
|
||||||
|
let target = env::var("TARGET").expect("Cargo build scripts always have TARGET");
|
||||||
|
let host = env::var("HOST").expect("Cargo build scripts always have HOST");
|
||||||
|
if target != host {
|
||||||
|
cc_args.push("-target");
|
||||||
|
cc_args.push(target.as_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut additional_args = Vec::new();
|
||||||
|
if target.ends_with("emscripten") {
|
||||||
|
if let Ok(em_path) = env::var("EMSDK") {
|
||||||
|
additional_args.push("-I".to_string());
|
||||||
|
additional_args.push(format!("{}/upstream/emscripten/system/include/libc", em_path));
|
||||||
|
additional_args.push("-I".to_string());
|
||||||
|
additional_args.push(format!("{}/upstream/emscripten/system/lib/libc/musl/arch/emscripten", em_path));
|
||||||
|
additional_args.push("-I".to_string());
|
||||||
|
additional_args.push(format!("{}/upstream/emscripten/system/include/SDL", em_path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
bindgen::Builder::default()
|
let bindings = bindgen::Builder::default()
|
||||||
.header(shims_dir.join("lvgl_sys.h").to_str().unwrap())
|
.header(shims_dir.join("lvgl_sys.h").to_str().unwrap())
|
||||||
.layout_tests(false)
|
.layout_tests(false)
|
||||||
.use_core()
|
.use_core()
|
||||||
.rustfmt_bindings(true)
|
.rustfmt_bindings(true)
|
||||||
.ctypes_prefix("cty")
|
.ctypes_prefix("cty")
|
||||||
.clang_args(&cc_args)
|
.clang_args(&cc_args)
|
||||||
|
.clang_args(&additional_args)
|
||||||
.generate()
|
.generate()
|
||||||
.expect("Unable to generate bindings")
|
.expect("Unable to generate bindings");
|
||||||
.write_to_file(out_path.join("bindings.rs"))
|
|
||||||
|
bindings.write_to_file(out_path.join("bindings.rs"))
|
||||||
.expect("Can't write bindings!");
|
.expect("Can't write bindings!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue