#wasm-bytecode #wasm-binary #interpreter #bytecode #wasm-interpreter #binary-format #serde

不使用std parity-wasm-cp

WebAssembly二进制格式序列化/反序列化/解释器

7个版本

使用旧的Rust 2015

0.1.6 2018年10月18日
0.1.5 2018年10月18日

#1091 in WebAssembly

MIT/Apache

235KB
6.5K SLoC

parity-wasm

低级WebAssembly格式库。

Build Status crates.io link

文档

Rust WebAssembly格式序列化/反序列化

添加到Cargo.toml

[dependencies]
parity-wasm = "0.31"

然后


extern crate parity_wasm;

let module = parity_wasm::deserialize_file("./res/cases/v1/hello.wasm").unwrap();
assert!(module.code_section().is_some());

let code_section = module.code_section().unwrap(); // Part of the module with functions code

println!("Function count in wasm file: {}", code_section.bodies().len());

Wabt测试套件

parity-wasm支持完整的wabt测试套件(https://github.com/WebAssembly/testsuite),运行涉及反序列化的断言。

运行测试套件

  • 确保您已安装所有构建wabt的先决条件(因为parity-wasm使用wabt-rs内部构建它,请参阅https://github.com/WebAssembly/wabt
  • 检出子模块(git submodule update --init --recursive
  • 运行cargo test --release --manifest-path=spec/Cargo.toml

解码器可以使用cargo-fuzzwasm-opthttps://github.com/WebAssembly/binaryen)进行模糊测试

  • 确保您已安装所有构建binaryencargo-fuzzcmake和C++11工具链)的先决条件
  • 检出子模块(git submodule update --init --recursive
  • 使用cargo fuzz子命令安装cargo install cargo-fuzz
  • 将rustup设置为使用nightly工具链,因为cargo fuzz使用一个rust编译器插件:rustup override set nightly
  • 运行cargo fuzz run deserialize

no_std crates

这个包有一个默认启用的特性 std。要在 no_std 上下文中使用此包,请在您的 Cargo.toml 中添加以下内容

[dependencies]
parity-wasm = { version = "0.31", default-features = false }

在分配器 API 稳定之前,此类使用仅限于 nightly Rust。

许可证

parity-wasm 主要在 MIT 许可证和 Apache 许可证(版本 2.0)的条款下分发,您可选择。

有关详细信息,请参阅 LICENSE-APACHE 和 LICENSE-MIT。

贡献

除非您明确声明,否则根据 Apache-2.0 许可证定义的,您提交给 parity-wasm 的任何有意贡献均应按照上述方式双许可,不附加任何额外条款或条件。

依赖项