Crates.io | wasi2ic |
lib.rs | wasi2ic |
version | 0.2.14 |
source | src |
created_at | 2024-07-09 09:53:02.496125 |
updated_at | 2024-11-02 16:33:05.40672 |
description | This tool converts WebAssembly System Interface (WASI) dependent Wasm files to be compatible with the Internet Computer (IC) platform. |
homepage | |
repository | https://github.com/wasm-forge/wasi2ic |
max_upload_size | |
id | 1296872 |
size | 46,487 |
wasi2ic
is a command-line tool that replaces WebAssembly System Interface (WASI) specific function calls with their
corresponding polyfill implementations. This allows you to run Wasm binaries compiled for wasm32-wasi
on the Internet
Computer.
Install wasi2ic
using Cargo:
cargo install wasi2ic
Replace WASI dependencies in a Wasm file using:
wasi2ic <input-wasm-file> <output_wasm_file>
This command reads the input Wasm file, removes WASI dependencies, and reroutes WASI calls to their IC-specific implementations. Note that the polyfill implementation must be present in your Wasm binary.
To include the polyfill implementation in your Canister project, add the ic-wasi-polyfill dependency in it:
cargo add ic-wasi-polyfill
Also you will need to add the initialization call to the polyfill library, basic example featuring user memory manager:
use ic_stable_structures::{memory_manager::MemoryManager, DefaultMemoryImpl};
use std::cell::RefCell;
thread_local! {
static MEMORY_MANAGER: RefCell<MemoryManager<DefaultMemoryImpl>> =
RefCell::new(MemoryManager::init(DefaultMemoryImpl::default()));
}
#[ic_cdk::init]
fn init() {
MEMORY_MANAGER.with(|m| {
let m = m.borrow();
ic_wasi_polyfill::init_with_memory_manager(&[0u8; 32], &[], &m, 200..210);
});
}
For more detailed information, see our examples repository.
Repository | Description |
---|---|
ic-wasi-polyfill | Polyfill library implementing the low-level WASI calls. |
stable-fs | Simple file system implementation based on the stable structures. The file system implements backend for the ic-wasi-polyfill |
examples | Repository containing various examplpes of running WASI projects on the IC. |