aboutsummaryrefslogtreecommitdiff
path: root/xtask/tests/ci.rs
blob: 48356e49ede60c13abd6967810873d36feb427cd (plain) (blame)
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
48
49
50
51
52
53
54
55
56
57
use std::process::Command;
use std::{env, str};
use xtask::{check_blobs, install_targets};

static TARGETS: &[&str] = &[
    "thumbv6m-none-eabi",
    "thumbv7m-none-eabi",
    "thumbv7em-none-eabi",
    "thumbv7em-none-eabihf",
    "thumbv8m.base-none-eabi",
    "thumbv8m.main-none-eabi",
    "thumbv8m.main-none-eabihf",
];

fn build(target: &str, features: &[&str]) {
    println!("building for {} {:?}", target, features);
    let mut cargo = Command::new("cargo");
    cargo.args(&["build", "--target", target]);
    for feat in features {
        cargo.args(&["--features", *feat]);
    }

    let status = cargo.status().unwrap();
    assert!(status.success());
}

fn main() {
    // Tests execute in the containing crate's root dir, `cd ..` so that we find `asm` etc.
    env::set_current_dir("..").unwrap();

    install_targets(&mut TARGETS.iter().cloned(), None);

    // Check that the ASM blobs are up-to-date.
    check_blobs();

    let output = Command::new("rustc").arg("-V").output().unwrap();
    let is_nightly = str::from_utf8(&output.stdout).unwrap().contains("nightly");

    // Build `cortex-m` for each supported target.
    for target in TARGETS {
        build(*target, &[]);

        if is_nightly {
            // This may fail when nightly breaks. That's fine, the CI job isn't essential.
            build(*target, &["inline-asm"]);
        }

        if target.starts_with("thumbv7em") {
            // These can target Cortex-M7s, which have an errata workaround.
            build(*target, &["cm7-r0p1"]);

            if is_nightly {
                build(*target, &["inline-asm", "cm7-r0p1"]);
            }
        }
    }
}