Skip to content

Rust 1.73 + emscripten 3.1.44 fails if using filesystem api #116655

Open

Description

@selassje

It builds fine with EMSDK 3.1.43.

use std::{fs::File, io::Read};

fn main() {
    let mut file = File::open("Hello world!").unwrap();
    let mut buf = Vec::new();
    file.read_to_end(&mut buf);
}

= note: wasm-ld: error: C:\Users\Przemyslaw.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\wasm32-unknown-emscripten\lib\libstd-330edb0856239641.rlib(std-330edb0856239641.std.fa9f9c7c191d43dc-cgu.0.rcgu.o): undefined symbol: open64
wasm-ld: error: C:\Users\Przemyslaw.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\wasm32-unknown-emscripten\lib\libstd-330edb0856239641.rlib(std-330edb0856239641.std.fa9f9c7c191d43dc-cgu.0.rcgu.o): undefined symbol: fstat64
wasm-ld: error: C:\Users\Przemyslaw.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\wasm32-unknown-emscripten\lib\libstd-330edb0856239641.rlib(std-330edb0856239641.std.fa9f9c7c191d43dc-cgu.0.rcgu.o): undefined symbol: lseek64

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-pc-windows-msvc
release: 1.73.0
LLVM version: 17.0.2
Backtrace

<backtrace>

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 12, 2023
  2. kleisauke commented on Oct 28, 2023

    @kleisauke
    Contributor

    This should be fixed in Emscripten 3.1.46, see: emscripten-core/emscripten#20123. Edit: this PR didn't help for Rust somehow, see comments below.

    Compatibility with Emscripten 3.1.44 and 3.1.45 is addressed in PR rust-lang/libc#3308, which is included in libc 0.2.149. This should be available in (the upcoming) Rust 1.75.0 (see #116527).

  3. added
    O-wasmTarget: WASM (WebAssembly), http://webassembly.org/
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 31, 2023
  4. tari commented on Dec 6, 2023

    @tari
    Contributor

    I don't think newer emscripten fixed this, or if it was fixed it regressed again. I have emscripten 3.1.48 and the reproducer from the original report above still fails to link with the same undefined symbols.

    Building with rustc 1.75 (I tried 1.75.0-beta.5) does work, though.

  5. lonsbio commented on Dec 14, 2023

    @lonsbio

    Just to add that using 1.75.0-beta.5 as advised by @tari was the only way to fix this issue for me

    rustc 1.75.0-beta.5 
    emcc 3.1.50
    
  6. kleisauke commented on Dec 14, 2023

    @kleisauke
    Contributor

    Indeed, I can confirm that it's still broken on the latest stable version of Rust in combination with Emscripten 3.1.44 or higher. I've updated my previous comment.

    Details
    $ curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --target wasm32-unknown-emscripten
    $ source "$HOME/.cargo/env"
    $ rustc --version --verbose
    rustc 1.74.1 (a28077b28 2023-12-04)
    binary: rustc
    commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
    commit-date: 2023-12-04
    host: x86_64-unknown-linux-gnu
    release: 1.74.1
    LLVM version: 17.0.4
    $ emcc -dumpversion
    3.1.51
    $ cat <<EOT > main.rs
    use std::{fs::File, io::Read};
    
    fn main() {
        let mut file = File::open("Hello world!").unwrap();
        let mut buf = Vec::new();
        let _ = file.read_to_end(&mut buf);
    }
    EOT
    $ rustc main.rs --target wasm32-unknown-emscripten
    error: linking with `emcc` failed: exit status: 1
    ...

    This is curious, as the above mentioned Emscripten PR is supposed to fix that, at least for C/C++ programs.

  7. added
    O-emscriptenTarget: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL!
    on Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-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/T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions