| 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 mut add = AddMetadata ::default(); |
| 29 |
//! add.name = AddMetadataField::Set("program".to_owned()); |
| 30 |
//! add.language = vec![("tunalang".to_owned(), "1.0.0".to_owned())]; |
| 31 |
//! add.processed_by = vec![("chashu-tools".to_owned(), "1.0.1".to_owned())]; |
| 32 |
//! add.sdk = vec![]; |
| 33 |
//! add.authors = AddMetadataField::Set(Authors::new("Chashu Cat")); |
| 34 |
//! add.description = AddMetadataField::Set(Description::new("Chashu likes tuna")); |
| 35 |
//! add.licenses = AddMetadataField::Set(Licenses::new("Apache-2.0 WITH LLVM-exception")?); |
| 36 |
//! add.source = AddMetadataField::Set(Source::new("https://github.com/chashu/chashu-tools")?); |
| 37 |
//! add.homepage = AddMetadataField::Set(Homepage::new("https://github.com/chashu/chashu-tools")?); |
| 38 |
//! add.revision = AddMetadataField::Set(Revision::new("de978e17a80c1118f606fce919ba9b7d5a04a5ad")); |
| 39 |
//! add.version = AddMetadataField::Set(Version::new("1.0.0")); |
| 40 |
//! |
| 41 |
//! let wasm = add.to_wasm(&wasm)?; |
| 42 |
//! fs::write("program.wasm", &wasm)?; |
| 43 |
//! # Ok(()) } |
| 44 |
//! ``` |
| 45 |
|
| 46 |
#![cfg_attr(docsrs, feature(doc_auto_cfg))] |
| 47 |
#![warn(missing_debug_implementations, missing_docs)] |
| 48 |
|
| 49 |
pub use add_metadata::{AddMetadata, AddMetadataField}; |
| 50 |
pub use names::{ComponentNames, ModuleNames}; |
| 51 |
pub use producers::{Producers, ProducersField}; |
| 52 |
|
| 53 |
pub(crate) use rewrite::rewrite_wasm; |
| 54 |
|
| 55 |
mod add_metadata; |
| 56 |
#[cfg(feature = "clap")] |
| 57 |
mod clap; |
| 58 |
mod names; |
| 59 |
mod producers; |
| 60 |
mod rewrite; |
| 61 |
|
| 62 |
pub(crate) mod utils; |
| 63 |
|
| 64 |
#[cfg(feature = "oci")] |
| 65 |
mod dependencies; |
| 66 |
#[cfg(feature = "oci")] |
| 67 |
pub use dependencies::Dependencies; |
| 68 |
#[cfg(feature = "oci")] |
| 69 |
mod oci_annotations; |
| 70 |
#[cfg(feature = "oci")] |
| 71 |
pub use oci_annotations::{Authors, Description, Homepage, Licenses, Revision, Source, Version}; |
| 72 |
#[cfg(feature = "oci")] |
| 73 |
mod metadata; |
| 74 |
#[cfg(feature = "oci")] |
| 75 |
pub use metadata::Metadata; |
| 76 |
#[cfg(feature = "oci")] |
| 77 |
mod payload; |
| 78 |
|
| 79 |
#[cfg(feature = "oci")] |
| 80 |
pub use payload::Payload; |
| 81 |
|
| 82 |
#[cfg(feature = "clap")] |
| 83 |
pub use clap::AddMetadataOpts; |