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

Support running std tests #7

Closed
RalfJung opened this issue Apr 9, 2022 · 6 comments
Closed

Support running std tests #7

RalfJung opened this issue Apr 9, 2022 · 6 comments

Comments

@RalfJung
Copy link
Member

RalfJung commented Apr 9, 2022

Many std tests will not work (since they use FFIs we don't support), but it could still make sense to run some of the tests in std -- for example, the mpsc tests. However, I can't get that to work. I pushed my WIP branch here, but it fails spectacularly -- the build of libs complains that it cannot find any of the things in core. Looks like some of the magic for the rustc workspace is not quite working out here, and I don't know what or how.

core and alloc are fine as they have no external dependencies, but with std, this seems to all fall apart.

   Compiling unwind v0.0.0 (/home/r/src/rust/miri-test-libstd/library/unwind)
   Compiling compiler_builtins v0.1.72
   Compiling libc v0.2.122
error[E0433]: failed to resolve: could not find `prelude` in `core`

error[E0432]: unresolved import `core::ops`
 --> /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.72/src/float/mod.rs:1:5
  |
1 | use core::ops;
  |     ^^^^^^^^^ no `ops` in the root

error[E0432]: unresolved import `core::ops`
 --> /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.72/src/int/mod.rs:1:5
  |
1 | use core::ops;
  |     ^^^^^^^^^ no `ops` in the root

[...]

error[E0412]: cannot find type `c_void` in the crate root
  --> /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.122/src/unix/mod.rs:49:28
   |
49 | pub type locale_t = *mut ::c_void;
   |                            ^^^^^^ not found in the crate root

error[E0412]: cannot find type `c_void` in the crate root
   --> /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.122/src/unix/mod.rs:151:30
    |
151 |         pub iov_base: *mut ::c_void,
    |                              ^^^^^^ not found in the crate root
@RalfJung
Copy link
Member Author

RalfJung commented Apr 9, 2022

It might be possible to draw inspiration from xargo, which does manage to turn the rust-src library folder into a workspace that can be built with just regular nightly rustc (no x.py).

@bjorn3
Copy link
Member

bjorn3 commented Apr 9, 2022

@RalfJung
Copy link
Member Author

RalfJung commented Aug 4, 2022

Good catch! That gets us a lot further. Now libc fails to build:

error[E0557]: feature has been removed
  --> /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.122/src/lib.rs:29:13
   |
29 |     feature(static_nobundle, native_link_modifiers, native_link_modifiers_bundle)
   |             ^^^^^^^^^^^^^^^ feature has been removed
   |
   = note: subsumed by `#[link(kind = "static", modifiers = "-bundle", ...)]`

I probably need to make it use the rust-src lockfile.

@RalfJung
Copy link
Member Author

RalfJung commented Aug 4, 2022

Hm... still no luck so far

warning: Patch `rustc-std-workspace-std v1.99.0 (/home/r/src/rust/miri-test-libstd/library/rustc-std-workspace-std)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
   Compiling core v0.0.0 (/home/r/src/rust/miri-test-libstd/library/core)
   Compiling compiler_builtins v0.1.73
   Compiling libc v0.2.126
   Compiling getrandom v0.1.14
   Compiling cc v1.0.69
   Compiling ppv-lite86 v0.2.8
   Compiling hashbrown v0.12.3
   Compiling rustc-demangle v0.1.21
   Compiling unwind v0.0.0 (/home/r/src/rust/miri-test-libstd/library/unwind)
   Compiling rustc-std-workspace-core v1.99.0 (/home/r/src/rust/miri-test-libstd/library/rustc-std-workspace-core)
   Compiling cfg-if v0.1.10
   Compiling alloc v0.0.0 (/home/r/src/rust/miri-test-libstd/library/alloc)
   Compiling std_detect v0.1.5 (/home/r/src/rust/miri-test-libstd/library/stdarch/crates/std_detect)
error: duplicate lang item in crate `core` (which `rustc_std_workspace_core` depends on): `sized`.
  |
  = note: the lang item is first defined in crate `core` (which `std_detect` depends on)
  = note: first definition in `core` loaded from /home/r/.cache/miri/HOST/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-f8802f41586624b3.rmeta
  = note: second definition in `core` loaded from /home/r/src/rust/miri-test-libstd/target/miri/x86_64-unknown-linux-gnu/debug/deps/libcore-5a7939b2c5a9d1a2.rmeta

This reminds me a bit of #4.

@RalfJung
Copy link
Member Author

RalfJung commented Aug 4, 2022

After a lot more messing about I actually got something to run! Though I did edit the libstd sources quite a bit and I messed around quite a lot so I will have to figure out which part of that was necessary.

@RalfJung
Copy link
Member Author

RalfJung commented Aug 4, 2022

This works now on CI. :) So far we only run a few tests to ensure the basic setup works; I hope to grow the test set over time.

@RalfJung RalfJung closed this as completed Aug 4, 2022
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

No branches or pull requests

2 participants