Skip to content

Use cargo-make to build the packages #55

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

Merged
merged 10 commits into from
Sep 4, 2023
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
46 changes: 27 additions & 19 deletions .github/workflows/firmware.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
name: Firmware CI Checks
name: Firmware Checks

on:
push
push:
branches:
- master
- dev-*
paths-ignore:
- '*.py'
- 'inputmodule-control/**'
pull_request:
branches:
- '*'
paths-ignore:
- '*.py'
- 'inputmodule-control/**'

env:
CARGO_TERM_COLOR: always
Expand All @@ -17,22 +29,22 @@ jobs:
- name: Setup Rust toolchain
run: rustup show

- run: cargo install cargo-make

- run: cargo install flip-link
- run: cargo build -p ledmatrix
- run: cargo build -p b1display
- run: cargo build -p c1minimal
- run: cargo build -p ledmatrix --release
- run: cargo build -p b1display --release
- run: cargo build -p c1minimal --release
- run: cargo make --cwd b1display
Copy link
Contributor Author

Choose a reason for hiding this comment

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

running cargo make and then cargo make build-release in the top level directory will also work, it will essentially run all the tasks you have listed out here, as well as a bunch more that are part of the default dev-test-flow task, but that can be customized; to, for instance, not run any tests. I would also definitely recommend looking through the all the rest of the pre-defined tasks in the link above, it provides a bunch of sane defaults that can be tweaked as necessary to support your use case, including things like building binaries for release, or CI workflows.

In general, the default behavior when run you run cargo make in a workspace root is to go down into each workspace member and run the task that was called.

- run: cargo make --cwd c1minimal
- run: cargo make --cwd ledmatrix build-release
- run: cargo make --cwd b1display build-release
- run: cargo make --cwd c1minimal build-release

- name: Convert to UF2 format
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev
cargo install elf2uf2-rs
elf2uf2-rs target/thumbv6m-none-eabi/release/b1display b1display.uf2
elf2uf2-rs target/thumbv6m-none-eabi/release/c1minimal c1minimal.uf2
elf2uf2-rs target/thumbv6m-none-eabi/release/ledmatrix ledmatrix.uf2
cargo make --cwd b1display uf2
cargo make --cwd c1minimal uf2
cargo make --cwd ledmatrix uf2

- name: Upload UF2 files
uses: actions/upload-artifact@v3
Expand All @@ -47,9 +59,9 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y llvm
llvm-objcopy -O binary target/thumbv6m-none-eabi/release/b1display b1display.bin
llvm-objcopy -O binary target/thumbv6m-none-eabi/release/c1minimal c1minimal.bin
llvm-objcopy -O binary target/thumbv6m-none-eabi/release/ledmatrix ledmatrix.bin
cargo make --cwd b1display bin
cargo make --cwd c1minimal bin
cargo make --cwd ledmatrix bin

- name: Upload bin files
uses: actions/upload-artifact@v3
Expand All @@ -65,8 +77,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Setup Rust toolchain
run: rustup show
Expand All @@ -93,8 +103,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Setup Rust toolchain
run: rustup show
Expand Down
31 changes: 26 additions & 5 deletions .github/workflows/software.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
name: Software CI Checks
name: Software Checks

on:
push:
branches:
- master
- dev-*
paths-ignore:
- 'b1display/**'
- 'c1minimal/**'
- 'fl16-inputmodules/**'
- 'ledmatrix/**'
pull_request:
branches:
- '*'
paths-ignore:
- 'b1display/**'
- 'c1minimal/**'
- 'fl16-inputmodules/**'
- 'ledmatrix/**'

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -43,11 +60,13 @@ jobs:
- name: Setup Rust toolchain
run: rustup show

- run: cargo install cargo-make

- name: Build Linux tool
run: cargo build --release --target x86_64-unknown-linux-gnu -p inputmodule-control
run: cargo make --cwd inputmodule-control build-release

- name: Check if Linux tool can start
run: cargo run --release --target x86_64-unknown-linux-gnu -p inputmodule-control -- --help
run: cargo make --cwd inputmodule-control run -- --help | grep 'RAW HID and VIA commandline'

- name: Upload Linux tool
uses: actions/upload-artifact@v3
Expand All @@ -64,11 +83,13 @@ jobs:
- name: Setup Rust toolchain
run: rustup show

- run: cargo install cargo-make

- name: Build Windows tool
run: cargo build --release --target x86_64-pc-windows-msvc -p inputmodule-control
run: cargo make --cwd inputmodule-control build-release

- name: Check if Windows tool can start
run: cargo run --release --target x86_64-pc-windows-msvc -p inputmodule-control -- --help
run: cargo make --cwd inputmodule-control run -- --help | grep 'RAW HID and VIA commandline'

- name: Upload Windows App
uses: actions/upload-artifact@v3
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/traditional-cargo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Test builds without cargo-make
# Not the recommended path, but should make sure it still works
name: Traditional Cargo Workflow

on:
push:
branches:
- master
- dev-*
paths-ignore:
- '*.py'
pull_request:
branches:
- '*'
paths-ignore:
- '*.py'

env:
CARGO_TERM_COLOR: always
CARGO_NET_GIT_FETCH_WITH_CLI: true

jobs:
firmware:
name: Building
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v3

- name: Setup Rust toolchain
run: rustup show

- run: cargo install flip-link

- run: cargo build -p ledmatrix
- run: cargo build -p b1display
- run: cargo build -p c1minimal

linux-software:
name: Build Linux
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev libasound2-dev

- name: Setup Rust toolchain
run: rustup show

- name: Build tool
run: cargo build --release --target x86_64-unknown-linux-gnu -p inputmodule-control

- name: Check if tool can start
run: cargo run --release --target x86_64-unknown-linux-gnu -p inputmodule-control -- --help | grep 'RAW HID and VIA commandline'

windows-software:
name: Build Windows
runs-on: windows-2022
steps:
- uses: actions/checkout@v3

- name: Setup Rust toolchain
run: rustup show

- run: cargo install cargo-make

- name: Build tool
run: cargo build --release --target x86_64-pc-windows-msvc -p inputmodule-control

- name: Check if tool can start
run: cargo run --release --target x86_64-pc-windows-msvc -p inputmodule-control -- --help | grep 'RAW HID and VIA commandline'

lint-format:
name: Lint and format check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev libasound2-dev

- name: Setup Rust toolchain
run: rustup show

- name: Firmware clippy
run: |
cargo clippy -p b1display -- --deny=warnings
cargo clippy -p c1minimal -- --deny=warnings
cargo clippy -p ledmatrix -- --deny=warnings

- name: Software clippy
run: cargo clippy --target x86_64-unknown-linux-gnu -p inputmodule-control -- -D warnings

- name: All cargo fmt
run: cargo fmt --all -- --check
22 changes: 22 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[env]
TARGET_TRIPLE = "thumbv6m-none-eabi"
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
FEATURES = ""

[tasks.build]
args = [
"build",
"@@remove-empty(BUILD_TYPE)",
"--target",
"${TARGET_TRIPLE}",
"--features",
"${FEATURES}",
]

[tasks.build-release]
clear = true
env.BUILD_TYPE = "--release"
run_task = "build"

[tasks.test]
disabled = true
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,22 @@ Prepare Rust toolchain (once):
```sh
rustup target install thumbv6m-none-eabi
cargo install flip-link
cargo install elf2uf2-rs --locked
```

Build:

```sh
cargo build -p ledmatrix
cargo build -p b1display
cargo build -p c1minimal
cargo make --cwd ledmatrix
cargo make --cwd b1display
cargo make --cwd c1minimal
```

Generate the UF2 update file:

```sh
elf2uf2-rs target/thumbv6m-none-eabi/debug/ledmatrix ledmatrix.uf2
elf2uf2-rs target/thumbv6m-none-eabi/debug/b1display b1dipslay.uf2
elf2uf2-rs target/thumbv6m-none-eabi/debug/c1minimal c1minimal.uf2
cargo make --cwd ledmatrix uf2
cargo make --cwd b1display uf2
cargo make --cwd c1minimal uf2
```

