Skip to content

Commit e3d98fa

Browse files
committed
[component_macro] Add host_bindgen!()
This adds a proc-macro crate that exposes the bindings code generation from hyperlight_component_util as a macro suitable for using WIT to define a hyperlight host<->guest interface. Signed-off-by: Lucy Menon <[email protected]>
1 parent a5148db commit e3d98fa

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Diff for: Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"src/hyperlight_guest_capi",
1010
"fuzz",
1111
"src/hyperlight_component_util",
12+
"src/hyperlight_component_macro",
1213
]
1314
# Guests have custom linker flags, so we need to exclude them from the workspace
1415
exclude = [
@@ -32,6 +33,7 @@ hyperlight-host = { path = "src/hyperlight_host", version = "0.2.0", default-fea
3233
hyperlight-guest = { path = "src/hyperlight_guest", version = "0.2.0", default-features = false }
3334
hyperlight-testing = { path = "src/hyperlight_testing", default-features = false }
3435
hyperlight-component-util = { path = "src/hyperlight_component_util" }
36+
hyperlight-component-macro = { path = "src/hyperlight_component_macro" }
3537

3638
[workspace.lints.rust]
3739
unsafe_op_in_unsafe_fn = "deny"

Diff for: src/hyperlight_component_macro/Cargo.toml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "hyperlight-component-macro"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
readme.workspace = true
10+
description = """
11+
Procedural macros to generate Hyperlight host and guest bindings from component types
12+
"""
13+
14+
[lib]
15+
name = "hyperlight_component_macro"
16+
proc-macro = true
17+
18+
[dependencies]
19+
wasmparser = { version = "0.224.0" }
20+
quote = { version = "1.0.38" }
21+
proc-macro2 = { version = "1.0.93" }
22+
syn = { version = "2.0.96" }
23+
itertools = { version = "0.14.0" }
24+
prettyplease = { version = "0.2.31" }
25+
hyperlight-component-util = { workspace = true }

Diff for: src/hyperlight_component_macro/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
extern crate proc_macro;
2+
3+
use hyperlight_component_util::*;
4+
5+
#[proc_macro]
6+
pub fn host_bindgen(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
7+
let path: String = syn::parse_macro_input!(input as syn::LitStr).value();
8+
util::read_wit_type_from_file(path, |kebab_name, ct| {
9+
let decls = emit::run_state(false, |s| {
10+
rtypes::emit_toplevel(s, &kebab_name, ct);
11+
host::emit_toplevel(s, &kebab_name, ct);
12+
});
13+
util::emit_decls(decls).into()
14+
})
15+
}

0 commit comments

Comments
 (0)