diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..1b13f9854 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "crates/mun_abi/c"] + path = crates/mun_abi/c + url = ../abi-c diff --git a/Cargo.toml b/Cargo.toml index ad61bcc22..664b607fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ [workspace] members = [ + "crates\\mun_abi", "crates\\mun_runtime", "crates\\mun_symbols", ] diff --git a/crates/mun_abi/Cargo.toml b/crates/mun_abi/Cargo.toml new file mode 100644 index 000000000..e89339e0c --- /dev/null +++ b/crates/mun_abi/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "mun_abi" +version = "0.1.0" +authors = ["Wodann "] +edition = "2018" + +[build-dependencies] +bindgen = "0.51" diff --git a/crates/mun_abi/build.rs b/crates/mun_abi/build.rs new file mode 100644 index 000000000..7939d166c --- /dev/null +++ b/crates/mun_abi/build.rs @@ -0,0 +1,48 @@ +use std::env; +use std::path::PathBuf; + +use bindgen::{self, callbacks::EnumVariantValue, callbacks::ParseCallbacks}; + +#[derive(Debug)] +struct RemoveVendorName; + +impl ParseCallbacks for RemoveVendorName { + fn enum_variant_name( + &self, + enum_name: Option<&str>, + original_variant_name: &str, + _variant_value: EnumVariantValue, + ) -> Option { + Some( + original_variant_name + .trim_start_matches(enum_name.unwrap_or("")) + .to_string(), + ) + } + + fn item_name(&self, original_item_name: &str) -> Option { + if original_item_name == "MunPrivacy_t" { + Some("Privacy".to_string()) + } else { + Some(original_item_name.trim_start_matches("Mun").to_string()) + } + } +} + +fn main() { + let bindings = bindgen::Builder::default() + .header("c/include/mun_abi.h") + .whitelist_type("Mun.*") + .blacklist_type("MunPrivacy.*") + .parse_callbacks(Box::new(RemoveVendorName)) + .generate() + .expect("Unable to generate bindings for 'mun_abi.h'"); + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect(&format!( + "Couldn't write bindings to '{}'", + out_path.as_path().to_string_lossy() + )); +} diff --git a/crates/mun_abi/c b/crates/mun_abi/c new file mode 160000 index 000000000..97e94fb43 --- /dev/null +++ b/crates/mun_abi/c @@ -0,0 +1 @@ +Subproject commit 97e94fb43e206df7293e59d7043b3a830a9f760e diff --git a/crates/mun_abi/src/lib.rs b/crates/mun_abi/src/lib.rs new file mode 100644 index 000000000..970cba925 --- /dev/null +++ b/crates/mun_abi/src/lib.rs @@ -0,0 +1,7 @@ +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +#[repr(u8)] +pub enum Privacy { + Public = 0, + Private = 1, +}