Skip to content
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

Use cargo-xtask in CI #207

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[alias]
xtask = "run -p xtask --"

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Tlink.x",
]

[build]
target = "thumbv7em-none-eabihf"
Copy link
Contributor

@Yatekii Yatekii Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this gone? I would assume this is still relevant for development?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of. We now explicitly pass the right target in CI, and I've found this default to be a bit confusing since it doesn't work on nRF51, the nRF52810, and the nRF9160.

Demos can add their own .cargo/config if they want though, that should make development easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I guess it does work on the nRF9160, but it's not usually the target you want to use there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ok, so I guess you suggest just using the build script during development I guess :) I always hit cargo build out of habit =D but the change & its reasoning is fair enough for me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you can still do that if you cd to the demo project you're editing and add a .cargo/config there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care about the demo projects ;) I care about building the HAL if I change something (which hasn't happened in a log time).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The HALs should all build even for x86_64 (at least that's how docs.rs generates documentation for them)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does cortex-m really build for x86 targets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it goes out of its way to ensure that

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
thumbv7em-none-eabihf
thumbv8m.main-none-eabi
- name: Build Crates
run: scripts/build.sh
run: cargo test -p xtask

strategy:
matrix:
Expand Down
18 changes: 2 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
[workspace]
members = [
"xtask",
"nrf52810-hal",
"nrf52832-hal",
"nrf52833-hal",
"nrf52840-hal",
"nrf9160-hal",
"examples/rtic-demo",
"examples/spi-demo",
"examples/twi-ssd1306",
"examples/ecb-demo",
"examples/ccm-demo",
"examples/ppi-demo",
"examples/gpiote-demo",
"examples/wdt-demo",
"examples/lpcomp-demo",
"examples/qdec-demo",
"examples/comp-demo",
"examples/i2s-controller-demo",
"examples/i2s-peripheral-demo",
"examples/pwm-demo",
"examples/twim-demo",
"examples/twis-demo",
"examples/*",
]

[profile.dev]
Expand Down
1 change: 0 additions & 1 deletion examples/rtic-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ optional = true
52810 = ["nrf52810-hal"]
52832 = ["nrf52832-hal"]
52840 = ["nrf52840-hal"]
default = ["52832"]
1 change: 0 additions & 1 deletion examples/twi-ssd1306/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ optional = true
[features]
52832 = ["nrf52832-hal"]
52840 = ["nrf52840-hal"]
default = ["52832"]
92 changes: 0 additions & 92 deletions scripts/build.sh

This file was deleted.

10 changes: 10 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "xtask"
version = "0.0.0"
authors = ["Jonas Schievink <[email protected]>"]
edition = "2018"
publish = false

[[test]]
name = "ci"
harness = false
64 changes: 64 additions & 0 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::process::Command;

pub static HALS: &[(&str, &str)] = &[
("nrf51-hal", "thumbv6m-none-eabi"),
("nrf9160-hal", "thumbv8m.main-none-eabihf"),
("nrf52810-hal", "thumbv7em-none-eabi"),
("nrf52832-hal", "thumbv7em-none-eabihf"),
("nrf52833-hal", "thumbv7em-none-eabihf"),
("nrf52840-hal", "thumbv7em-none-eabihf"),
];

pub static EXAMPLES: &[(&str, &[&str])] = &[
("ccm-demo", &["52810", "52832", "52833", "52840"]),
("comp-demo", &[]),
("ecb-demo", &["51", "52810", "52832", "52833", "52840"]),
("gpiote-demo", &[]),
("i2s-controller-demo", &[]),
("i2s-peripheral-demo", &[]),
("lpcomp-demo", &[]),
("ppi-demo", &["51", "52810", "52832", "52833", "52840"]),
("pwm-demo", &[]),
("qdec-demo", &[]),
("rtic-demo", &["51", "52810", "52832", "52840"]),
("spi-demo", &[]),
("twi-ssd1306", &["52832", "52840"]),
("twim-demo", &[]),
("twis-demo", &[]),
("wdt-demo", &[]),
];

pub fn feature_to_target(feat: &str) -> &str {
match feat {
"51" => "thumbv6m-none-eabi",
"52810" => "thumbv7em-none-eabi",
_ if feat.starts_with("52") => "thumbv7em-none-eabihf",
_ => panic!("unknown Cargo feature `{}`", feat),
}
}

pub fn install_targets() {
let mut targets = HALS
.iter()
.map(|(_, target)| *target)
.chain(
EXAMPLES
.iter()
.flat_map(|(_, features)| features.iter().map(|feat| feature_to_target(feat))),
)
.collect::<Vec<_>>();
targets.sort();
targets.dedup();

let mut cmd = Command::new("rustup");
cmd.args(&["target", "add"]).args(&targets);
let status = cmd
.status()
.map_err(|e| format!("couldn't execute {:?}: {}", cmd, e))
.unwrap();
assert!(
status.success(),
"failed to install targets with rustup: {:?}",
cmd
);
}
76 changes: 76 additions & 0 deletions xtask/tests/ci.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use std::env;
use std::{fs, process::Command};
use xtask::{EXAMPLES, HALS};

fn build_example(example: &str, target: &str, feature: Option<&str>) {
println!("building `{}` for `{}`", example, target);
let mut cargo = Command::new("cargo");
let toml_path = format!("examples/{}/Cargo.toml", example);
cargo.args(&["build", "--target", target, "--manifest-path", &toml_path]);
if let Some(feature) = feature {
cargo.args(&["--features", feature]);
}

let status = cargo
.status()
.map_err(|e| format!("could not execute {:?}: {}", cargo, e))
.unwrap();
assert!(
status.success(),
"command exited with error status: {:?}",
cargo
);
}

fn main() {
xtask::install_targets();

// We execute from the `xtask` dir, so `cd ..` so that we can find `examples` etc.
env::set_current_dir("..").unwrap();

// Build-test every HAL.
for (hal, target) in HALS {
let mut cargo = Command::new("cargo");
let toml_path = format!("{}/Cargo.toml", hal);
let status = cargo
.args(&["build", "--manifest-path", &toml_path, "--target", target])
.status()
.map_err(|e| format!("could not execute {:?}: {}", cargo, e))
.unwrap();
assert!(
status.success(),
"command exited with error status: {:?}",
cargo
);
}

// Build-test every example with each supported feature.
for (example, features) in EXAMPLES {
// Features are exclusive (they select the target chip), so we test each one
// individually.
if features.is_empty() {
// Use a default target.
build_example(example, "thumbv7em-none-eabihf", None);
} else {
for feature in *features {
let target = xtask::feature_to_target(feature);
build_example(example, target, Some(*feature));
}
}
}

// Ensure that no examples get added without an entry in EXAMPLES.
for entry in fs::read_dir("examples").unwrap() {
let entry = entry.unwrap();
let name = entry.file_name();
let name = name.to_str().unwrap();

if EXAMPLES
.iter()
.find(|(example, ..)| *example == name)
.is_none()
{
panic!("example `{}` is missing an entry in xtask `EXAMPLES`", name);
}
}
}