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

add lib.miri.rs file for miri-test-libstd #586

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Apr 6, 2024

In rust-lang/rust#123317 we added lib.miri.rs files for core, alloc, and std to enable cargo miri test on those crates. Bootstrap has a comment that explains what this is about:

            // This hack helps bootstrap run standard library tests in Miri. The issue is as
            // follows: when running `cargo miri test` on libcore, cargo builds a local copy of core
            // and makes it a dependency of the integration test crate. This copy duplicates all the
            // lang items, so the build fails. (Regular testing avoids this because the sysroot is a
            // literal copy of what `cargo build` produces, but since Miri builds its own sysroot
            // this does not work for us.) So we need to make it so that the locally built libcore
            // contains all the items from `core`, but does not re-define them -- we want to replace
            // the entire crate but a re-export of the sysroot crate. We do this by swapping out the
            // source file: if `MIRI_REPLACE_LIBRS_IF_NOT_TEST` is set and we are building a
            // `lib.rs` file, and a `lib.miri.rs` file exists in the same folder, we build that
            // instead. But crucially we only do that for the library, not the test builds.

compiler_builtins has the same issue -- it defines global symbols via extern "C" fn, and then Miri complains that the same function is defined multiple times and calls to that function elsewhere are ambiguous.

This can be fixed by adding a lib.miri.rs here as well.

Fixes rust-lang/miri-test-libstd#59

@RalfJung
Copy link
Member Author

RalfJung commented Apr 7, 2024

What I am not sure about is whether this file will be picked up by cargo when creating the package for crates.io.

@Amanieu Amanieu merged commit 63976cb into rust-lang:master Apr 10, 2024
22 checks passed
@RalfJung RalfJung deleted the lib.miri.rs branch April 10, 2024 11:03
bors added a commit to rust-lang/miri that referenced this pull request Apr 10, 2024
MIRI_REPLACE_LIBRS_IF_NOT_TEST: also apply to crates.io crates

This is needed to make rust-lang/compiler-builtins#586 work.
@Amanieu
Copy link
Member

Amanieu commented Apr 10, 2024

What I am not sure about is whether this file will be picked up by cargo when creating the package for crates.io.

Yes, it was picked up by Cargo.

@RalfJung
Copy link
Member Author

Awesome, thanks for checking. :)

RalfJung pushed a commit to RalfJung/rust that referenced this pull request Apr 13, 2024
MIRI_REPLACE_LIBRS_IF_NOT_TEST: also apply to crates.io crates

This is needed to make rust-lang/compiler-builtins#586 work.
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.

i686-pc-windows-gnu std tests complain about duplicate symbol
2 participants