## Building the Application
Expand All @@ -158,8 +157,11 @@ Currently have to specify the build target because it's not possible to specify
Tracking issue: https://github.com/rust-lang/cargo/issues/9406

```
> cargo build --target x86_64-unknown-linux-gnu -p inputmodule-control
> cargo run --target x86_64-unknown-linux-gnu -p inputmodule-control
# Build it
> cargo make --cwd inputmodule-control

# Build and run it, showing the tool version
> cargo make --cwd inputmodule-control run -- --version
```

### Check the firmware version of the device
Expand Down
12 changes: 12 additions & 0 deletions b1display/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extend = "../Makefile.toml"

[tasks.uf2]
command = "elf2uf2-rs"
args = ["../target/thumbv6m-none-eabi/release/b1display", "../target/thumbv6m-none-eabi/release/b1display.uf2"]
dependencies = ["build-release"]
install_crate = "elf2uf2-rs"

[tasks.bin]
command = "llvm-objcopy"
args = ["-Obinary", "../target/thumbv6m-none-eabi/release/b1display", "../target/thumbv6m-none-eabi/release/b1display.bin"]
dependencies = ["build-release"]
12 changes: 12 additions & 0 deletions c1minimal/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extend = "../Makefile.toml"

[tasks.uf2]
command = "elf2uf2-rs"
args = ["../target/thumbv6m-none-eabi/release/c1minimal", "../target/thumbv6m-none-eabi/release/c1minimal.uf2"]
dependencies = ["build-release"]
install_crate = "elf2uf2-rs"

[tasks.bin]
command = "llvm-objcopy"
args = ["-Obinary", "../target/thumbv6m-none-eabi/release/c1minimal", "../target/thumbv6m-none-eabi/release/c1minimal.bin"]
dependencies = ["build-release"]
21 changes: 21 additions & 0 deletions fl16-inputmodules/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extend = "../Makefile.toml"

[tasks.build-all]
run_task = { name = [
"build-ledmatrix",
"build-b1display",
"build-c1minimal",
], parallel = true }


[tasks.build-ledmatrix]
env.FEATURES = "ledmatrix"
run_task = "build"

[tasks.build-b1display]
env.FEATURES = "b1display"
run_task = "build"

[tasks.build-c1minimal]
env.FEATURES = "c1minimal"
run_task = "build"
7 changes: 7 additions & 0 deletions fl16-inputmodules/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#![allow(clippy::needless_range_loop)]
#![no_std]

#[cfg(any(
all(feature = "ledmatrix", feature = "b1display"),
all(feature = "ledmatrix", feature = "c1minimal"),
all(feature = "b1display", feature = "c1minimal"),
))]
compile_error!("Features \"ledmatrix\", \"b1display\", and \"c1minimal\" are mutually exclusive");

#[cfg(feature = "ledmatrix")]
pub mod fl16;
#[cfg(feature = "ledmatrix")]
Expand Down
14 changes: 14 additions & 0 deletions inputmodule-control/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extend = "../Makefile.toml"

# Since it's a tool, build it for the platform we're running on
[env]
TARGET_TRIPLE = "${CARGO_MAKE_RUST_TARGET_TRIPLE}"

[tasks.run]
command = "cargo"
args = [
"run",
"--target",
"${CARGO_MAKE_RUST_TARGET_TRIPLE}",
"${@}",
]
12 changes: 12 additions & 0 deletions ledmatrix/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extend = "../Makefile.toml"

[tasks.uf2]
command = "elf2uf2-rs"
args = ["../target/thumbv6m-none-eabi/release/ledmatrix", "../target/thumbv6m-none-eabi/release/ledmatrix.uf2"]
dependencies = ["build-release"]
install_crate = "elf2uf2-rs"

[tasks.bin]
command = "llvm-objcopy"
args = ["-Obinary", "../target/thumbv6m-none-eabi/release/ledmatrix", "../target/thumbv6m-none-eabi/release/ledmatrix.bin"]
dependencies = ["build-release"]