Auto merge of #128361 - Oneirical:testle-deforestation, r=jieyouxu · rust-lang/rust@fd8d6fb (original) (raw)

``

1

`` +

// The #[link(cfg(..))] annotation means that the #[link]

``

``

2

`` +

// directive is only active in a compilation unit if that cfg value is satisfied.

``

``

3

`+

// For example, when compiling an rlib, these directives are just encoded and

`

``

4

`+

// ignored for dylibs, and all staticlibs are continued to be put into the rlib as

`

``

5

`+

// usual. When placing that rlib into a staticlib, executable, or dylib, however,

`

``

6

`` +

// the cfg is evaluated as if it were defined in the final artifact and the

``

``

7

`+

// library is decided to be linked or not.

`

``

8

`+

// This test exercises this new feature by testing it with no dependencies, then

`

``

9

`+

// with only dynamic libraries, then with both a staticlib and dylibs. Compilation

`

``

10

`+

// and execution should be successful.

`

``

11

`+

// See https://github.com/rust-lang/rust/pull/37545

`

``

12

+

``

13

`+

//@ ignore-cross-compile

`

``

14

`+

// Reason: the compiled binary is executed

`

``

15

+

``

16

`+

use run_make_support::{bare_rustc, build_native_dynamic_lib, build_native_static_lib, run, rustc};

`

``

17

+

``

18

`+

fn main() {

`

``

19

`+

build_native_dynamic_lib("return1");

`

``

20

`+

build_native_dynamic_lib("return2");

`

``

21

`+

build_native_static_lib("return3");

`

``

22

`+

bare_rustc()

`

``

23

`+

.print("cfg")

`

``

24

`+

.target("x86_64-unknown-linux-musl")

`

``

25

`+

.run()

`

``

26

`+

.assert_stdout_contains("crt-static");

`

``

27

`+

rustc().input("no-deps.rs").cfg("foo").run();

`

``

28

`+

run("no-deps");

`

``

29

`+

rustc().input("no-deps.rs").cfg("bar").run();

`

``

30

`+

run("no-deps");

`

``

31

+

``

32

`+

rustc().input("dep.rs").run();

`

``

33

`+

rustc().input("with-deps.rs").cfg("foo").run();

`

``

34

`+

run("with-deps");

`

``

35

`+

rustc().input("with-deps.rs").cfg("bar").run();

`

``

36

`+

run("with-deps");

`

``

37

+

``

38

`+

rustc().input("dep-with-staticlib.rs").run();

`

``

39

`+

rustc().input("with-staticlib-deps.rs").cfg("foo").run();

`

``

40

`+

run("with-staticlib-deps");

`

``

41

`+

rustc().input("with-staticlib-deps.rs").cfg("bar").run();

`

``

42

`+

run("with-staticlib-deps");

`

``

43

`+

}

`