Stream: git-wasmtime

Topic: wasmtime / issue #11716 Hard to compile `wasmtime` (compo...


view this post on Zulip Wasmtime GitHub notifications bot (Sep 19 2025 at 12:43):

rinthnoid opened issue #11716:

Hi contributors,
I made some plugins using WASM's component model in rust using cargo component build command and voila it worked perfectly for windows for me.

But the problem arises when I tried to compile it for android from same program same os (windows) it was hell of a nightmare to be able embed the wasmtime into a rust library and It took plain 3 days to still to figure out that it is somehow not possible for android right now (at least for now) so it just wasted a 3 days and nights :expressionless:.

I got something like this in error when compiling for android -

.
.
.
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `linux_raw_sys`
   --> D:\Programs\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rustix-1.1.2\src\thread\prctl.rs:257:16
    |
257 |     IPCOwner = linux_raw_sys::general::CAP_IPC_OWNER,
    |                ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `linux_raw_sys`
    |
    = help: if you wanted to use a crate named `linux_raw_sys`, use `cargo add linux_raw_sys` to add it to your `Cargo.toml`

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `linux_raw_sys`
   --> D:\Programs\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rustix-1.1.2\src\thread\prctl.rs:259:20
    |
259 |     SystemModule = linux_raw_sys::general::CAP_SYS_MODULE,
    |                    ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `linux_raw_sys`
    |
    = help: if you wanted to use a crate named `linux_raw_sys`, use `cargo add linux_raw_sys` to add it to your `Cargo.toml`

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `linux_raw_sys`
   --> D:\Programs\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rustix-1.1.2\src\thread\prctl.rs:262:19
    |
262 |     SystemRawIO = linux_raw_sys::general::CAP_SYS_RAWIO,
    |                   ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `linux_raw_sys`
    |
    = help: if you wanted to use a crate named `linux_raw_sys`, use `cargo add linux_raw_sys` to add it to your `Cargo.toml`
.
.
.
.

I also made an easy reproducible example

// src/main.rs
use anyhow::Result;
use wasmtime::{Config, Engine, Store, StoreContextMut};
use wasmtime::component::{Component, Linker, ResourceTable};
use wasmtime_wasi::{p2,WasiCtx, WasiCtxView, WasiView};
use reqwest::{blocking::Client,};

wasmtime::component::bindgen!({
    inline: r#"
    package component:adder;
    world example {
        import log: func(s: string);
        import fetch-http: func(url: string) -> string;
        export hello-world: func(name: string) -> string;
        export get-json: func(url: string) -> string;
    }
    "#,
});

/// Per-store host state required by wasmtime-wasi.
struct Host {
    wasi: WasiCtx,
    table: ResourceTable,
}

impl WasiView for Host {
    fn ctx(&mut self) -> WasiCtxView<'_> {
        WasiCtxView {
            ctx: &mut self.wasi,
            table: &mut self.table,
        }
    }
}

fn build_host_state() -> Host {
    // Configure the WasiCtx (inherit host stdio so guest prints appear in host console).
    let mut builder = WasiCtx::builder();
    builder.inherit_stdio();
    Host {
        wasi: builder.build(),
        table: ResourceTable::new(),
    }
}

fn main() -> Result<()> {
    // Engine configured for the component model (synchronous mode).
    let mut config = Config::new();
    config.wasm_component_model(true);
    config.async_support(false);
    let engine = Engine::new(&config)?;

    // Load the component compiled from your component crate.
    let component = Component::from_file(&engine, "./adder.wasm")?;

    // Linker for host imports; parameterized by our Host state.
    let mut linker: Linker<Host> = Linker::new(&engine);

    // Register WASI Preview-2 implementations into the linker (sync API).
    p2::add_to_linker_sync(&mut linker)?;

    // Provide the implementation for the `log` function that the component imports.
    linker.root().func_wrap("log", |mut _cx: StoreContextMut<'_, Host>, (s,): (String,)| {
        println!("Guest says: {}", s);
        Ok(())
    })?;

    // Provide a simple implementation for the `fetch-http` function that the component imports.
    linker.root().func_wrap("fetch-http", |mut _cx: StoreContextMut<'_, Host>, (url,): (String,)| {
        println!("Fetching URL: {}", url);
        let json_response = match Client::new().get(&url).send() {
            Ok(resp) => match resp.text() {
                Ok(body) => body,
                Err(e) => format!("error reading response body: {}", e),
            },
            Err(e) => format!("request error: {}", e),
        };
        Ok((json_response,))
    })?;

    // Create the store (holds our Host state) and instantiate the component.
    let host_state = build_host_state();
    let mut store = Store::new(&engine, host_state);
    let instance = Example::instantiate(&mut store, &component, &linker)?;

    // Call the exported function and print the string.
    let s = instance.call_hello_world(&mut store, "Nezha")?;
    println!("WASM said: {}", s);

    let json = instance.call_get_json(&mut store, "https://jsonplaceholder.typicode.com/todos/2")?;
    println!("Fetched JSON: {}", json);

    Ok(())
}

