greentic_runner/gen_bindings/
component.rs1use anyhow::{Context, Result};
2use wasmparser::{Parser, Payload};
3
4#[derive(Debug, Default, Clone)]
5pub struct ComponentFeatures {
6 pub http: bool,
7 pub secrets: bool,
8 pub filesystem: bool,
9}
10
11pub fn analyze_component(path: &std::path::Path) -> Result<ComponentFeatures> {
12 let wasm = std::fs::read(path)
13 .with_context(|| format!("failed to read component {}", path.display()))?;
14 let mut features = ComponentFeatures::default();
15 for payload in Parser::new(0).parse_all(&wasm) {
16 if let Payload::ImportSection(section) = payload? {
17 for import in section {
18 let import = import?;
19 match import.module {
20 "greentic:host/http-v1" => features.http = true,
21 "greentic:host/secrets-v1" => features.secrets = true,
22 "greentic:host/filesystem-v1" => features.filesystem = true,
23 "greentic:host/kv-v1" => features.filesystem = true,
24 _ => (),
25 }
26 }
27 }
28 }
29 Ok(features)
30}