# Existing WASM to IC

**URL:** <https://forum.dfinity.org/t/existing-wasm-to-ic/15868>\
**Category:** Programs & Applications\
**Created:** [October 13, 2022, 12:54am UTC](https://forum.dfinity.org/t/existing-wasm-to-ic/15868 "2022-10-13T00:54:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![apotheosis](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/apotheosis/32/24516_2.png) [@apotheosis](https://forum.dfinity.org/u/apotheosis)\
**Post date:** [October 13, 2022, 12:54am UTC](https://forum.dfinity.org/t/existing-wasm-to-ic/15868/1 "2022-10-13T00:54:57Z")

</div>

Hey,

I am thinking about a push-to-deploy module for ICME that would allow a user to spin up  
an instance of an already existing WASM application, onto the IC.

What would one need to do, to get this WASM IC ready? What are the specs needed??  
If it has a frontend does it need to work within Asset canister??

Thanks!

@domwoe @lastmjs

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [October 13, 2022, 2:51am UTC](https://forum.dfinity.org/t/existing-wasm-to-ic/15868/2 "2022-10-13T02:51:16Z")

</div>

I think if the Wasm module targets another runtime (for example [WASI](https://wasi.dev/)) you’d need to somehow detect that and patch each system call to the equivalent on the IC.

---

<div class="post-metadata">

**Author:** ![rossberg](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rossberg/32/795_2.png) [@rossberg](https://forum.dfinity.org/u/rossberg)\
**Post date:** [October 13, 2022, 6:09am UTC](https://forum.dfinity.org/t/existing-wasm-to-ic/15868/3 "2022-10-13T06:09:39Z")

</div>

Wasm is just a code format. An application also expects an OS.

First, you’d need to know what environment and possible glue code that Wasm app targets, because that determines what imports it expects to be available.

Then you’d probably need to implement something more or less equivalent to a POSIX emulation layer on the IC. Or at least a sizeable portion thereof, like file system, I/O system, etc., which many applications may expect.

Finally, you’d need to figure out tooling to cram all that into a single Wasm module, since the IC does not yet support on-chain linking. That may be tough before Wasm officially supports multiple memories, which are a prerequisite for being able to merge multiple modules into one in general.

---

<div class="post-metadata">

**Author:** ![apotheosis](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/apotheosis/32/24516_2.png) [@apotheosis](https://forum.dfinity.org/u/apotheosis)\
**Post date:** [October 13, 2022, 6:29am UTC](https://forum.dfinity.org/t/existing-wasm-to-ic/15868/4 "2022-10-13T06:29:04Z")

</div>

But when we are building it with undefined-undefined it should be OS independent??  
I know we can deploy single-wasm because I commonly deploy the ledger canister as wasm locally.

I am looking for specs that make a wasm like that ledger wasm work on the IC normally.

---

<div class="post-metadata">

**Author:** ![apotheosis](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/apotheosis/32/24516_2.png) [@apotheosis](https://forum.dfinity.org/u/apotheosis)\
**Post date:** [October 13, 2022, 6:33am UTC](https://forum.dfinity.org/t/existing-wasm-to-ic/15868/5 "2022-10-13T06:33:25Z")

</div>

Actually I think this clears it up. Thanks!

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [October 13, 2022, 6:55am UTC](https://forum.dfinity.org/t/existing-wasm-to-ic/15868/6 "2022-10-13T06:55:12Z")

</div>

> [@apotheosis](#):
>
> But when we are building it with undefined-undefined it should be OS independent??

Do you mean `wasm32-unknown-unknown`?

If so, you can still produce a Wasm module that will panic at runtime if certain things are called because they aren’t available. See: [any limitation in using rust to develop ic? · Issue #123 · dfinity/cdk-rs · GitHub](https://github.com/dfinity/cdk-rs/issues/123#issuecomment-1042424271)

---

<div class="post-metadata">

**Author:** ![paulyoung](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/paulyoung/32/5251_2.png) [@paulyoung](https://forum.dfinity.org/u/paulyoung)\
**Post date:** [October 13, 2022, 6:55am UTC](https://forum.dfinity.org/t/existing-wasm-to-ic/15868/7 "2022-10-13T06:55:29Z")

</div>

If you’re interested in replacing I/O and filesystem access, you could try:

> **[GitHub - codebase-labs/icfs: Internet Computer File System](https://github.com/codebase-labs/icfs)**
>
> Internet Computer File System. Contribute to codebase-labs/icfs development by creating an account on GitHub.

- `icfs` provides implementations of `std::io::{Read, Write, Seek}` backed by stable memory to enable the use of existing Rust code that requires implementations of these traits.
- `icfs-fatfs` uses `icfs` to leverage the `fatfs` crate in providing a FAT file system.

---

<div class="post-metadata">

**Author:** ![apotheosis](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/apotheosis/32/24516_2.png) [@apotheosis](https://forum.dfinity.org/u/apotheosis)\
**Post date:** [October 13, 2022, 7:07am UTC](https://forum.dfinity.org/t/existing-wasm-to-ic/15868/8 "2022-10-13T07:07:00Z")

</div>

I think the WASM I was looking into will not work because there are more than one working together. Started programming in Rust a bit because the transform function was out faster for the HTTP calls.

Fun to deep dive into how Rust compiles `wasm32-unknown-unknown` with Wasmtime. Anyway! NG on this usecase.
