Skip to content

Commit 8d63ba2

Browse files
committed
Some tests of the current behavior, including the elaborated output when we fail due to repeated static library.
1 parent 0099f6b commit 8d63ba2

40 files changed

+587
-0
lines changed

src/test/ui/dylibs/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
This directory is a collection of tests of how dylibs and rlibs are compiled and loaded.
2+
3+
It is mostly an exploration checkpointing the current state of Rust.
4+
5+
We tend to advise people to try make at least one format available all the way
6+
up: e.g. all rlibs or all dylibs. But it is good to keep track of how we are
7+
handling other combinations.
8+
9+
There are seven auxiliary crates: `a`,`i`,`j`,`m`,`s`,`t`,`z`. Each top-level
10+
test in this directory varies which of the auxiliary crates are compiled to
11+
dylibs and which are compiled to rlibs.
12+
13+
The seven auxiliary form a dependence graph that looks like this (a pair of
14+
diamonds):
15+
16+
```graphviz
17+
z -> s; s -> m; m -> i; i -> a
18+
z -> t; t -> m; m -> j; j -> a
19+
// ~ ~~~~ ~~~~ ~~~~ ~
20+
// | | | | |
21+
// | | | | +- basement
22+
// | | | |
23+
// | | | +- ground
24+
// | | |
25+
// | | +- middle
26+
// | |
27+
// | +- upper
28+
// |
29+
// +- roof
30+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub fn a() -> String {
2+
format!("a_basement_core")
3+
}
4+
5+
pub fn a_addr() -> usize { a as fn() -> String as *const u8 as usize }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![crate_name="a_basement"]
2+
#![crate_type="dylib"]
3+
4+
mod a_basement_core;
5+
pub use a_basement_core::*;
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="rlib"]
3+
4+
// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
5+
// output crate type for this file.
6+
7+
mod a_basement_core;
8+
pub use a_basement_core::*;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub fn i() -> String {
2+
format!("i_ground_core -> ({})", a::a())
3+
}
4+
5+
pub fn i_addr() -> usize { i as fn() -> String as *const u8 as usize }
6+
7+
pub fn a_addr() -> usize { a::a_addr() }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![crate_name="i_ground"]
2+
#![crate_type="dylib"]
3+
4+
pub extern crate a_basement as a;
5+
6+
mod i_ground_core;
7+
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="i_ground"]
2+
#![crate_type="rlib"]
3+
4+
// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
5+
// output crate type for this file.
6+
7+
pub extern crate a_basement as a;
8+
9+
mod i_ground_core;
10+
pub use i_ground_core::*;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub fn j() -> String {
2+
format!("j_ground_core -> ({})", a::a())
3+
}
4+
5+
pub fn j_addr() -> usize { j as fn() -> String as *const u8 as usize }
6+
7+
pub fn a_addr() -> usize { a::a_addr() }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![crate_name="j_ground"]
2+
#![crate_type="dylib"]
3+
4+
pub extern crate a_basement as a;
5+
6+
mod j_ground_core;
7+
pub use j_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="rlib"]
3+
4+
// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
5+
// output crate type for this file.
6+
7+
pub extern crate a_basement as a;
8+
9+
mod j_ground_core;
10+
pub use j_ground_core::*;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub fn m() -> String {
2+
format!("m_middle_core -> ({}), -> ({})", i::i(), j::j())
3+
}
4+
5+
pub fn m_addr() -> usize { m as fn() -> String as *const u8 as usize }
6+
7+
pub fn i_addr() -> usize { i::i_addr() }
8+
9+
pub fn j_addr() -> usize { j::j_addr() }
10+
11+
pub fn i_a_addr() -> usize { i::a_addr() }
12+
13+
pub fn j_a_addr() -> usize { j::a_addr() }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![crate_name="m_middle"]
2+
#![crate_type="dylib"]
3+
4+
pub extern crate i_ground as i;
5+
pub extern crate j_ground as j;
6+
7+
mod m_middle_core;
8+
pub use m_middle_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="rlib"]
3+
4+
// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
5+
// output crate type for this file.
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pub fn s() -> String {
2+
format!("s_upper_core -> ({})", m::m())
3+
}
4+
5+
pub fn s_addr() -> usize { s as fn() -> String as *const u8 as usize }
6+
7+
pub fn m_addr() -> usize { m::m_addr() }
8+
9+
pub fn m_i_addr() -> usize { m::i_addr() }
10+
11+
pub fn m_j_addr() -> usize { m::j_addr() }
12+
13+
pub fn m_i_a_addr() -> usize { m::i_a_addr() }
14+
15+
pub fn m_j_a_addr() -> usize { m::j_a_addr() }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![crate_name="s_upper"]
2+
#![crate_type="dylib"]
3+
4+
pub extern crate m_middle as m;
5+
6+
mod s_upper_core;
7+
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="s_upper"]
2+
#![crate_type="rlib"]
3+
4+
// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
5+
// output crate type for this file.
6+
7+
pub extern crate m_middle as m;
8+
9+
mod s_upper_core;
10+
pub use s_upper_core::*;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pub fn t() -> String {
2+
format!("t_upper_core -> {}", m::m())
3+
}
4+
5+
pub fn t_addr() -> usize { t as fn() -> String as *const u8 as usize }
6+
7+
pub fn m_addr() -> usize { m::m_addr() }
8+
9+
pub fn m_i_addr() -> usize { m::i_addr() }
10+
11+
pub fn m_j_addr() -> usize { m::j_addr() }
12+
13+
pub fn m_i_a_addr() -> usize { m::i_a_addr() }
14+
15+
pub fn m_j_a_addr() -> usize { m::j_a_addr() }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![crate_name="t_upper"]
2+
#![crate_type="dylib"]
3+
4+
pub extern crate m_middle as m;
5+
6+
mod t_upper_core;
7+
pub use t_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="rlib"]
3+
4+
// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
5+
// output crate type for this file.
6+
7+
pub extern crate m_middle as m;
8+
9+
mod t_upper_core;
10+
pub use t_upper_core::*;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
pub fn z() -> String {
2+
format!("z_roof_core -> ({}), -> ({})", s::s(), t::t())
3+
}
4+
5+
pub fn z_addr() -> usize { z as fn() -> String as *const u8 as usize }
6+
7+
pub fn s_addr() -> usize { s::s_addr() }
8+
9+
pub fn t_addr() -> usize { t::t_addr() }
10+
11+
pub fn s_m_addr() -> usize { s::m_addr() }
12+
13+
pub fn t_m_addr() -> usize { t::m_addr() }
14+
15+
pub fn s_m_i_addr() -> usize { s::m_i_addr() }
16+
17+
pub fn s_m_j_addr() -> usize { s::m_j_addr() }
18+
19+
pub fn t_m_i_addr() -> usize { t::m_i_addr() }
20+
21+
pub fn t_m_j_addr() -> usize { t::m_j_addr() }
22+
23+
pub fn s_m_i_a_addr() -> usize { s::m_i_a_addr() }
24+
25+
pub fn s_m_j_a_addr() -> usize { s::m_j_a_addr() }
26+
27+
pub fn t_m_i_a_addr() -> usize { t::m_i_a_addr() }
28+
29+
pub fn t_m_j_a_addr() -> usize { t::m_j_a_addr() }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![crate_name="z_roof"]
2+
#![crate_type="dylib"]
3+
4+
pub extern crate s_upper as s;
5+
pub extern crate t_upper as t;
6+
7+
mod z_roof_core;
8+
pub use z_roof_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="rlib"]
3+
4+
// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
5+
// output crate type for this file.
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-pass
2+
3+
// All the dependencies are dylibs, so we can successfully link them all and run them.
4+
5+
// aux-build: a_basement_dynamic.rs
6+
// aux-build: i_ground_dynamic.rs
7+
// aux-build: j_ground_dynamic.rs
8+
// aux-build: m_middle_dynamic.rs
9+
// aux-build: s_upper_dynamic.rs
10+
// aux-build: t_upper_dynamic.rs
11+
// aux-build: z_roof_dynamic.rs
12+
13+
extern crate z_roof as z;
14+
15+
mod diamonds_core;
16+
17+
fn main() {
18+
diamonds_core::sanity_check();
19+
diamonds_core::check_linked_function_equivalence();
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-pass
2+
3+
// There is no sharing of an rlib via two dylibs, and thus we can link and run
4+
// this program.
5+
6+
// aux-build: a_basement_dynamic.rs
7+
// aux-build: i_ground_dynamic.rs
8+
// aux-build: j_ground_dynamic.rs
9+
// aux-build: m_middle_dynamic.rs
10+
// aux-build: s_upper_rlib.rs
11+
// aux-build: t_upper_rlib.rs
12+
// aux-build: z_roof_rlib.rs
13+
14+
extern crate z_roof as z;
15+
16+
mod diamonds_core;
17+
18+
fn main() {
19+
diamonds_core::sanity_check();
20+
diamonds_core::check_linked_function_equivalence();
21+
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// build-fail
2+
3+
// This fails to compile because the middle static library (m) is included via
4+
// two dylibs: `s_upper` and `t_upper`.
5+
6+
// aux-build: a_basement_dynamic.rs
7+
// aux-build: i_ground_dynamic.rs
8+
// aux-build: j_ground_dynamic.rs
9+
// aux-build: m_middle_rlib.rs
10+
// aux-build: s_upper_dynamic.rs
11+
// aux-build: t_upper_dynamic.rs
12+
13+
extern crate s_upper as s;
14+
extern crate t_upper as t;
15+
16+
fn main() {
17+
s::s(); t::t();
18+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: cannot satisfy dependencies so `m_middle` only shows up once (two static copies from multiple different locations, via [`s_upper`, `t_upper`])
2+
|
3+
= help: having upstream crates all available in one format will likely make this go away
4+
5+
error: aborting due to previous error
6+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-pass
2+
3+
// There is no sharing of an rlib via two dylibs, and thus we can link and run
4+
// this program.
5+
6+
// aux-build: a_basement_dynamic.rs
7+
// aux-build: i_ground_dynamic.rs
8+
// aux-build: j_ground_dynamic.rs
9+
// aux-build: m_middle_rlib.rs
10+
// aux-build: s_upper_rlib.rs
11+
// aux-build: t_upper_rlib.rs
12+
// aux-build: z_roof_rlib.rs
13+
14+
extern crate z_roof as z;
15+
16+
mod diamonds_core;
17+
18+
fn main() {
19+
diamonds_core::sanity_check();
20+
diamonds_core::check_linked_function_equivalence();
21+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// build-fail
2+
3+
// This fails to compile because the static library foundation (a) is
4+
// included via two dylibs: `i_ground` and `j_ground`.
5+
6+
// aux-build: a_basement_rlib.rs
7+
// aux-build: i_ground_dynamic.rs
8+
// aux-build: j_ground_dynamic.rs
9+
10+
extern crate i_ground as i;
11+
extern crate j_ground as j;
12+
13+
fn main() {
14+
i::i(); j::j();
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: cannot satisfy dependencies so `a_basement` only shows up once (two static copies from multiple different locations, via [`i_ground`, `j_ground`])
2+
|
3+
= help: having upstream crates all available in one format will likely make this go away
4+
5+
error: aborting due to previous error
6+

0 commit comments

Comments
 (0)