Skip to content

Commit a2231a4

Browse files
committed
Variations on the dylibs/diamonds tests inspired by issue 82151.
These tests specifically show the effects of having both rlib and dylib library variants present, as well as what happens when you mix in various settings for `-C prefer-dynamic=...`.
1 parent 172ba70 commit a2231a4

14 files changed

+257
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![crate_name="a_basement"]
2+
#![crate_type="dylib"]
3+
#![crate_type="rlib"]
4+
5+
// no-prefer-dynamic
6+
7+
mod a_basement_core;
8+
pub use a_basement_core::*;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![crate_name="i_ground"]
2+
#![crate_type="dylib"]
3+
#![crate_type="rlib"]
4+
5+
// no-prefer-dynamic
6+
7+
pub extern crate a_basement as a;
8+
9+
mod i_ground_core;
10+
pub use i_ground_core::*;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![crate_name="j_ground"]
2+
#![crate_type="dylib"]
3+
#![crate_type="rlib"]
4+
5+
// no-prefer-dynamic
6+
7+
pub extern crate a_basement as a;
8+
9+
mod j_ground_core;
10+
pub use j_ground_core::*;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![crate_name="m_middle"]
2+
#![crate_type="dylib"]
3+
#![crate_type="rlib"]
4+
5+
// no-prefer-dynamic
6+
7+
pub extern crate i_ground as i;
8+
pub extern crate j_ground as j;
9+
10+
mod m_middle_core;
11+
pub use m_middle_core::*;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![crate_name="s_upper"]
2+
#![crate_type="dylib"]
3+
#![crate_type="rlib"]
4+
5+
// no-prefer-dynamic
6+
7+
pub extern crate m_middle as m;
8+
9+
mod s_upper_core;
10+
pub use s_upper_core::*;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![crate_name="t_upper"]
2+
#![crate_type="dylib"]
3+
#![crate_type="rlib"]
4+
5+
// no-prefer-dynamic
6+
7+
pub extern crate m_middle as m;
8+
9+
mod t_upper_core;
10+
pub use t_upper_core::*;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![crate_name="z_roof"]
2+
#![crate_type="dylib"]
3+
#![crate_type="rlib"]
4+
5+
// no-prefer-dynamic
6+
7+
pub extern crate s_upper as s;
8+
pub extern crate t_upper as t;
9+
10+
mod z_roof_core;
11+
pub use z_roof_core::*;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// run-pass
2+
3+
// no-prefer-dynamic
4+
// compile-flags: -C prefer-dynamic=std -Z prefer-dynamic-std
5+
6+
// aux-build: a_basement_both.rs
7+
8+
pub extern crate a_basement as a;
9+
10+
fn main() {
11+
a::a();
12+
}

src/test/ui/dylibs/diamonds-b.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// build-fail
2+
3+
// The a_basement dependency has been compiled with `-C prefer-dynamic=no`,
4+
// which ends up leading to a duplication of `std` (and all crates underneath
5+
// it) in both the `a_basement` crate and in this crate. Rust does not support
6+
// having duplicate libraries like that, so this compilation will fail.
7+
8+
// aux-build: a_basement_both.rs
9+
10+
pub extern crate a_basement as a;
11+
12+
fn main() {
13+
a::a();
14+
}