and then use this command - [for emulator but same for other arch like arm64 etc]
cargo build -v --target x86_64-linux-android

I also tried these things -

So these are things I tried (took lot of time to research cause there are less and less article and explanation) and failed miserably. And the whole ideas was to create a fast cross platform (specially the mobile devices) plugins for my app cause that will literally change the world for plugin dev if it work on almost all platform without any these errors.

Expected Results

If I am doing something wrong then please make this thread for the specially for ref material for future programmers so that they can also develop android library embedded with wasmtime runtime. And try to sprinkle as much as info about this so that if you are facing some problems then any android developer can extend this feature for wasmtime.

Cause right now wasmtime is the only library which support component model fully not other library come near to it. So it will help a lot this new emerging community if people use this then they will likely raise more issue and people contribute more.

Actual Results

Errors as state above

Versions and Environment

Wasmtime version or commit: v36.0.2

Operating system: Windows 11

Architecture: -

Extra Info

building for android targets

Thanks you so much for making this awesome support of component model and the feature rich wasm runtime it is really a great deal for me.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 19 2025 at 12:43):

rinthnoid added the bug label to Issue #11716.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 19 2025 at 15:15):

alexcrichton closed issue #11716:

Hi contributors,
I made some plugins using WASM's component model in rust using cargo component build command and voila it worked perfectly for windows for me.

But the problem arises when I tried to compile it for android from same program same os (windows) it was hell of a nightmare to be able embed the wasmtime into a rust library and It took plain 3 days to still to figure out that it is somehow not possible for android right now (at least for now) so it just wasted a 3 days and nights :expressionless:.

I got something like this in error when compiling for android -

.
.
.
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `linux_raw_sys`
   --> D:\Programs\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rustix-1.1.2\src\thread\prctl.rs:257:16
    |
257 |     IPCOwner = linux_raw_sys::general::CAP_IPC_OWNER,
    |                ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `linux_raw_sys`
    |
    = help: if you wanted to use a crate named `linux_raw_sys`, use `cargo add linux_raw_sys` to add it to your `Cargo.toml`

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `linux_raw_sys`
   --> D:\Programs\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rustix-1.1.2\src\thread\prctl.rs:259:20
    |
259 |     SystemModule = linux_raw_sys::general::CAP_SYS_MODULE,
    |                    ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `linux_raw_sys`
    |
    = help: if you wanted to use a crate named `linux_raw_sys`, use `cargo add linux_raw_sys` to add it to your `Cargo.toml`

error[E0433]: failed to resolve: use of unresolved module or unlinked crate `linux_raw_sys`
   --> D:\Programs\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\rustix-1.1.2\src\thread\prctl.rs:262:19
    |
262 |     SystemRawIO = linux_raw_sys::general::CAP_SYS_RAWIO,
    |                   ^^^^^^^^^^^^^ use of unresolved module or unlinked crate `linux_raw_sys`
    |
    = help: if you wanted to use a crate named `linux_raw_sys`, use `cargo add linux_raw_sys` to add it to your `Cargo.toml`
.
.
.
.

I also made an easy reproducible example

// src/main.rs
use anyhow::Result;
use wasmtime::{Config, Engine, Store, StoreContextMut};
use wasmtime::component::{Component, Linker, ResourceTable};
use wasmtime_wasi::{p2,WasiCtx, WasiCtxView, WasiView};
use reqwest::{blocking::Client,};

wasmtime::component::bindgen!({
    inline: r#"
    package component:adder;
    world example {
        import log: func(s: string);
        import fetch-http: func(url: string) -> string;
        export hello-world: func(name: string) -> string;
        export get-json: func(url: string) -> string;
    }
    "#,
});

/// Per-store host state required by wasmtime-wasi.
struct Host {
    wasi: WasiCtx,
    table: ResourceTable,
}

impl WasiView for Host {
    fn ctx(&mut self) -> WasiCtxView<'_> {
        WasiCtxView {
            ctx: &mut self.wasi,
            table: &mut self.table,
        }
    }
}

