7个版本
使用旧的Rust 2015
0.1.6 | 2018年10月18日 |
---|---|
0.1.5 | 2018年10月18日 |
#1091 in WebAssembly
235KB
6.5K SLoC
parity-wasm
低级WebAssembly格式库。
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-fuzz
和wasm-opt
(https://github.com/WebAssembly/binaryen)进行模糊测试
- 确保您已安装所有构建
binaryen
和cargo-fuzz
(cmake
和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 的任何有意贡献均应按照上述方式双许可,不附加任何额外条款或条件。