Auto merge of #127328 - Oneirical:yield-to-petestrians, r=jieyouxu · rust-lang/rust@d4a6200 (original) (raw)

``

1

`+

// Setting the linker flavor as a C compiler should cause the output of the -l flags to be

`

``

2

`+

// prefixed by -Wl, except when a flag is requested to be verbatim. A bare linker (ld) should

`

``

3

`+

// never cause prefixes to appear in the output. This test checks this ruleset twice, once with

`

``

4

`+

// explicit flags and then with those flags passed inside the rust source code.

`

``

5

`+

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

`

``

6

+

``

7

`+

//@ only-linux

`

``

8

`` +

// Reason: the gnu-cc linker is only available on linux

``

``

9

+

``

10

`+

use run_make_support::{regex, rustc};

`

``

11

+

``

12

`+

fn main() {

`

``

13

`+

let out_gnu = rustc()

`

``

14

`+

.input("empty.rs")

`

``

15

`+

.linker_flavor("gnu-cc")

`

``

16

`+

.arg("-Zunstable-options")

`

``

17

`+

.arg("-lstatic=l1")

`

``

18

`+

.arg("-llink-arg=a1")

`

``

19

`+

.arg("-lstatic=l2")

`

``

20

`+

.arg("-llink-arg=a2")

`

``

21

`+

.arg("-ldylib=d1")

`

``

22

`+

.arg("-llink-arg=a3")

`

``

23

`+

.print("link-args")

`

``

24

`+

.run_unchecked()

`

``

25

`+

.stdout_utf8();

`

``

26

`+

let out_gnu_verbatim = rustc()

`

``

27

`+

.input("empty.rs")

`

``

28

`+

.linker_flavor("gnu-cc")

`

``

29

`+

.arg("-Zunstable-options")

`

``

30

`+

.arg("-lstatic=l1")

`

``

31

`+

.arg("-llink-arg:+verbatim=a1")

`

``

32

`+

.arg("-lstatic=l2")

`

``

33

`+

.arg("-llink-arg=a2")

`

``

34

`+

.arg("-ldylib=d1")

`

``

35

`+

.arg("-llink-arg=a3")

`

``

36

`+

.print("link-args")

`

``

37

`+

.run_unchecked()

`

``

38

`+

.stdout_utf8();

`

``

39

`+

let out_ld = rustc()

`

``

40

`+

.input("empty.rs")

`

``

41

`+

.linker_flavor("ld")

`

``

42

`+

.arg("-Zunstable-options")

`

``

43

`+

.arg("-lstatic=l1")

`

``

44

`+

.arg("-llink-arg=a1")

`

``

45

`+

.arg("-lstatic=l2")

`

``

46

`+

.arg("-llink-arg=a2")

`

``

47

`+

.arg("-ldylib=d1")

`

``

48

`+

.arg("-llink-arg=a3")

`

``

49

`+

.print("link-args")

`

``

50

`+

.run_unchecked()

`

``

51

`+

.stdout_utf8();

`

``

52

`+

let out_att_gnu = rustc()

`

``

53

`+

.arg("-Zunstable-options")

`

``

54

`+

.linker_flavor("gnu-cc")

`

``

55

`+

.input("attribute.rs")

`

``

56

`+

.print("link-args")

`

``

57

`+

.run_unchecked()

`

``

58

`+

.stdout_utf8();

`

``

59

`+

let out_att_gnu_verbatim = rustc()

`

``

60

`+

.cfg(r#"feature="verbatim""#)

`

``

61

`+

.arg("-Zunstable-options")

`

``

62

`+

.linker_flavor("gnu-cc")

`

``

63

`+

.input("attribute.rs")

`

``

64

`+

.print("link-args")

`

``

65

`+

.run_unchecked()

`

``

66

`+

.stdout_utf8();

`

``

67

`+

let out_att_ld = rustc()

`

``

68

`+

.linker_flavor("ld")

`

``

69

`+

.input("attribute.rs")

`

``

70

`+

.print("link-args")

`

``

71

`+

.run_unchecked()

`

``

72

`+

.stdout_utf8();

`

``

73

+

``

74

`+

let no_verbatim = regex::Regex::new("l1.*-Wl,a1.l2.-Wl,a2.d1.-Wl,a3").unwrap();

`

``

75

`+

let one_verbatim = regex::Regex::new(r#"l1.*"a1".l2.-Wl,a2.d1.-Wl,a3"#).unwrap();

`

``

76

`+

let ld = regex::Regex::new(r#"l1.*"a1".l2."a2".d1."a3""#).unwrap();

`

``

77

+

``

78

`+

assert!(no_verbatim.is_match(&out_gnu));

`

``

79

`+

assert!(no_verbatim.is_match(&out_att_gnu));

`

``

80

`+

assert!(one_verbatim.is_match(&out_gnu_verbatim));

`

``

81

`+

assert!(one_verbatim.is_match(&out_att_gnu_verbatim));

`

``

82

`+

assert!(ld.is_match(&out_ld));

`

``

83

`+

assert!(ld.is_match(&out_att_ld));

`

``

84

`+

}

`