Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build minimal example with no_std #2689

Closed
dignifiedquire opened this issue Oct 2, 2021 · 8 comments
Closed

Unable to build minimal example with no_std #2689

dignifiedquire opened this issue Oct 2, 2021 · 8 comments
Labels

Comments

@dignifiedquire
Copy link

dignifiedquire commented Oct 2, 2021

Describe the Bug

When trying to build a minimal example with no_std unfortnately it does not compile with 0.2.78

Steps to Reproduce

# Cargo.toml
[package]
name = "hello-wasm"
version = "0.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = { version = "0.2.78", default-features = false }
// src/lib.rs
![no_std]

extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;

#[panic_handler]
fn panic(_panic: &core::panic::PanicInfo<'_>) -> ! {
    loop {}
}

#[wasm_bindgen]
extern "C" {
    fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet() {
    alert("Hello world!");
}

Expected Behavior

It compiles.

Actual Behavior

Error log (both 1.57.0 nightly and 1.51.0 produce the same error

 cargo build --target wasm32-unknown-unknown
   Compiling wasm-bindgen v0.2.78
error[E0433]: failed to resolve: use of undeclared crate or module `mem`
   --> /Users/dignifiedquire/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wasm-bindgen-0.2.78/src/convert/slices.rs:232:9
    |
232 |         mem::transmute::<Box<[u8]>, Box<str>>(<Box<[u8]>>::from_abi(js))
    |         ^^^ use of undeclared crate or module `mem`

error[E0433]: failed to resolve: could not find `externref` in the crate root
    --> /Users/dignifiedquire/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wasm-bindgen-0.2.78/src/lib.rs:1482:16
     |
1482 |         crate::externref::link_intrinsics();
     |                ^^^^^^^^^ could not find `externref` in the crate root

error[E0412]: cannot find type `Box` in this scope
   --> /Users/dignifiedquire/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wasm-bindgen-0.2.78/src/convert/slices.rs:103:27
    |
103 |               type Anchor = Box<[$t]>;
    |                             ^^^ not found in this scope
...
128 | / vectors! {
129 | |     u8 i8 u16 i16 u32 i32 u64 i64 usize isize f32 f64
130 | | }
    | |_- in this macro invocation
    |
    = note: this error originates in the macro `vectors` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `Box` in this scope
   --> /Users/dignifiedquire/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wasm-bindgen-0.2.78/src/convert/slices.rs:106:54
    |
106 |               unsafe fn ref_from_abi(js: WasmSlice) -> Box<[$t]> {
    |                                                        ^^^ not found in this scope
@jonboj
Copy link

jonboj commented Oct 2, 2021

Tried to reproduce on Ubuntu 21.04
When building the above with >wasm-pack build --debug --target web
get error
error[E0152]: found duplicate lang item panic_impl
--> src/lib.rs:7:1
|
7 | fn panic(panic: &core::panic::PanicInfo<'>) -> ! {

When the panic function is removed this builds successfully.

@dignifiedquire
Copy link
Author

got the same error when I removed everything in the file, except the no_std line (macos)

@jonboj
Copy link

jonboj commented Oct 2, 2021

Could indicate some misconfiguration in the tool-chain. Maybe start with a minimal working project and then introduce #![no_std]

@dignifiedquire
Copy link
Author

dignifiedquire commented Oct 4, 2021

I have reduced it to the absolute minimum I could:

  • empty lib.rs
  • building with cargo build --target wasm32-unknown-unknown --release
  • with wasm-bindgen: default-features = true, everything builds fine
  • with wasm-bindgen: default-features = false, errors as described above

@jonboj
Copy link

jonboj commented Oct 4, 2021

On Ubuntu 21.04
Have reproduced, the error above, but the error persist even without #![no_std] in lib.rs. So seems triggerede by wasm-bindgen = { version = "0.2.78", default-features = false } in Cargo.toml.

@alexcrichton
Copy link
Contributor

At this time this crate doesn't support no_std. The idea was to add it at some point but it never panned out. I unfortunately just haven't gotten around to removing it yet.

@dignifiedquire
Copy link
Author

I see, thanks

@bhgomes
Copy link

bhgomes commented Feb 28, 2022

@alexcrichton It seems like you would only need to make sure imports come from core and alloc instead of std to support no_std. I can give it a try in a PR if the other maintainers aren't already planning on doing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants