Skip to content

Commit 6391543

Browse files
authored
Fix running cargo test in workspace root (#427)
Allow running `cargo test` / `cargo build` in the workspace root by scoping `embassy-executor` features to builds for `arm` targets. Move the workflow-specific command line params into the workspace Cargo.toml (`warnings = "deny"`) so running `cargo clippy` on a workstation will produce the same results as CI.
1 parent 80a9846 commit 6391543

34 files changed

Lines changed: 112 additions & 65 deletions

File tree

.github/workflows/check.yml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111
# intentionally no target specifier; see https://github.com/jonhoo/rust-ci-conf/pull/4
112112
# --feature-powerset runs for every combination of features
113113
- name: cargo hack
114-
run: cargo hack --feature-powerset --mutually-exclusive-features=log,defmt clippy --locked --target ${{ matrix.target }} -- -Dwarnings
114+
run: cargo hack --feature-powerset --mutually-exclusive-features=log,defmt clippy --locked --target ${{ matrix.target }}
115115

116116
deny:
117117
# cargo-deny checks licenses, advisories, sources, and bans for
@@ -138,21 +138,9 @@ jobs:
138138

139139
test:
140140
runs-on: ubuntu-latest
141-
name: ubuntu / stable / test / ${{ matrix.crate }}
141+
name: ubuntu / stable / test
142142
strategy:
143143
fail-fast: false
144-
matrix:
145-
crate:
146-
- battery-service
147-
- cfu-service
148-
- embedded-services
149-
- espi-service
150-
- hid-service
151-
- platform-service
152-
- power-button-service
153-
- power-policy-service
154-
- storage_bus
155-
- type-c-service
156144
steps:
157145
- uses: actions/checkout@v4
158146
with:
@@ -165,11 +153,11 @@ jobs:
165153
with:
166154
name: updated-lock-files
167155
- name: cargo test
168-
run: cargo test --locked -p ${{ matrix.crate }}
156+
run: cargo test --locked
169157
# After ensuring tests pass, finally ensure the test code itself contains no clippy warnings
170158
- name: cargo clippy
171159
run: |
172-
cargo clippy --locked --tests -p ${{ matrix.crate }} -- -Dwarnings
160+
cargo clippy --locked --tests
173161
174162
msrv:
175163
# check that we can build using the minimal rust version that is specified by this crate
@@ -223,7 +211,7 @@ jobs:
223211
- name: cargo clippy
224212
working-directory: ${{ matrix.example_directory }}
225213
run: |
226-
cargo clippy --target thumbv8m.main-none-eabihf --locked -- -Dwarnings
214+
cargo clippy --target thumbv8m.main-none-eabihf --locked
227215
228216
check-std-examples:
229217
runs-on: ubuntu-latest
@@ -248,4 +236,4 @@ jobs:
248236
- name: cargo clippy
249237
working-directory: ${{ matrix.example_directory }}
250238
run: |
251-
cargo clippy --locked -- -Dwarnings
239+
cargo clippy --locked

Cargo.lock

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ edition = "2024"
2222
license = "MIT"
2323
repository = "https://github.com/OpenDevicePartnership/embedded-services"
2424

25+
[workspace.lints.rust]
26+
warnings = "deny"
27+
2528
[workspace.dependencies]
2629
aligned = "0.4"
2730
anyhow = "1.0"

battery-service/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ repository = "https://github.com/OpenDevicePartnership/embedded-services"
77
rust-version = "1.85"
88
license = "MIT"
99

10+
[lints]
11+
workspace = true
12+
1013
[dependencies]
1114
defmt = { workspace = true, optional = true }
1215
embassy-executor.workspace = true

cfu-service/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ version = "0.1.0"
44
edition = "2024"
55
license = "MIT"
66

7+
[lints]
8+
workspace = true
9+
710
[dependencies]
811
defmt = { workspace = true, optional = true }
912
embassy-executor.workspace = true

embedded-service/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ description = "Embedded Service Layer for IPC, Feature Customization and Extensi
77
repository = "https://github.com/OpenDevicePartnership/embedded-services"
88
rust-version = "1.85"
99

10+
[lints]
11+
workspace = true
12+
1013
[dependencies]
1114
bitfield.workspace = true
1215
bitflags.workspace = true
@@ -46,10 +49,6 @@ critical-section = { workspace = true, features = ["std"] }
4649
tokio = { workspace = true, features = ["rt", "macros", "time"] }
4750
embassy-time = { workspace = true, features = ["std"] }
4851
embassy-time-driver = { workspace = true }
49-
embassy-executor = { workspace = true, features = [
50-
"arch-std",
51-
"executor-thread",
52-
] }
5352
embassy-futures.workspace = true
5453
static_cell.workspace = true
5554

embedded-service/src/comms.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,31 @@ impl<'a> Data<'a> {
117117

118118
/// Fetch type ID for message contents to allow reception of multiple top level elements
119119
/// Ex:
120-
/// match message.data.type_id() {
121-
/// TypeId::of::<MessageClassA>() -> (),
122-
/// TypeId::of::<MessageClassB>() -> (), etc.
120+
/// ```
121+
/// # use core::any::TypeId;
122+
/// # use embedded_services::comms::{Data, Message, EndpointID, Internal};
123+
/// struct MessageClassA;
124+
/// struct MessageClassB;
125+
/// let message = Message {
126+
/// from: EndpointID::from(Internal::PlatformInfo),
127+
/// to: EndpointID::from(Internal::PlatformInfo),
128+
/// data: Data::new(&MessageClassA),
129+
/// };
130+
/// if message.data.type_id() == TypeId::of::<MessageClassA>() {
131+
/// // do something
132+
/// } else if message.data.type_id() == TypeId::of::<MessageClassB>() {
133+
/// // do something else
134+
/// } else {
135+
/// // do something else
123136
/// }
137+
/// ```
124138
pub fn type_id(&self) -> TypeId {
125139
self.contents.type_id()
126140
}
127141

128142
/// Shorthand if only a few Message types are supported by an Endpoint:
129-
/// if data.is_a::<MessageClassA>() {}
130-
/// else if data.is_a::<MessageClassB>() {}
143+
/// if `data.is_a::<MessageClassA>() {}`
144+
/// else if `data.is_a::<MessageClassB>() {}`
131145
/// etc.
132146
pub fn is_a<T: Any>(&self) -> bool {
133147
self.type_id() == TypeId::of::<T>()

embedded-service/src/critical_section_cell.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ impl<T> CriticalSectionCell<T> {
1818
/// for read/write conditions but does not automatically handle logical data
1919
/// race conditions. It is still possible for a user to read a value but have
2020
/// it change after they've performed the read. This just ensures data integrity:
21-
/// CriticalSectionCell<T> will always contain a valid T, even if it's been read "late"
21+
/// `CriticalSectionCell<T>` will always contain a valid `T`, even if it's been read "late"
2222
pub fn set(&self, value: T) {
2323
critical_section::with(|_cs| self.inner.set(value))
2424
}
2525

26-
/// Swap contents between two CriticalSectionCell's
26+
/// Swap contents between two CriticalSectionCell's
2727
/// # Panics
2828
///
2929
/// This function will panic if `self` and `other` are different `Cell`s that partially overlap.
@@ -33,7 +33,7 @@ impl<T> CriticalSectionCell<T> {
3333
critical_section::with(|_cs| self.inner.swap(&other.inner));
3434
}
3535

36-
/// consume the CriticalSectionCell and return the inner value T
36+
/// consume the `CriticalSectionCell` and return the inner value `T`
3737
pub fn into_inner(self) -> T {
3838
self.inner.into_inner()
3939
}
@@ -58,13 +58,13 @@ impl<T: ?Sized> CriticalSectionCell<T> {
5858
}
5959

6060
impl<T: Default> CriticalSectionCell<T> {
61-
/// consume the inner T, returning its value and replacing it with default()
61+
/// consume the inner `T`, returning its value and replacing it with `Default::default()`
6262
pub fn take(&self) -> T {
6363
critical_section::with(|_cs| self.inner.take())
6464
}
6565
}
6666

67-
// SAFETY: Sync is implemented here for CriticalSectionCell as T is only accessed via nestable critical sections
67+
// SAFETY: Sync is implemented here for `CriticalSectionCell` as `T` is only accessed via nestable critical sections
6868
unsafe impl<T> Sync for CriticalSectionCell<T> {}
6969

7070
// SAFETY: Can implement send here due to critical section without T being explicitly Send
@@ -78,7 +78,7 @@ impl<T: Copy> Clone for CriticalSectionCell<T> {
7878
}
7979

8080
impl<T: Default> Default for CriticalSectionCell<T> {
81-
/// Creates a `Cell<T>`, with the `Default` value for T.
81+
/// Creates a `Cell<T>`, with the `Default` value for `T`.
8282
#[inline]
8383
fn default() -> CriticalSectionCell<T> {
8484
CriticalSectionCell::new(Default::default())

embedded-service/src/hid/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! HID sevices
2-
//! See spec at http://msdn.microsoft.com/en-us/library/windows/hardware/hh852380.aspx
2+
//! See spec at <http://msdn.microsoft.com/en-us/library/windows/hardware/hh852380.aspx>
33
use core::convert::Infallible;
44

55
use embassy_sync::once_lock::OnceLock;

embedded-service/src/intrusive_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub enum Error {
1212
NodeAlreadyInList,
1313
}
1414

15-
/// override Result type for shorthand -> Result<T>
15+
/// override Result type for shorthand `-> Result<T>`
1616
pub type Result<T> = core::result::Result<T, Error>;
1717

1818
/// Embedded node that "intrudes" on a structure

0 commit comments

Comments
 (0)