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

"unknown file type lib.rmeta" when compiling Emscripten side module #92738

Open
hoodmane opened this issue Jan 10, 2022 · 5 comments
Open

"unknown file type lib.rmeta" when compiling Emscripten side module #92738

hoodmane opened this issue Jan 10, 2022 · 5 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/

Comments

@hoodmane
Copy link
Contributor

hoodmane commented Jan 10, 2022

When compiling an Emscripten side module as follows:

export RUSTFLAGS="-C link-arg=-s -C link-arg=SIDE_MODULE=1 -C relocation-model=pic -C target-feature=+mutable-globals"
cargo +nightly -Z build-std build --target=wasm32-unknown-emscripten

I get the error

wasm-ld: error: unknown file type: lib.rmeta

This error occurs so long as emcc is invoked to link at least one .rlib file. I am using

rustc 1.59.0-nightly (f1ce0e6a0 2022-01-05)

I have tested that the error occurs with both emscripten v3.1.0 and emscripten v2.0.16. I have had success with patching the emscripten linker to run ar -d some_library.rlib lib.rmeta to fix this.

I am compiling lib.rs which looks as follows:

lib.rs
#![no_std]

use core::panic::PanicInfo;

#[no_mangle]
pub extern "C" fn main() -> i32 {
    0	
}

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}

and my Cargo.toml is:

Cargo.toml
[package]
name = "rust_test"
version = "0.1.0"
edition = "2021"

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

[profile.dev]
panic = 'abort'
@hoodmane hoodmane added the C-bug Category: This is a bug. label Jan 10, 2022
@bjorn3
Copy link
Member

bjorn3 commented Jan 11, 2022

The linker should skip lib.rmeta as it isn't an object file. Normally this happens automatically. I don't know why this doesn't happen here.

@bjorn3 bjorn3 added A-linkage Area: linking into static, shared libraries and binaries O-wasm Target: WASM (WebAssembly), http://webassembly.org/ labels Jan 11, 2022
@MolotovCherry
Copy link

Also happens when compiling with MAIN_MODULE=1

@hoodmane
Copy link
Contributor Author

hoodmane commented Apr 9, 2022

@MolotovCherry
Copy link

Thanks for posting the patch! I'll check it out asap

@hoodmane
Copy link
Contributor Author

As an update, the solution to this is to use -sSIDE_MODULE=2. If you also want everything to be exported, you could try -sSIDE_MODULE=2 -sEXPORT_ALL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/
Projects
None yet
Development

No branches or pull requests

3 participants