Skip to content

Instantly share code, notes, and snippets.

@mishushakov
Created February 21, 2024 21:24
Show Gist options
  • Save mishushakov/b88eabb1f10fed48da648921040eb54d to your computer and use it in GitHub Desktop.
Save mishushakov/b88eabb1f10fed48da648921040eb54d to your computer and use it in GitHub Desktop.
Hermes bindgen
use std::env;
use std::path::PathBuf;
fn main() {
let hermes_src_dir = "./hermes";
let hermes_build_dir = "./release_debug";
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed=wrapper.h");
// Add include paths
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg(format!("-I{}/API/hermes_abi", hermes_src_dir))
.layout_tests(false)
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
// Add link paths and libraries
println!("cargo:rustc-link-search=native={}/API/hermes_abi", hermes_build_dir);
println!("cargo:rustc-link-lib=dylib=hermesabi");
}
#include <hermes_abi.h>
#include <hermes_vtable.h>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment