Skip to content

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

Open
@hoodmane

Description

@hoodmane

Because of the lib.rmeta file, linking rust libraries doesn't work with -Wl,--whole-archive.

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-emscriptenTarget: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL!O-wasmTarget: WASM (WebAssembly), http://webassembly.org/

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions