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 3e95d16
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: cargo +nightly build --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"
18 changes: 14 additions & 4 deletions crates/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
[alias]
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 +32,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 3e95d16

Please sign in to comment.