Skip to content

CI updates #83

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
Jun 9, 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
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
timezone: Etc/UTC
open-pull-requests-limit: 10
reviewers:
- str4d
assignees:
- str4d
11 changes: 5 additions & 6 deletions .github/workflows/_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ on:

jobs:
build-and-test:
name: Build and test
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3.5.2
- run: sudo apt install libudev-dev
- name: Rustup
run: rustup +nightly target add thumbv7em-none-eabihf
- name: Build
run: cargo +nightly build --release --verbose
run: cargo build --release --verbose
- name: Build examples
run: cargo +nightly build --examples --release --verbose
run: cargo build --examples --release --verbose
- name: Run tests
run: |
cargo +nightly test --release --verbose 2>&1 | tee stderr.txt
cargo test --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"
92 changes: 92 additions & 0 deletions .github/workflows/_lints.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Reusable workflow for lints

on:
workflow_call:
inputs:
target:
required: true
type: string

jobs:
clippy:
name: Clippy (MSRV)
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/[email protected]
- name: Install build dependencies
run: sudo apt install libudev-dev
- name: Run Clippy
uses: auguwu/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ${{ inputs.target }}
all-features: true
# Broken until https://github.com/auguwu/clippy-action/issues/13 is resolved.
# deny: warnings
# Ignored until https://github.com/auguwu/clippy-action/issues/14 is resolved.
args: --all-targets

clippy-beta:
name: Clippy (beta)
runs-on: ubuntu-latest
continue-on-error: true
Comment on lines +33 to +35
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm adding this like I do in other repos I maintain, because it's useful for checking whether there are Clippy lint changes coming down the pipeline that a future MSRV bump may encounter, without the noise of checking lints against nightly.

However, until #58 is closed, this step will silently fail, and the Clippy (MSRV) step will be checking lints against nightly. So this step won't be useful until then, but it also won't get in the way, so we can add it now in preparation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the auguwu/clippy-action action will add source-code annotations when run. Does this mean we'll get duplicate annotations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For actions-rs/clippy-check this wasn't the case with continue-on-error: true AFAIR, but IDK about this action. At least from what I've seen in this PR itself, we weren't getting duplicates.

defaults:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/[email protected]
- name: Install build dependencies
run: sudo apt install libudev-dev
- uses: dtolnay/rust-toolchain@beta
id: toolchain
with:
components: clippy
- run: rustup override set ${{ steps.toolchain.outputs.name }}
- name: Run Clippy (beta)
uses: auguwu/[email protected]
continue-on-error: true
with:
token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ${{ inputs.target }}
all-features: true
# Broken until https://github.com/auguwu/clippy-action/issues/13 is resolved.
# warn: clippy::all
# Ignored until https://github.com/auguwu/clippy-action/issues/14 is resolved.
args: --all-targets

doc-links:
name: Intra-doc links
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/[email protected]
- name: Install build dependencies
run: sudo apt install libudev-dev
# Use nightly Rust (as docs.rs does), because some of our dependencies enable the
# `doc_cfg` feature when the `docsrs` config option is set.
- uses: dtolnay/rust-toolchain@nightly
id: toolchain
with:
targets: thumbv7em-none-eabihf
- run: rustup override set ${{ steps.toolchain.outputs.name }}
- run: cargo fetch
# Requires #![deny(rustdoc::broken_intra_doc_links)] in crates.
- name: Check intra-doc links
run: cargo doc --workspace --document-private-items
env:
RUSTDOCFLAGS: --cfg docsrs

fmt:
name: Rustfmt
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/[email protected]
- run: cargo fmt --all --check
17 changes: 17 additions & 0 deletions .github/workflows/lints.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lints

# We only run these lints on trial-merges of PRs to reduce noise.
on:
pull_request:
branches: ["main"]

jobs:
crates:
uses: ./.github/workflows/_lints.yml
with:
target: crates

tools:
uses: ./.github/workflows/_lints.yml
with:
target: tools
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
crates:
uses: ./.github/workflows/_build_and_test.yml
with:
target: crates
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]
### Added
- `impl Default for flipperzero::dialogs::DialogMessage`
- `impl Default for flipperzero::toolbox::Crc32`

