Stream: general

Topic: wasip2 imports not in WIT after --adapt


view this post on Zulip Eurvin (Apr 23 2026 at 15:44):

Hi all, I have a question about wasm-tools: I'm following along in the book "Server-Side WebAssembly" and I'm hitting a wall. I have created a simple "hello-world" with a greet function and built it for the wasm32-wasip1 target. Now I want to use
wasm-tools component new --adapt to convert it into a wasm32-wasp2 binary which outputs a new componentized wasm file. I have followed the instructions in the book, which are the same as in the wasm-tools github readme.md. However, when I inspect the WIT using wasm-tools component wit my-file-component.wasm it has no preview2 imports... I don't know what's doing wrong here. I'm running everything (rust / wasmtime / wasm-tools) on the latest release.

view this post on Zulip Eurvin (Apr 23 2026 at 16:03):

here's the code:

use core::ptr;

#[unsafe(no_mangle)]
pub unsafe fn greet(ptr: i32, len: i32) {
    let hello = b"Hello, ";

    let input_ptr = ptr as *const u8;
    let input_len = len as usize;

    unsafe {
        let output_ptr: *mut u8 = ptr::without_provenance_mut(0);

        for i in 0..hello.len() {
            output_ptr.add(i).write_volatile(hello[i]);
        }
        for i in 0..input_len {
            output_ptr
                .add(hello.len() + i)
                .write_volatile(input_ptr.add(i).read());
        }
    }
}

view this post on Zulip Joel Dice (Apr 23 2026 at 17:03):

The first thing to do when targeting WASIp2 is decide which WIT world you want to target (which might mean creating your own from scratch). For example, if you want to target wasi:cli/command, you would write a Rust binary crate with a fn main() {...} function and use the wasi_snapshot_preview1.command.wasm adapter.

In this case, you seem to want to create a component that exports a custom function called greet, in which case you'll want to write a WIT file that defines a world which exports such a function. Without doing that, wasm-tools component new doesn't know anything about what you're trying to export, so presumably it is dead-code-eliminating everything, producing a component with no imports or exports. I'd recommend following this tutorial and adapting the instructions to your use case.

view this post on Zulip Eurvin (Apr 24 2026 at 06:34):

I've given it a few more tries but it doesn't seem to work. I think what I'm trying to do is no longer supported. I'll complete the component model book afterwards. Thanks for the link!


Last updated: May 03 2026 at 22:13 UTC