From 408b54d2863299d709c1e7072a69217beb15ce9f Mon Sep 17 00:00:00 2001 From: wasm-forge <122647775+wasm-forge@users.noreply.github.com> Date: Fri, 1 Nov 2024 17:23:45 +0100 Subject: [PATCH] improve README --- README.md | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5e9ba23..9459abd 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,34 @@ wasi2ic 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 to your project. +To include the polyfill implementation in your Canister project, add the ic-wasi-polyfill dependency in it: +```bash +cargo add ic-wasi-polyfill +``` + +Also you will need to add the initialization call to the polyfill library, basic example using memory manager: + +```rust +use ic_stable_structures::{memory_manager::MemoryManager, DefaultMemoryImpl}; +use std::cell::RefCell; + +thread_local! { + // The memory manager enables multiple virtual memories in one. + static MEMORY_MANAGER: RefCell> = + 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 information, check out our [examples repository](https://github.com/wasm-forge/examples). +For more detailed information, see our [examples repository](https://github.com/wasm-forge/examples). ## Related repositories @@ -41,4 +66,4 @@ For more information, check out our [examples repository](https://github.com/was | --------------------------------------------- | ----------------------------- | | [ic-wasi-polyfill](https://github.com/wasm-forge/ic-wasi-polyfill) | Polyfill library implementing the low-level WASI calls. | | [stable-fs](https://github.com/wasm-forge/stable-fs) | Simple file system implementation based on the stable structures. The file system implements backend for the ic-wasi-polyfill | -| [examples](https://github.com/wasm-forge/examples) | Repository containing various examplpes of runnig WASI projects on the IC. | +| [examples](https://github.com/wasm-forge/examples) | Repository containing various examplpes of running WASI projects on the IC. |