summary refs log tree commit diff
path: root/compiler/rustc_target/src/spec/tests/tests_impl.rs
blob: b2c2b8254d8f05844cc658f937b5101cd01db104 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use super::super::*;

pub(super) fn test_target(target: TargetResult) {
    // Grab the TargetResult struct. If we successfully retrieved
    // a Target, then the test JSON encoding/decoding can run for this
    // Target on this testing platform (i.e., checking the iOS targets
    // only on a Mac test platform).
    if let Ok(original) = target {
        original.check_consistency();
        let as_json = original.to_json();
        let parsed = Target::from_json(as_json).unwrap();
        assert_eq!(original, parsed);
    }
}

impl Target {
    fn check_consistency(&self) {
        // Check that LLD with the given flavor is treated identically to the linker it emulates.
        // If your target really needs to deviate from the rules below, except it and document the
        // reasons.
        assert_eq!(
            self.linker_flavor == LinkerFlavor::Msvc
                || self.linker_flavor == LinkerFlavor::Lld(LldFlavor::Link),
            self.options.lld_flavor == LldFlavor::Link,
        );
        for args in &[
            &self.options.pre_link_args,
            &self.options.late_link_args,
            &self.options.late_link_args_dynamic,
            &self.options.late_link_args_static,
            &self.options.post_link_args,
        ] {
            assert_eq!(
                args.get(&LinkerFlavor::Msvc),
                args.get(&LinkerFlavor::Lld(LldFlavor::Link)),
            );
            if args.contains_key(&LinkerFlavor::Msvc) {
                assert_eq!(self.options.lld_flavor, LldFlavor::Link);
            }
        }
        assert!(
            (self.options.pre_link_objects_fallback.is_empty()
                && self.options.post_link_objects_fallback.is_empty())
                || self.options.crt_objects_fallback.is_some()
        );
    }
}