Skip to content

Commit

Permalink
Merge branch 'main' into gui-bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
JarvisCraft committed Jun 12, 2023
2 parents e8f7708 + dd1ba2a commit 82b54fd
Show file tree
Hide file tree
Showing 47 changed files with 575 additions and 331 deletions.
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.3
- 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/checkout@v3.5.3
- name: Install build dependencies
run: sudo apt install libudev-dev
- name: Run Clippy
uses: auguwu/clippy-action@1.1.2
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
defaults:
run:
working-directory: ${{ inputs.target }}
steps:
- uses: actions/checkout@v3.5.3
- 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/clippy-action@1.1.2
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/checkout@v3.5.3
- 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/checkout@v3.5.3
- 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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ 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.

### Documentation
- Feature flags are now documented and the items guarded by them are now annotated.

## [0.10.0]
### Added
Expand Down
7 changes: 1 addition & 6 deletions crates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@ repository = "https://github.com/dcoles/flipperzero-rs"
readme = "../README.md"
license = "MIT"

[workspace.metadata.docs.rs]
default-target = "thumbv7em-none-eabihf"
targets = []
all-features = true

[workspace.dependencies]
flipperzero-sys = { path = "sys", version = "0.10.0" }
flipperzero-rt = { path = "rt", version = "0.10.0" }
flipperzero-alloc = { path = "alloc", version = "0.10.0" }
flipperzero-test = { path = "test", version = "0.10.0" }
ufmt = "0.2.0"
document-features = { version = "0.2.0" }
document-features = "0.2.0"

[profile.dev]
opt-level = "z"
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
28 changes: 19 additions & 9 deletions crates/flipperzero/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ license.workspace = true
edition.workspace = true
rust-version.workspace = true
autobins = false
autotests = false
autobenches = false

[package.metadata.docs.rs]
default-target = "thumbv7em-none-eabihf"
targets = []
all-features = true

[lib]
bench = false
harness = false
Expand Down Expand Up @@ -43,20 +49,17 @@ sha2 = { version = "0.10", default-features = false }

[features]

## Default features.
default = []
#! ## Core features

## Enables features requiring an allocator.
##
## This will require you to set up an allocator such as by the following:
## This will require you to set the global allocator
## by importing the `flipperzero_alloc`:
##
## ```
## extern crate flipperzero_alloc as alloc;
## extern crate alloc;
## extern crate flipperzero_alloc;
## ```
##
## Note that the `as alloc` part is optional but is helpful
## if you want to reference items from `alloc` crate all of which are re-exported by `flipperzero_alloc`
## such as `alloc::string::ToString` instead of `flipperzero_alloc::string::ToString`.
alloc = []

#! ## Service features.
Expand Down Expand Up @@ -88,6 +91,13 @@ service-dialogs = ["service-gui"]
## Enables Dolphin APIs of Flipper.
service-dolphin = []

#! ## Utilities
#!
#! These APIs provide extra functionality required for specific use-cases.

## Enables APIs for working with XBM-images.
xbm = []

#! ## Unstable features
#!
#! This features are unstable and are yet a subject to drastic changes.
Expand Down Expand Up @@ -124,7 +134,7 @@ required-features = ["service-notification"]

[[example]]
name = "gui"
required-features = ["service-gui"]
required-features = ["service-gui", "xbm"]

[[example]]
name = "images"
Expand Down
1 change: 1 addition & 0 deletions crates/flipperzero/examples/example_images.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion crates/flipperzero/examples/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ use core::{ffi::CStr, time::Duration};

use flipperzero::{
furi::message_queue::MessageQueue,
gui::xbm::{ByteArray, XbmImage},
gui::{
canvas::CanvasView,
view_port::{ViewPort, ViewPortCallbacks},
Gui, GuiLayer,
},
input::{InputEvent, InputKey, InputType},
println,
xbm::{ByteArray, XbmImage},
};
use flipperzero_rt::{entry, manifest};
use flipperzero_sys::furi::Status;
Expand Down
1 change: 0 additions & 1 deletion crates/flipperzero/examples/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
extern crate flipperzero_rt;

// Required for allocator
#[cfg(feature = "alloc")]
extern crate flipperzero_alloc;

use core::ffi::CStr;
Expand Down
2 changes: 1 addition & 1 deletion crates/flipperzero/examples/xbms/ferris.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use flipperzero::gui::xbm::{ByteArray, XbmImage};
use flipperzero::xbm::{ByteArray, XbmImage};

pub const IMAGE: XbmImage<ByteArray<192>> = flipperzero::xbm! {
#define ferris_width 48
Expand Down
14 changes: 7 additions & 7 deletions crates/flipperzero/src/dialogs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,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 All @@ -165,15 +171,9 @@ impl DialogMessageButton {
}
}

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

/// Displays a simple dialog.
#[cfg(feature = "alloc")]
#[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "alloc")))]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn alert(text: &str) {
// SAFETY: string is known to end with NUL
const BUTTON_OK: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"OK\0") };
Expand Down
4 changes: 2 additions & 2 deletions crates/flipperzero/src/furi/log/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl ufmt::uDisplay for Level {
}

#[cfg(feature = "std")]
#[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for ParseLevelError {}

impl FromStr for Level {
Expand Down Expand Up @@ -466,7 +466,7 @@ impl ufmt::uDisplay for ParseLevelFilterError {
}

#[cfg(feature = "std")]
#[cfg_attr(feature = "unstable_docs", doc(cfg(feature = "std")))]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for ParseLevelFilterError {}

#[repr(usize)]
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
Loading

0 comments on commit 82b54fd

Please sign in to comment.