-
Notifications
You must be signed in to change notification settings - Fork 141
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,3 @@ optional = true | |
52810 = ["nrf52810-hal"] | ||
52832 = ["nrf52832-hal"] | ||
52840 = ["nrf52840-hal"] | ||
default = ["52832"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,3 @@ optional = true | |
[features] | ||
52832 = ["nrf52832-hal"] | ||
52840 = ["nrf52840-hal"] | ||
default = ["52832"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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