Skip to content

[WIP] parameterize -C prefer-dynamic #88101

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

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/test/ui/dylibs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
This directory is a collection of tests of how dylibs and rlibs are compiled and loaded.

It is mostly an exploration checkpointing the current state of Rust.

We tend to advise people to try make at least one format available all the way
up: e.g. all rlibs or all dylibs. But it is good to keep track of how we are
handling other combinations.

There are seven auxiliary crates: `a`,`i`,`j`,`m`,`s`,`t`,`z`. Each top-level
test in this directory varies which of the auxiliary crates are compiled to
dylibs and which are compiled to rlibs.

The seven auxiliary form a dependence graph that looks like this (a pair of
diamonds):

```graphviz
z -> s; s -> m; m -> i; i -> a
z -> t; t -> m; m -> j; j -> a
// ~ ~~~~ ~~~~ ~~~~ ~
// | | | | |
// | | | | +- basement
// | | | |
// | | | +- ground
// | | |
// | | +- middle
// | |
// | +- upper
// |
// +- roof
```
5 changes: 5 additions & 0 deletions src/test/ui/dylibs/auxiliary/a_basement_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub fn a() -> String {
format!("a_basement_core")
}

pub fn a_addr() -> usize { a as fn() -> String as *const u8 as usize }
5 changes: 5 additions & 0 deletions src/test/ui/dylibs/auxiliary/a_basement_dynamic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![crate_name="a_basement"]
#![crate_type="dylib"]

mod a_basement_core;
pub use a_basement_core::*;
8 changes: 8 additions & 0 deletions src/test/ui/dylibs/auxiliary/a_basement_rlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![crate_name="a_basement"]
#![crate_type="rlib"]

// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
// output crate type for this file.

mod a_basement_core;
pub use a_basement_core::*;
7 changes: 7 additions & 0 deletions src/test/ui/dylibs/auxiliary/i_ground_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn i() -> String {
format!("i_ground_core -> ({})", a::a())
}

pub fn i_addr() -> usize { i as fn() -> String as *const u8 as usize }

pub fn a_addr() -> usize { a::a_addr() }
7 changes: 7 additions & 0 deletions src/test/ui/dylibs/auxiliary/i_ground_dynamic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![crate_name="i_ground"]
#![crate_type="dylib"]

pub extern crate a_basement as a;

mod i_ground_core;
pub use i_ground_core::*;
10 changes: 10 additions & 0 deletions src/test/ui/dylibs/auxiliary/i_ground_rlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![crate_name="i_ground"]
#![crate_type="rlib"]

// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
// output crate type for this file.

pub extern crate a_basement as a;

mod i_ground_core;
pub use i_ground_core::*;
7 changes: 7 additions & 0 deletions src/test/ui/dylibs/auxiliary/j_ground_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn j() -> String {
format!("j_ground_core -> ({})", a::a())
}

pub fn j_addr() -> usize { j as fn() -> String as *const u8 as usize }

pub fn a_addr() -> usize { a::a_addr() }
7 changes: 7 additions & 0 deletions src/test/ui/dylibs/auxiliary/j_ground_dynamic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![crate_name="j_ground"]
#![crate_type="dylib"]

pub extern crate a_basement as a;

mod j_ground_core;
pub use j_ground_core::*;
10 changes: 10 additions & 0 deletions src/test/ui/dylibs/auxiliary/j_ground_rlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![crate_name="j_ground"]
#![crate_type="rlib"]

// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
// output crate type for this file.

pub extern crate a_basement as a;

mod j_ground_core;
pub use j_ground_core::*;
13 changes: 13 additions & 0 deletions src/test/ui/dylibs/auxiliary/m_middle_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub fn m() -> String {
format!("m_middle_core -> ({}), -> ({})", i::i(), j::j())
}

pub fn m_addr() -> usize { m as fn() -> String as *const u8 as usize }

pub fn i_addr() -> usize { i::i_addr() }

pub fn j_addr() -> usize { j::j_addr() }

pub fn i_a_addr() -> usize { i::a_addr() }

pub fn j_a_addr() -> usize { j::a_addr() }
8 changes: 8 additions & 0 deletions src/test/ui/dylibs/auxiliary/m_middle_dynamic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![crate_name="m_middle"]
#![crate_type="dylib"]

