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

Insert -Zbuild-std when building rust packages #40

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hoodmane
Copy link
Member

@hoodmane hoodmane commented Oct 11, 2024

Otherwise we are linking a copy of the standard library built with some particular version of emscripten selected by the rust compiler that does not match the version we are using. This can lead to ABI mismatch.
rust-lang/rust#131467

cc @messense @davidhewitt perhaps it would be good for maturin to also insert this flag when targeting emscripten.

Otherwise we are linking a copy of the standard library built with some
particular version of emscripten selected by the rust compiler that does not
match the version we are using. This can lead to an ABI mismatch.

See rust-lang/rust#131467
hoodmane added a commit to hoodmane/pyodide that referenced this pull request Oct 11, 2024
This tests the fix for rust-lang/rust#131467 in pyodide/pyodide-build#40.
The problem is that rust cannot correctly read file metadata because the ABI of
fstat64 changed between the version of emscripten that the rust compiler built
the standard library against and our version of the rust compiler.

By passing `-Zbuild-std` we rebuild the rust standard library with the correct
abi. I also added a test that works only if we pass `-Zbuild-std`.
@hoodmane
Copy link
Member Author

@juntyr says:

When building the Rust crates, you could pass --sysroot <PATH> to a prebuilt sysroot. To each crate, it would look again just normal (no build-std anymore).

I'm not sure how to prepare the sysroot itself, but there is a crate https://crates.io/crates/cargo-sysroot that supports building with custom sysroots, so it might be useful to look at.

This would have the advantage of not requiring nightly for this feature, but it has the disadvantage that none of the tooling looks very maintained...

Copy link
Member

@ryanking13 ryanking13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Well this is very tricky problem.

Comment on lines +528 to +530
elif cmd == "cargo":
line.insert(1, "-Zbuild-std")
return line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a test for this (test_pywasmcross.py)

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

Successfully merging this pull request may close these issues.

2 participants