bytecodealliance / bytecodealliance/cargo-component

Does not link `env` module when compiling libs with `[no_std]`

Open
#333 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
593
Forks
68
PR merge metrics
No merged PRs in 30d

Description

`cargo component build` fails to compile Rust libraries with `[no_std]` flags because it cannot resolve the `env` import interface:

```
error: failed to decode world from module

Caused by:
0: module was not valid
1: module requires an import interface named `env`
```

Minimum reproducible example:

`src/lib.rs` (it uses an allocator from the `lol_alloc` crate)
```
#![no_std]

extern crate alloc;
extern crate lol_alloc;

#[allow(warnings)]
mod bindings;

#[global_allocator]
static ALLOCATOR : lol_alloc::FailAllocator = lol_alloc::FailAllocator;

#[panic_handler]
fn panic(_i : &core::panic::PanicInfo) -> ! {
core::arch::wasm32::unreachable()
}

use bindings::Guest;
use alloc::string::{String, ToString};

struct Component;

impl Guest for Component {
/// Say hello!
fn hello_world() -> String {
"Hello, World!".to_string()
}
}

bindings::export!(Component with_types_in bindings);
```

`wit/world.wit`
```
package component:nostd;

/// An example world for the component to target.
world example {
export hello-world: func() -> string;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.