pub extern crate i_ground as i;
pub extern crate j_ground as j;

mod m_middle_core;
pub use m_middle_core::*;
11 changes: 11 additions & 0 deletions src/test/ui/dylibs/auxiliary/m_middle_rlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![crate_name="m_middle"]
#![crate_type="rlib"]

// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
// output crate type for this file.

pub extern crate i_ground as i;
pub extern crate j_ground as j;

mod m_middle_core;
pub use m_middle_core::*;
15 changes: 15 additions & 0 deletions src/test/ui/dylibs/auxiliary/s_upper_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub fn s() -> String {
format!("s_upper_core -> ({})", m::m())
}

pub fn s_addr() -> usize { s as fn() -> String as *const u8 as usize }

pub fn m_addr() -> usize { m::m_addr() }

pub fn m_i_addr() -> usize { m::i_addr() }

pub fn m_j_addr() -> usize { m::j_addr() }

pub fn m_i_a_addr() -> usize { m::i_a_addr() }

pub fn m_j_a_addr() -> usize { m::j_a_addr() }
7 changes: 7 additions & 0 deletions src/test/ui/dylibs/auxiliary/s_upper_dynamic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![crate_name="s_upper"]
#![crate_type="dylib"]

pub extern crate m_middle as m;

mod s_upper_core;
pub use s_upper_core::*;
10 changes: 10 additions & 0 deletions src/test/ui/dylibs/auxiliary/s_upper_rlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![crate_name="s_upper"]
#![crate_type="rlib"]

// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
// output crate type for this file.

pub extern crate m_middle as m;

mod s_upper_core;
pub use s_upper_core::*;
15 changes: 15 additions & 0 deletions src/test/ui/dylibs/auxiliary/t_upper_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub fn t() -> String {
format!("t_upper_core -> {}", m::m())
}

pub fn t_addr() -> usize { t as fn() -> String as *const u8 as usize }

pub fn m_addr() -> usize { m::m_addr() }

pub fn m_i_addr() -> usize { m::i_addr() }

pub fn m_j_addr() -> usize { m::j_addr() }

pub fn m_i_a_addr() -> usize { m::i_a_addr() }

pub fn m_j_a_addr() -> usize { m::j_a_addr() }
7 changes: 7 additions & 0 deletions src/test/ui/dylibs/auxiliary/t_upper_dynamic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![crate_name="t_upper"]
#![crate_type="dylib"]

pub extern crate m_middle as m;

mod t_upper_core;
pub use t_upper_core::*;
10 changes: 10 additions & 0 deletions src/test/ui/dylibs/auxiliary/t_upper_rlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![crate_name="t_upper"]
#![crate_type="rlib"]

// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
// output crate type for this file.

pub extern crate m_middle as m;

mod t_upper_core;
pub use t_upper_core::*;
29 changes: 29 additions & 0 deletions src/test/ui/dylibs/auxiliary/z_roof_core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub fn z() -> String {
format!("z_roof_core -> ({}), -> ({})", s::s(), t::t())
}

pub fn z_addr() -> usize { z as fn() -> String as *const u8 as usize }

pub fn s_addr() -> usize { s::s_addr() }

pub fn t_addr() -> usize { t::t_addr() }

pub fn s_m_addr() -> usize { s::m_addr() }

pub fn t_m_addr() -> usize { t::m_addr() }

pub fn s_m_i_addr() -> usize { s::m_i_addr() }

pub fn s_m_j_addr() -> usize { s::m_j_addr() }

pub fn t_m_i_addr() -> usize { t::m_i_addr() }

pub fn t_m_j_addr() -> usize { t::m_j_addr() }

pub fn s_m_i_a_addr() -> usize { s::m_i_a_addr() }

pub fn s_m_j_a_addr() -> usize { s::m_j_a_addr() }

pub fn t_m_i_a_addr() -> usize { t::m_i_a_addr() }

pub fn t_m_j_a_addr() -> usize { t::m_j_a_addr() }
8 changes: 8 additions & 0 deletions src/test/ui/dylibs/auxiliary/z_roof_dynamic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![crate_name="z_roof"]
#![crate_type="dylib"]

pub extern crate s_upper as s;
pub extern crate t_upper as t;