src/test/ui/dylibs/diamonds-b.stderr

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
error: cannot satisfy dependencies so `std` only shows up once (previously required dynamic, via [`diamonds_b`], and now also requires static, via [`a_basement`])
2+
|
3+
= help: having upstream crates all available in one format will likely make this go away
4+
5+
error: cannot satisfy dependencies so `core` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
6+
|
7+
= help: having upstream crates all available in one format will likely make this go away
8+
9+
error: cannot satisfy dependencies so `compiler_builtins` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
10+
|
11+
= help: having upstream crates all available in one format will likely make this go away
12+
13+
error: cannot satisfy dependencies so `rustc_std_workspace_core` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
14+
|
15+
= help: having upstream crates all available in one format will likely make this go away
16+
17+
error: cannot satisfy dependencies so `alloc` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
18+
|
19+
= help: having upstream crates all available in one format will likely make this go away
20+
21+
error: cannot satisfy dependencies so `libc` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
22+
|
23+
= help: having upstream crates all available in one format will likely make this go away
24+
25+
error: cannot satisfy dependencies so `unwind` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
26+
|
27+
= help: having upstream crates all available in one format will likely make this go away
28+
29+
error: cannot satisfy dependencies so `cfg_if` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
30+
|
31+
= help: having upstream crates all available in one format will likely make this go away
32+
33+
error: cannot satisfy dependencies so `hashbrown` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
34+
|
35+
= help: having upstream crates all available in one format will likely make this go away
36+
37+
error: cannot satisfy dependencies so `rustc_std_workspace_alloc` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
38+
|
39+
= help: having upstream crates all available in one format will likely make this go away
40+
41+
error: cannot satisfy dependencies so `rustc_demangle` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
42+
|
43+
= help: having upstream crates all available in one format will likely make this go away
44+
45+
error: cannot satisfy dependencies so `std_detect` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
46+
|
47+
= help: having upstream crates all available in one format will likely make this go away
48+
49+
error: cannot satisfy dependencies so `addr2line` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
50+
|
51+
= help: having upstream crates all available in one format will likely make this go away
52+
53+
error: cannot satisfy dependencies so `gimli` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
54+
|
55+
= help: having upstream crates all available in one format will likely make this go away
56+
57+
error: cannot satisfy dependencies so `object` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
58+
|
59+
= help: having upstream crates all available in one format will likely make this go away
60+
61+
error: cannot satisfy dependencies so `miniz_oxide` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
62+
|
63+
= help: having upstream crates all available in one format will likely make this go away
64+
65+
error: cannot satisfy dependencies so `adler` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
66+
|
67+
= help: having upstream crates all available in one format will likely make this go away
68+
69+
error: cannot satisfy dependencies so `panic_unwind` only shows up once (two static copies from multiple different locations, via [`std`, `a_basement`])
70+
|
71+
= help: having upstream crates all available in one format will likely make this go away
72+
73+
error: aborting due to 18 previous errors
74+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run-pass
2+
3+
// Make use of new `-C prefer-dynamic=...` flag so only `z` is linked dynamically.
4+
5+
// no-prefer-dynamic
6+
// compile-flags: -C prefer-dynamic=z_roof -Z prefer-dynamic-subset
7+
8+
// aux-build: a_basement_both.rs
9+
// aux-build: i_ground_both.rs
10+
// aux-build: j_ground_both.rs
11+
// aux-build: m_middle_both.rs
12+
// aux-build: s_upper_both.rs
13+
// aux-build: t_upper_both.rs
14+
// aux-build: z_roof_both.rs
15+
16+
extern crate z_roof as z;
17+
18+
mod diamonds_core;
19+
20+
fn main() {
21+
diamonds_core::sanity_check();
22+
diamonds_core::check_linked_function_equivalence();
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run-pass
2+
3+
// Make use of new `-C prefer-dynamic=...` flag to allow *only* `std` to be linked dynamically.
4+
5+
// no-prefer-dynamic
6+
// compile-flags: -C prefer-dynamic=std -Z prefer-dynamic-std
7+
8+
// aux-build: a_basement_both.rs
9+
// aux-build: i_ground_both.rs
10+
// aux-build: j_ground_both.rs
11+
// aux-build: m_middle_both.rs
12+
// aux-build: s_upper_both.rs
13+
// aux-build: t_upper_both.rs
14+
// aux-build: z_roof_both.rs
15+
16+
extern crate z_roof as z;
17+
18+
mod diamonds_core;
19+
20+
fn main() {
21+
diamonds_core::sanity_check();
22+
diamonds_core::check_linked_function_equivalence();
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-pass
2+
3+
// Make use of new `-C prefer-dynamic=...` flag to allow *only* `std` to be linked dynamically.
4+
5+
// no-prefer-dynamic
6+
// compile-flags: -C prefer-dynamic=std -Z prefer-dynamic-std -la_basement
7+
8+
// aux-build: a_basement_dynamic.rs
9+
10+
extern crate a_basement as a;
11+
12+
fn main() {
13+
a::a();
14+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// run-pass
2+
3+
// Make use of new `-C prefer-dynamic=...` flag to allow *only* `std` to be
4+
// linked dynamically via rustc's injected flags
5+
//
6+
// All the dependencies are dylibs, so we can successfully link them all and run them, *if* we
7+
// provide the right additional flags.
8+
9+
// no-prefer-dynamic
10+
// compile-flags: -C prefer-dynamic=std -Z prefer-dynamic-std -la_basement -li_ground -lj_ground -lm_middle -ls_upper -lt_upper -lz_roof
11+
12+
// aux-build: a_basement_dynamic.rs
13+
// aux-build: i_ground_dynamic.rs
14+
// aux-build: j_ground_dynamic.rs
15+
// aux-build: m_middle_dynamic.rs
16+
// aux-build: s_upper_dynamic.rs
17+
// aux-build: t_upper_dynamic.rs
18+
// aux-build: z_roof_dynamic.rs
19+
20+
extern crate z_roof as z;
21+
22+
mod diamonds_core;
23+
24+
fn main() {
25+
diamonds_core::sanity_check();
26+
diamonds_core::check_linked_function_equivalence();
27+
}

0 commit comments

Comments
 (0)