MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / read_wasm_link_metadata

Function read_wasm_link_metadata

xtask/src/main.rs:9522–9665  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

9520}
9521
9522fn read_wasm_link_metadata(path: &Path) -> Result<WasmLinkMetadataOut> {
9523 let bytes = fs::read(path).with_context(|| format!("read {}", path.display()))?;
9524 let mut metadata = WasmLinkMetadataOut {
9525 has_dylink0: false,
9526 dylink_needed: Vec::new(),
9527 dylink_runtime_paths: Vec::new(),
9528 dylink_memory: None,
9529 dylink_imports: Vec::new(),
9530 dylink_exports: Vec::new(),
9531 imports: Vec::new(),
9532 exports: Vec::new(),
9533 memories: Vec::new(),
9534 };
9535
9536 for payload in Parser::new(0).parse_all(&bytes) {
9537 match payload.with_context(|| format!("parse {}", path.display()))? {
9538 Payload::ImportSection(reader) => {
9539 for import in reader.into_imports() {
9540 let import =
9541 import.with_context(|| format!("read import from {}", path.display()))?;
9542 metadata.imports.push(WasmImportOut {
9543 module: import.module.to_owned(),
9544 name: import.name.to_owned(),
9545 kind: type_ref_kind(import.ty).to_owned(),
9546 });
9547 }
9548 }
9549 Payload::ExportSection(reader) => {
9550 for export in reader {
9551 let export =
9552 export.with_context(|| format!("read export from {}", path.display()))?;
9553 metadata.exports.push(WasmExportOut {
9554 name: export.name.to_owned(),
9555 kind: external_kind_name(export.kind).to_owned(),
9556 });
9557 }
9558 }
9559 Payload::MemorySection(reader) => {
9560 for memory in reader {
9561 let memory =
9562 memory.with_context(|| format!("read memory from {}", path.display()))?;
9563 metadata.memories.push(wasm_memory_out(memory));
9564 }
9565 }
9566 Payload::CustomSection(section) if section.name() == "dylink.0" => {
9567 metadata.has_dylink0 = true;
9568 let KnownCustom::Dylink0(reader) = section.as_known() else {
9569 bail!("{} contains an unreadable dylink.0 section", path.display());
9570 };
9571 for subsection in reader {
9572 match subsection
9573 .with_context(|| format!("read dylink.0 from {}", path.display()))?
9574 {
9575 Dylink0Subsection::MemInfo(info) => {
9576 metadata.dylink_memory = Some(WasmDylinkMemoryOut {
9577 memory_size: info.memory_size,
9578 memory_alignment: info.memory_alignment,
9579 table_size: info.table_size,

Callers 4

write_manifestMethod · 0.85
wasix_export_list_textFunction · 0.85
write_asset_manifestFunction · 0.85

Calls 5

type_ref_kindFunction · 0.85
external_kind_nameFunction · 0.85
wasm_memory_outFunction · 0.85
pushMethod · 0.80
nameMethod · 0.45

Tested by

no test coverage detected