wasm_metadata/
lib.rs

1//! Read and manipulate WebAssembly metadata
2//!
3//! # Examples
4//!
5//! **Read metadata from a Wasm binary**
6//!
7//! ```no_run
8//! # #![allow(unused)]
9//! # fn main() -> Result<(), anyhow::Error> {
10//! use wasm_metadata::Payload;
11//! use std::fs;
12//!
13//! let wasm = fs::read("program.wasm")?;
14//! let metadata = Payload::from_binary(&wasm)?.metadata();
15//! # Ok(()) }
16//! ```
17//!
18//! **Add metadata to a Wasm binary**
19//!
20//! ```no_run
21//! # #![allow(unused)]
22//! # fn main() -> Result<(), anyhow::Error> {
23//! use wasm_metadata::*;
24//! use std::fs;
25//!
26//! let wasm = fs::read("program.wasm")?;
27//!
28//! let metadata = AddMetadata {
29//!     name: Some("program".to_owned()),
30//!     language: vec![("tunalang".to_owned(), "1.0.0".to_owned())],
31//!     processed_by: vec![("chashu-tools".to_owned(), "1.0.1".to_owned())],
32//!     sdk: vec![],
33//!     authors: Some(Authors::new("Chashu Cat")),
34//!     description: Some(Description::new("Chashu likes tuna")),
35//!     licenses: Some(Licenses::new("Apache-2.0 WITH LLVM-exception")?),
36//!     source: Some(Source::new("https://github.com/chashu/chashu-tools")?),
37//!     homepage: Some(Homepage::new("https://github.com/chashu/chashu-tools")?),
38//!     revision: Some(Revision::new("de978e17a80c1118f606fce919ba9b7d5a04a5ad")),
39//!     version: Some(Version::new("1.0.0")),
40//! };
41//!
42//! let wasm = metadata.to_wasm(&wasm)?;
43//! fs::write("program.wasm", &wasm)?;
44//! # Ok(()) }
45//! ```
46
47#![warn(missing_debug_implementations, missing_docs)]
48
49pub use add_metadata::AddMetadata;
50pub use metadata::Metadata;
51pub use names::{ComponentNames, ModuleNames};
52pub use oci_annotations::{Authors, Description, Homepage, Licenses, Revision, Source, Version};
53pub use payload::Payload;
54pub use producers::{Producers, ProducersField};
55
56pub(crate) use rewrite::rewrite_wasm;
57
58mod add_metadata;
59mod metadata;
60mod names;
61mod oci_annotations;
62mod payload;
63mod producers;
64mod rewrite;
65
66pub(crate) mod utils;