mod z_roof_core;
pub use z_roof_core::*;
11 changes: 11 additions & 0 deletions src/test/ui/dylibs/auxiliary/z_roof_rlib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![crate_name="z_roof"]
#![crate_type="rlib"]

// no-prefer-dynamic : flag controls both `-C prefer-dynamic` *and* overrides the
// output crate type for this file.

pub extern crate s_upper as s;
pub extern crate t_upper as t;

mod z_roof_core;
pub use z_roof_core::*;
20 changes: 20 additions & 0 deletions src/test/ui/dylibs/diamonds-ddddddd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// run-pass

// All the dependencies are dylibs, so we can successfully link them all and run them.

// aux-build: a_basement_dynamic.rs
// aux-build: i_ground_dynamic.rs
// aux-build: j_ground_dynamic.rs
// aux-build: m_middle_dynamic.rs
// aux-build: s_upper_dynamic.rs
// aux-build: t_upper_dynamic.rs
// aux-build: z_roof_dynamic.rs

extern crate z_roof as z;

mod diamonds_core;

fn main() {
diamonds_core::sanity_check();
diamonds_core::check_linked_function_equivalence();
}
21 changes: 21 additions & 0 deletions src/test/ui/dylibs/diamonds-ddddrrr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// run-pass

// There is no sharing of an rlib via two dylibs, and thus we can link and run
// this program.

// aux-build: a_basement_dynamic.rs
// aux-build: i_ground_dynamic.rs
// aux-build: j_ground_dynamic.rs
// aux-build: m_middle_dynamic.rs
// aux-build: s_upper_rlib.rs
// aux-build: t_upper_rlib.rs
// aux-build: z_roof_rlib.rs

extern crate z_roof as z;

mod diamonds_core;

fn main() {
diamonds_core::sanity_check();
diamonds_core::check_linked_function_equivalence();
}
18 changes: 18 additions & 0 deletions src/test/ui/dylibs/diamonds-dddrdd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// build-fail

// This fails to compile because the middle static library (m) is included via
// two dylibs: `s_upper` and `t_upper`.

// aux-build: a_basement_dynamic.rs
// aux-build: i_ground_dynamic.rs
// aux-build: j_ground_dynamic.rs
// aux-build: m_middle_rlib.rs
// aux-build: s_upper_dynamic.rs
// aux-build: t_upper_dynamic.rs

extern crate s_upper as s;
extern crate t_upper as t;

fn main() {
s::s(); t::t();
}
6 changes: 6 additions & 0 deletions src/test/ui/dylibs/diamonds-dddrdd.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: cannot satisfy dependencies so `m_middle` only shows up once (two static copies from multiple different locations, via [`s_upper`, `t_upper`])
|
= help: having upstream crates all available in one format will likely make this go away

error: aborting due to previous error

21 changes: 21 additions & 0 deletions src/test/ui/dylibs/diamonds-dddrrrr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// run-pass

// There is no sharing of an rlib via two dylibs, and thus we can link and run
// this program.

// aux-build: a_basement_dynamic.rs
// aux-build: i_ground_dynamic.rs
// aux-build: j_ground_dynamic.rs
// aux-build: m_middle_rlib.rs
// aux-build: s_upper_rlib.rs
// aux-build: t_upper_rlib.rs
// aux-build: z_roof_rlib.rs

extern crate z_roof as z;

mod diamonds_core;

fn main() {
diamonds_core::sanity_check();
diamonds_core::check_linked_function_equivalence();
}
15 changes: 15 additions & 0 deletions src/test/ui/dylibs/diamonds-rdd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// build-fail

// This fails to compile because the static library foundation (a) is
// included via two dylibs: `i_ground` and `j_ground`.

// aux-build: a_basement_rlib.rs
// aux-build: i_ground_dynamic.rs
// aux-build: j_ground_dynamic.rs

extern crate i_ground as i;
extern crate j_ground as j;

fn main() {
i::i(); j::j();
}
6 changes: 6 additions & 0 deletions src/test/ui/dylibs/diamonds-rdd.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: cannot satisfy dependencies so `a_basement` only shows up once (two static copies from multiple different locations, via [`i_ground`, `j_ground`])
|
= help: having upstream crates all available in one format will likely make this go away

error: aborting due to previous error

Loading