rust-lang / wg-cargo-std-aware

Repo for working on "std aware cargo"
133 stars 8 forks source link

Support code-coverage #63

Open catenacyber opened 3 years ago

catenacyber commented 3 years ago

Reported first in https://github.com/rust-lang/rust/issues/79401

I tried this code:

git clone https://github.com/OISF/suricata.git
cd suricata
export RUSTFLAGS="-Zinstrument-coverage"
sh autogen.sh
./configure --disable-shared --enable-fuzztargets --disable-gccmarch-native --enable-debug-validation
cd rust
cargo build --release -Z build-std

I expected to see this happen: Compilation succeeds

Instead, this happened: Compilation failed with

Updating crates.io index
   Compiling core v0.0.0 (/Users/catena/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core)
error[E0152]: found duplicate lang item `f32`
   --> /Users/catena/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/num/f32.rs:319:1
    |
319 | / impl f32 {
320 | |     /// The radix or base of the internal representation of `f32`.
321 | |     #[stable(feature = "assoc_int_consts", since = "1.43.0")]
322 | |     pub const RADIX: u32 = 2;
...   |
937 | |     }
938 | | }
    | |_^
    |
    = note: the lang item is first defined in crate `core`.
    = note: first definition in `core` loaded from /Users/catena/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-e3cd79f6ad1173fd.rlib
    = note: second definition in the local crate (`core`)

and many more errors about other duplicate items

Meta

This is part of https://github.com/rust-lang/rust/issues/34701 cc @richkadel

rustc --version --verbose:

rustc 1.50.0-nightly (603ab5bd6 2020-11-15)
binary: rustc
commit-hash: 603ab5bd6e0ffefafa7411cd8bd23a6ca82bcff0
commit-date: 2020-11-15
host: x86_64-apple-darwin
release: 1.50.0-nightly
Backtrace

``` Updating crates.io index Compiling core v0.0.0 (/Users/catena/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core) error[E0152]: found duplicate lang item `f32` --> /Users/catena/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/num/f32.rs:319:1 | 319 | / impl f32 { 320 | | /// The radix or base of the internal representation of `f32`. 321 | | #[stable(feature = "assoc_int_consts", since = "1.43.0")] 322 | | pub const RADIX: u32 = 2; ... | 937 | | } 938 | | } | |_^ | = note: the lang item is first defined in crate `core`. = note: first definition in `core` loaded from /Users/catena/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-e3cd79f6ad1173fd.rlib = note: second definition in the local crate (`core`) ```

Amanieu commented 3 years ago

I am successfully using -Z build-std and -Z instrument-coverage in my codebase. Can you double-check if this is still an issue in your case?

catenacyber commented 3 years ago

Can you double-check if this is still an issue in your case?

Failed with rustc 1.50.0-nightly (603ab5bd6 2020-11-15) and again after running dustup update and using rustc 1.51.0-nightly (d1aed50ab 2021-01-26)

I use RUSTFLAGS="-Zinstrument-coverage" instead of -Z instrument-coverage cargo build -Z build-std -Z instrument-coveragefails witherror: unknown -Z flag specified: instrument-coverage`

saethlin commented 2 years ago

I can reproduce this problem with the default bin crate.

cargo new --bin scratch
cd scratch
RUSTFLAGS=-Cinstrument-coverage cargo build -Zbuild-std --target=x86_64-unknown-linux-gnu

My rustc is

rustc 1.61.0-nightly (38a0b81b1 2022-03-06)
binary: rustc
commit-hash: 38a0b81b1c32764d6a583a5efb6f306b8c44c503
commit-date: 2022-03-06
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0

@Amanieu I'm very curious to know what you're doing that makes this work.

Amanieu commented 2 years ago

I looked into this: the reason it works for me is that I use -Zno-profiler-runtime and instead use minicov as the profiler runtime.