fn build_host_state() -> Host {
    // Configure the WasiCtx (inherit host stdio so guest prints appear in host console).
    let mut builder = WasiCtx::builder();
    builder.inherit_stdio();
    Host {
        wasi: builder.build(),
        table: ResourceTable::new(),
    }
}

fn main() -> Result<()> {
    // Engine configured for the component model (synchronous mode).
    let mut config = Config::new();
    config.wasm_component_model(true);
    config.async_support(false);
    let engine = Engine::new(&config)?;

    // Load the component compiled from your component crate.
    let component = Component::from_file(&engine, "./adder.wasm")?;

    // Linker for host imports; parameterized by our Host state.
    let mut linker: Linker<Host> = Linker::new(&engine);

    // Register WASI Preview-2 implementations into the linker (sync API).
    p2::add_to_linker_sync(&mut linker)?;

    // Provide the implementation for the `log` function that the component imports.
    linker.root().func_wrap("log", |mut _cx: StoreContextMut<'_, Host>, (s,): (String,)| {
        println!("Guest says: {}", s);
        Ok(())
    })?;

    // Provide a simple implementation for the `fetch-http` function that the component imports.
    linker.root().func_wrap("fetch-http", |mut _cx: StoreContextMut<'_, Host>, (url,): (String,)| {
        println!("Fetching URL: {}", url);
        let json_response = match Client::new().get(&url).send() {
            Ok(resp) => match resp.text() {
                Ok(body) => body,
                Err(e) => format!("error reading response body: {}", e),
            },
            Err(e) => format!("request error: {}", e),
        };
        Ok((json_response,))
    })?;

    // Create the store (holds our Host state) and instantiate the component.
    let host_state = build_host_state();
    let mut store = Store::new(&engine, host_state);
    let instance = Example::instantiate(&mut store, &component, &linker)?;

    // Call the exported function and print the string.
    let s = instance.call_hello_world(&mut store, "Nezha")?;
    println!("WASM said: {}", s);

    let json = instance.call_get_json(&mut store, "https://jsonplaceholder.typicode.com/todos/2")?;
    println!("Fetched JSON: {}", json);

    Ok(())
}

and then use this command - [for emulator but same for other arch like arm64 etc]
cargo build -v --target x86_64-linux-android

I also tried these things -

So these are things I tried (took lot of time to research cause there are less and less article and explanation) and failed miserably. And the whole ideas was to create a fast cross platform (specially the mobile devices) plugins for my app cause that will literally change the world for plugin dev if it work on almost all platform without any these errors.

Expected Results

If I am doing something wrong then please make this thread for the specially for ref material for future programmers so that they can also develop android library embedded with wasmtime runtime. And try to sprinkle as much as info about this so that if you are facing some problems then any android developer can extend this feature for wasmtime.

Cause right now wasmtime is the only library which support component model fully not other library come near to it. So it will help a lot this new emerging community if people use this then they will likely raise more issue and people contribute more.

Actual Results

Errors as state above

Versions and Environment

Wasmtime version or commit: v36.0.2

Operating system: Windows 11

Architecture: -

Extra Info

building for android targets

Thanks you so much for making this awesome support of component model and the feature rich wasm runtime it is really a great deal for me.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 19 2025 at 15:15):

alexcrichton commented on issue #11716:

Thanks for the report, but this is not something we can reasonably fix/handle in Wasmtime. Some possible pointers for you, however, are:

There's unfortunately not really much we can do in this repository here about this. We do not have expertise for Android available to help out. This might be a bug in rustix, but I do not personally have the expertise in that area to say whether it is or not.

Given that this looks like a general toolchain issue, build configuration issue, or an issue in a dependency on a tier 3 platform, I'm going to close this. Wasmtime does not guarantee that it works on Android at this time due to the tier 3 target status (a result of the lack of expertise amongst maintainers on Android). As such we can't guarantee that free support is available for platforms like this.

It's fine to continue discussion here, and if a Wasmtime-related fix is necessary I'm happy to reopen.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 19 2025 at 15:35):

Ludea commented on issue #11716:

Relevant issue: https://github.com/bytecodealliance/rustix/issues/1519

view this post on Zulip Wasmtime GitHub notifications bot (Sep 19 2025 at 15:47):

rinthnoid commented on issue #11716:

Thanks @alexcrichton for citing some info for me as well as future developers I think It will help us lot for this direction and will look forward if I will able to learn something with that .

and Thanks @Ludea for referencing this issue I think it is being followed specially in rustix library finally!! I will follow it there too.:blush::raised_hands:


Last updated: Dec 06 2025 at 06:05 UTC