Skip to content

Commit

Permalink
Add an xtask package to simplify our CI workflow (#22)
Browse files Browse the repository at this point in the history
* Add an option to specify the output directory of the generated project

* Remove the `stack-protector` option

* Add an `xtask` package to simplify our CI workflow

* Update the CI workflow to use `xtask` package and run tests

* Remove extraneous HAL initialization from `async_main`

* Use `stable` release channel for running tests

* Fix a typo in `README.md`
  • Loading branch information
jessebraham authored Oct 25, 2024
1 parent 1d377a9 commit 5f285d1
Show file tree
Hide file tree
Showing 9 changed files with 691 additions and 77 deletions.
59 changes: 16 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,70 +24,43 @@ concurrency:

jobs:
verify:
name: "${{ matrix.chip }} | ${{ matrix.options }}"

name: "Check ${{ matrix.chip }}"
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
chip: [
"esp32",
"esp32c2",
"esp32c3",
"esp32c6",
"esp32h2",
"esp32s2",
"esp32s3",
]
options: [
"",
"-o alloc",
"-o wifi -o alloc",
"-o ble -o alloc",
"-o embassy",
"-o probe-rs",
"-o stack-protector"
]
# Exclude some combinations that are not supported
exclude:
- chip: "esp32h2"
options: "-o wifi -o alloc"
- chip: "esp32s2"
options: "-o ble -o alloc"
chip: [esp32, esp32c2, esp32c3, esp32c6, esp32h2, esp32s2, esp32s3]

steps:
- uses: actions/checkout@v4

# Rust toolchain for Xtensa:
- if: matrix.chip == 'esp32' || matrix.chip == 'esp32s2' || matrix.chip == 'esp32s3'
- if: ${{ contains(fromJson('["esp32", "esp32s2", "esp32s3"]'), matrix.chip) }}
uses: esp-rs/[email protected]
with:
default: true
buildtargets: ${{ matrix.chip }}
ldproxy: false

# Rust toolchain for RISC-V:
- if: matrix.chip != 'esp32' && matrix.chip != 'esp32s2' && matrix.chip != 'esp32s3'
- if: ${{ !contains(fromJson('["esp32", "esp32s2", "esp32s3"]'), matrix.chip) }}
uses: dtolnay/rust-toolchain@stable
with:
target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf
components: clippy,rustfmt,rust-src

# Rust toolchain for RISC-V:
- if: matrix.chip != 'esp32' && matrix.chip != 'esp32s2' && matrix.chip != 'esp32s3' && matrix.options == '-o stack-protector'
uses: dtolnay/rust-toolchain@nightly
with:
target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf
components: clippy,rustfmt,rust-src

- uses: Swatinem/rust-cache@v2

- name: Generate project
run: cargo run --release -- --chip ${{ matrix.chip }} --headless ${{ matrix.options }} test
- name: Generate and check project
run: cd xtask && cargo run -- check ${{ matrix.chip }}

test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable

- name: Build and check the project
working-directory: test
run: |
cargo fmt -- --check
cargo clippy --no-deps -- -Dwarnings
cargo build --release
- name: Run tests
run: cargo test
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@ Template generation tool to create `no_std` applications targeting Espressif's l
## Quickstart

To generate a proect using this template:

1. Install `esp-generate`:

```
cargo install esp-generate --git https://github.com/esp-rs/esp-generate.git
```

2. Generate a project. There are two options:
1. Using TUI:
```
esp-generate --chip esp32 tests
```
Replace the chip and project name accordingly and choose the different options using the TUI.
2. Adding the options to the `esp-generate command:
```
esp-generate --chip esp32 -o wifi -o alloc tests
```
Replace the chip and project name accordingly and choose the different options using the `-o/--option` flag.
For a full list of available options, see [Usage](#usage) section.

1. Using TUI:

```
esp-generate --chip esp32 tests
```
Replace the chip and project name accordingly and choose the different options using the TUI.
2. Adding the options to the `esp-generate` command:
```
esp-generate --chip esp32 -o wifi -o alloc tests
```
Replace the chip and project name accordingly and choose the different options using the `-o/--option` flag.
For a full list of available options, see [Usage](#usage) section.
## Usage
Expand All @@ -52,7 +58,6 @@ Options:
- `ble`: Enables BLE via the `esp-wifi` crate. Requires `alloc`.
- `embassy`: Adds `embassy` framework support.
- `probe-rs`: Enables `defmt` and flashes using `probe-rs` instead of `espflash`.
- `stack-protector`: Enable stack-smash protection (`nightly` only).
- `optional`: Enables the following set of options:
- `wokwi`: Adds support for Wokwi simulation using [VS Code Wokwi extension].
- `dev-container`: Adds support for [VS Code Dev Containers] and [GitHub Codespaces].
Expand Down
29 changes: 18 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ static OPTIONS: &[GeneratorOptionItem] = &[
disables: &[],
chips: &[],
}),
GeneratorOptionItem::Option(GeneratorOption {
name: "stack-protector",
display_name: "Enable stack-smash protection (`nightly` only).",
enables: &[],
disables: &[],
chips: &[],
}),
GeneratorOptionItem::Category(GeneratorOptionCategory {
name: "optional",
display_name: "Options",
Expand Down Expand Up @@ -175,12 +168,25 @@ struct Args {

#[arg(short, long)]
option: Vec<String>,

#[arg(short = 'O', long)]
output_path: Option<PathBuf>,
}

fn main() {
let args = Args::parse();

if env::current_dir().unwrap().join(&args.name).exists() {
let path = &args
.output_path
.clone()
.unwrap_or_else(|| env::current_dir().unwrap());

if !path.is_dir() {
eprintln!("Output path must be a directory");
process::exit(-1);
}

if path.join(&args.name).exists() {
eprintln!("Directory already exists");
process::exit(-1);
}
Expand All @@ -190,6 +196,7 @@ fn main() {

let mut selected = if !args.headless {
let repository = tui::Repository::new(args.chip, OPTIONS, &args.option);

// TUI stuff ahead
let terminal = tui::init_terminal().unwrap();

Expand Down Expand Up @@ -227,7 +234,7 @@ fn main() {
}
}

let dir = PathBuf::from(&args.name);
let dir = path.join(&args.name);
std::fs::create_dir(&dir).unwrap();

for &(file_path, contents) in template_files::TEMPLATE_FILES.iter() {
Expand All @@ -248,14 +255,14 @@ fn main() {
.arg("group_imports=StdExternalCrate")
.arg("--config")
.arg("imports_granularity=Module")
.current_dir(&args.name)
.current_dir(path.join(&args.name))
.output()
.unwrap();

// Run git init
process::Command::new("git")
.arg("init")
.current_dir(&args.name)
.current_dir(path.join(&args.name))
.output()
.unwrap();
}
Expand Down
3 changes: 0 additions & 3 deletions template/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ rustflags = [
# NOTE: May negatively impact performance of produced code
"-C", "force-frame-pointers",
#ENDIF
#IF option("stack-protector")
"-Z", "stack-protector=all",
#ENDIF
]

#REPLACE riscv32imac-unknown-none-elf rust_target
Expand Down
6 changes: 1 addition & 5 deletions template/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
[toolchain]
#IF option("riscv")
#IF option("stack-protector")
channel = "nightly"
#ELSE
#+channel = "stable"
#ENDIF
channel = "stable"
components = ["rust-src"]
#REPLACE riscv32imac-unknown-none-elf rust_target
targets = ["riscv32imac-unknown-none-elf"]
Expand Down
2 changes: 0 additions & 2 deletions template/src/bin/async_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ async fn main(spawner: Spawner) {
info!("Embassy initialized!");

//IF option("wifi") || option("ble")
let peripherals = esp_hal::init(esp_hal::Config::default());

let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1);
let _init = esp_wifi::init(
//IF option("wifi")
Expand Down
Loading

0 comments on commit 5f285d1

Please sign in to comment.