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

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

Open
selassje opened this issue Oct 12, 2023 · 4 comments
Open

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

selassje opened this issue Oct 12, 2023 · 4 comments
Labels
C-bug Category: This is a bug. O-emscripten Target: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL! O-wasm Target: WASM (WebAssembly), http://webassembly.org/ T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@selassje
Copy link

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>

@selassje selassje added the C-bug Category: This is a bug. label Oct 12, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 12, 2023
@kleisauke
Copy link
Contributor

kleisauke commented Oct 28, 2023

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).

@Noratrieb Noratrieb added O-wasm Target: WASM (WebAssembly), http://webassembly.org/ T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 31, 2023
@tari
Copy link
Contributor

tari commented Dec 6, 2023

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.

@lonsbio
Copy link

lonsbio commented Dec 14, 2023

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

@kleisauke
Copy link
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.

@workingjubilee workingjubilee added the O-emscripten Target: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL! label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-emscripten Target: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL! O-wasm Target: WASM (WebAssembly), http://webassembly.org/ T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants