Skip to content

Commit 86f8422

Browse files
committed
tests: Test no profiler-runtime injected for rlib
This test fails in this commit, but passes with the fix in the next commit.
1 parent a0e5aea commit 86f8422

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//! Tests that for `--crate-type rlib`` there is no profiler runtime injected. This
2+
//! is needed for
3+
//! ```sh
4+
//! RUSTFLAGS="-Cinstrument-coverage" cargo build -Zbuild-std=std,profiler_builtins
5+
//! ```
6+
//! to work. See <https://github.com/rust-lang/rust/pull/133300>.
7+
8+
use run_make_support::rustc;
9+
10+
fn main() {
11+
let stderr = rustc()
12+
.env("RUSTC_LOG", "rustc_metadata::creader=info")
13+
.input("test.rs")
14+
.opt()
15+
.arg("-Cinstrument-coverage")
16+
.arg("--crate-type=rlib")
17+
.run()
18+
.stderr_utf8();
19+
20+
let mut names: Vec<&str> = vec![];
21+
let mut in_resolved_crates = false;
22+
for line in stderr.lines() {
23+
if !in_resolved_crates {
24+
in_resolved_crates = line.starts_with(" INFO rustc_metadata::creader resolved crates:");
25+
} else {
26+
if line.starts_with(" name: ") {
27+
names.push(line.strip_prefix(" name: ").unwrap());
28+
} else if !line.starts_with(" ") {
29+
break;
30+
}
31+
}
32+
}
33+
34+
// Make sure we see "core" and "std" so we know parsing works at all.
35+
assert!(names.contains(&"core"));
36+
assert!(names.contains(&"std"));
37+
38+
// Now make sure "profiler_builtins" has not been injected since we built an rlib.
39+
assert!(!names.contains(&"profiler_builtins"));
40+
}
41+
42+
/* Example stderr that we parse follows. Generated by
43+
https://github.com/rust-lang/rust/blob/b4cfcd9a8f82c689/compiler/rustc_metadata/src/creader.rs#L133
44+
45+
INFO rustc_metadata::creader resolved crates:
46+
name: std
47+
cnum: 1
48+
hash: df6056d905861dad8c1fb84eaadfee3d
49+
reqd: Explicit
50+
rlib: .../stable-x86_64-unknown-linux-gnu/lib/libstd-22be60875a4ac8d7.rlib
51+
name: core
52+
cnum: 2
53+
hash: d2a9b639158d9bf64905c675d97640f2
54+
reqd: Explicit
55+
rlib: .../stable-x86_64-unknown-linux-gnu/lib/libcore-46b25da62cc69443.rlib
56+
name: compiler_builtins
57+
cnum: 3
58+
hash: 7130505301859f8a39afc97a37b8d758
59+
reqd: Explicit
60+
rlib: .../stable-x86_64-unknown-linux-gnu/lib/libcompiler_builtins-c71612932829263c.rlib
61+
62+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn test() {}

0 commit comments

Comments
 (0)