Skip to content

Commit

Permalink
Use an alias to compile for Flipper Zero instead of build.target
Browse files Browse the repository at this point in the history
Hard-coding `python3` in the runner means it doesn't work on Windows
because only `python` is provided. Conversely, Debian / Ubuntu don't
provide `python` by default. So it is more reliable to use `cargo`
itself as the runner. However, doing so means we need to be able to
compile for the host inside the `crates/` subdirectory.

It is currently not possible to revert Cargo config options to their
default, so the only way to compile for both host and Flipper Zero is
to set the target additively. We achieve this by defining an alias
`cargo test-flipper` that developers can use instead.
  • Loading branch information
str4d committed Apr 2, 2023
1 parent 1c316d9 commit 39fa367
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
- name: Rustup
run: rustup +nightly target add thumbv7em-none-eabihf
- name: Build
run: cargo +nightly build --release --verbose
run: cargo +nightly build-flipper --release --verbose
- name: Build examples
run: cargo +nightly build --examples --release --verbose
run: cargo +nightly build-flipper --examples --release --verbose
- name: Run tests
run: |
cargo +nightly test --release --verbose 2>&1 | tee stderr.txt
cargo +nightly test-flipper --release --verbose 2>&1 | tee stderr.txt
- name: Check that tests failed for the expected reason
run: |
cat stderr.txt | grep -q "Error: unable to find Flipper Zero"
20 changes: 16 additions & 4 deletions crates/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
[alias]
check-flipper = "check --target thumbv7em-none-eabihf"
build-flipper = "build --target thumbv7em-none-eabihf"
test-flipper = "test --target thumbv7em-none-eabihf"

[target.thumbv7em-none-eabihf]
runner = "python3 ../cargo-runner.py"
runner = [
"cargo",
"run",
"--manifest-path",
"../../tools/Cargo.toml",
"--quiet",
"--release",
"--bin",
"run-fap",
"--",
]
rustflags = [
# CPU is Cortex-M4 (STM32WB55)
"-C", "target-cpu=cortex-m4",
Expand All @@ -19,6 +34,3 @@ rustflags = [
# Required to link with `lld`
"-Z", "no-unique-section-names=yes",
]

[build]
target = "thumbv7em-none-eabihf"
42 changes: 0 additions & 42 deletions crates/cargo-runner.py

This file was deleted.

12 changes: 12 additions & 0 deletions crates/sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
#![no_std]

// Features that identify thumbv7em-none-eabihf.
// Until target_abi is stable, this also permits thumbv7em-none-eabi.
#[cfg(not(all(
target_arch = "arm",
target_feature = "thumb2",
target_feature = "v7",
target_feature = "dsp",
target_os = "none",
//target_abi = "eabihf",
)))]
core::compile_error!("This crate requires `--target thumbv7em-none-eabihf`");

pub mod furi;
mod inlines;

Expand Down

0 comments on commit 39fa367

Please sign in to comment.