### Changed
- `flipperzero_test::tests` now allows `#[cfg(..)]` attributes on test methods.

Expand Down
1 change: 1 addition & 0 deletions crates/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! *Note:* This currently requires using nightly.

#![no_std]
#![deny(rustdoc::broken_intra_doc_links)]

use core::alloc::{GlobalAlloc, Layout};
use core::ffi::c_void;
Expand Down
6 changes: 6 additions & 0 deletions crates/flipperzero/src/dialogs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ impl<'a> Drop for DialogMessage<'a> {
}
}

impl<'a> Default for DialogMessage<'a> {
fn default() -> Self {
Self::new()
}
}

impl DialogMessageButton {
fn from_sys(sys: sys::DialogMessageButton) -> Option<Self> {
match sys {
Expand Down
3 changes: 2 additions & 1 deletion crates/flipperzero/src/furi/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ impl RngCore for HwRng {
}

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
Ok(self.fill_bytes(dest))
self.fill_bytes(dest);
Ok(())
}
}

Expand Down
33 changes: 13 additions & 20 deletions crates/flipperzero/src/furi/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const WHITESPACE: &[char] = &[
/// allocator. Very short strings (7 bytes or fewer) are stored directly inside the
/// `FuriString` struct (which is stored on the heap), while longer strings are allocated
/// on the heap by the Flipper Zero firmware.
///
/// [`CString`]: alloc::ffi::CString
/// [`String`]: alloc::string::String
#[derive(Eq)]
pub struct FuriString(NonNull<sys::FuriString>);

Expand Down Expand Up @@ -296,11 +299,10 @@ impl FuriString {
///
/// Returns `false` if it does not.
///
/// The [pattern] can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// The pattern can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// [`char`]s.
///
/// [`char`]: prim@char
/// [pattern]: self::pattern
#[inline]
pub fn contains<P: Pattern>(&self, pat: P) -> bool {
pat.is_contained_in(self)
Expand All @@ -310,11 +312,10 @@ impl FuriString {
///
/// Returns `false` if it does not.
///
/// The [pattern] can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// The pattern can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// [`char`]s.
///
/// [`char`]: prim@char
/// [pattern]: self::pattern
pub fn starts_with<P: Pattern>(&self, pat: P) -> bool {
pat.is_prefix_of(self)
}
Expand All @@ -323,11 +324,10 @@ impl FuriString {
///
/// Returns `false` if it does not.
///
/// The [pattern] can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// The pattern can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// [`char`]s.
///
/// [`char`]: prim@char
/// [pattern]: self::pattern
pub fn ends_with<P: Pattern>(&self, pat: P) -> bool {
pat.is_suffix_of(self)
}
Expand All @@ -336,11 +336,10 @@ impl FuriString {
///
/// Returns [`None`] if the pattern doesn't match.
///
/// The [pattern] can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// The pattern can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// [`char`]s.
///
/// [`char`]: prim@char
/// [pattern]: self::pattern
#[inline]
pub fn find<P: Pattern>(&self, pat: P) -> Option<usize> {
pat.find_in(self)
Expand All @@ -351,11 +350,10 @@ impl FuriString {
///
/// Returns [`None`] if the pattern doesn't match.
///
/// The [pattern] can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// The pattern can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// [`char`]s.
///
/// [`char`]: prim@char
/// [pattern]: self::pattern
#[inline]
pub fn rfind<P: Pattern>(&self, pat: P) -> Option<usize> {
pat.rfind_in(self)
Expand Down Expand Up @@ -404,23 +402,21 @@ impl FuriString {

/// Repeatedly removes from this string all prefixes and suffixes that match a pattern.
///
/// The [pattern] can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// The pattern can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// [`char`]s.
///
/// [`char`]: prim@char
/// [pattern]: self::pattern
pub fn trim_matches<P: Pattern + Copy>(&mut self, pat: P) {
self.trim_start_matches(pat);
self.trim_end_matches(pat);
}

/// Repeatedly removes from this string all prefixes that match a pattern.
///
/// The [pattern] can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// The pattern can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// [`char`]s.
///
/// [`char`]: prim@char
/// [pattern]: self::pattern
///
/// # Text directionality
///
Expand All @@ -434,11 +430,10 @@ impl FuriString {

/// Repeatedly removes from this string all suffixes that match a pattern.
///
/// The [pattern] can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// The pattern can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// [`char`]s.
///
/// [`char`]: prim@char
/// [pattern]: self::pattern
///
/// # Text directionality
///
Expand All @@ -457,11 +452,10 @@ impl FuriString {
///
/// If the string does not start with `prefix`, returns `false`.
///
/// The [pattern] can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// The pattern can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// [`char`]s.
///
/// [`char`]: prim@char
/// [pattern]: self::pattern
#[must_use]
pub fn strip_prefix<P: Pattern>(&mut self, prefix: P) -> bool {
prefix.strip_prefix_of(self)
Expand All @@ -474,11 +468,10 @@ impl FuriString {
///
/// If the string does not end with `suffix`, returns `false`.
///
/// The [pattern] can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// The pattern can be a `&FuriString`, [`c_char`], `&CStr`, [`char`], or a slice of
/// [`char`]s.
///
/// [`char`]: prim@char
/// [pattern]: self::pattern
#[must_use]
pub fn strip_suffix<P: Pattern>(&mut self, suffix: P) -> bool {
suffix.strip_suffix_of(self)
Expand Down
13 changes: 8 additions & 5 deletions crates/flipperzero/src/furi/string/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ pub unsafe fn next_code_point<'a, I: Iterator<Item = &'a u8>>(bytes: &mut I) ->

/// An iterator over the [`char`]s of a string.
///
/// This struct is created by the [`chars`] method on [`FuriString`]. See its
/// This struct is created by the [`chars_lossy`] method on [`FuriString`]. See its
/// documentation for more.
///
/// [`char`]: prim@char
/// [`chars`]: FuriString::chars
/// [`chars_lossy`]: super::FuriString::chars_lossy
/// [`FuriString`]: super::FuriString
#[derive(Clone)]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct Chars<'a> {
Expand Down Expand Up @@ -65,11 +66,12 @@ impl FusedIterator for Chars<'_> {}

/// An iterator over the [`char`]s of a string, and their positions.
///
/// This struct is created by the [`char_indices`] method on [`FuriString`]. See its
/// This struct is created by the [`char_indices_lossy`] method on [`FuriString`]. See its
/// documentation for more.
///
/// [`char`]: prim@char
/// [`char_indices`]: FuriString::char_indices
/// [`char_indices_lossy`]: super::FuriString::char_indices_lossy
/// [`FuriString`]: super::FuriString
#[derive(Clone, Debug)]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct CharIndices<'a> {
Expand Down Expand Up @@ -112,7 +114,8 @@ impl FusedIterator for CharIndices<'_> {}
/// This struct is created by the [`bytes`] method on [`FuriString`]. See its
/// documentation for more.
///
/// [`bytes`]: FuriString::bytes
/// [`bytes`]: super::FuriString::bytes
/// [`FuriString`]: super::FuriString
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[derive(Clone, Debug)]
pub struct Bytes<'a>(pub(super) Copied<slice::Iter<'a, u8>>);
Expand Down
1 change: 1 addition & 0 deletions crates/flipperzero/src/furi/string/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const FURI_STRING_FAILURE: usize = usize::MAX;
/// | `&CStr | is substring |
/// | `char` | is contained in string |
/// | `&[char]` | any char in slice is contained in string |
#[allow(clippy::wrong_self_convention)]
pub trait Pattern: Sized {
/// Checks whether the pattern matches anywhere in the haystack.
#[inline]
Expand Down
1 change: 1 addition & 0 deletions crates/flipperzero/src/furi/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl Drop for FuriMutex {
}

unsafe impl RawMutex for FuriMutex {
#[allow(clippy::declare_interior_mutable_const)]
const INIT: Self = FuriMutex::new();
type GuardMarker = GuardNoSend;

Expand Down
Loading