Skip to content

Commit 889ebde

Browse files
authored
Add cross configuration (#69)
This allows running unit tests on a non-linux platform via the `cross test` command.
1 parent e7a4397 commit 889ebde

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"rust-analyzer.cargo.features": [
33
"rt",
4-
"stm32h503"
4+
"stm32h503",
5+
"async",
56
],
67
"rust-analyzer.check.allTargets": false,
78
"rust-analyzer.check.targets": "thumbv8m.main-none-eabihf",
8-
}
9+
}

Cross.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Cross doesn't seem to look for package specific configurations when invoked in a workspace so
2+
# we put the default target in Cross.toml
3+
4+
# Allow usage of locally built version of the cross docker image that matches the host architecture
5+
# e.g. Building a linux/arm64 image for an AARCH64 host allows native execution of the image.
6+
# Specifying the toolchain for a linux/arm64 image means the correct toolchain is used on that
7+
# platform (it defaults to x86_64).
8+
[target.aarch64-unknown-linux-gnu.image]
9+
name = "ghcr.io/cross-rs/aarch64-unknown-linux-gnu:main"
10+
toolchain = ["linux/arm64=aarch64-unknown-linux-gnu"]

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ a number of fantastic resources available to help.
7272
- [Rust Embedded FAQ](https://docs.rust-embedded.org/faq.html)
7373
- [rust-embedded/awesome-embedded-rust](https://github.com/rust-embedded/awesome-embedded-rust)
7474

75+
## Running unit tests
76+
77+
If you're on a linux host, you can simply run unit tests with:
78+
79+
cargo test --target x86_64-unknown-linux-gnu --tests --features stm32h503
80+
81+
If you're not, you'll need to install [`cross`](https://github.com/cross-rs/cross), which is a cross compilation tool. See the `cross` instructions for details of installation and use. Once that is installed, using `cross test` will run the unit tests within a docker image.
82+
83+
Running tests with `cross`:
84+
85+
cross test --target x86_64-unknown-linux-gnu --tests --features stm32h503
86+
87+
`cross` will automatically download the relevant docker image and install the correct rust toolchain.
88+
7589
## Changelog
7690

7791
See [CHANGELOG.md](CHANGELOG.md). Note: this will be populated once the first crates have been

0 commit comments

Comments
 (0)