diff --git a/.ci/config.json b/.ci/config.json index efa33378..3ffb12ad 100644 --- a/.ci/config.json +++ b/.ci/config.json @@ -13,7 +13,7 @@ "probe": "303a:1001:60:55:F9:BF:A9:44", "labels": { "target": "esp32", - "board": "esp-rust-board" + "board": "esp-rust-board" } } ] diff --git a/.github/rodbot.yaml b/.github/rodbot.yaml index 6ad3f6c1..81209275 100644 --- a/.github/rodbot.yaml +++ b/.github/rodbot.yaml @@ -1,3 +1,4 @@ +--- on: issue_comment: - if: diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0a7a32e9..81e5a87d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,3 +1,4 @@ +--- name: CI on: @@ -11,6 +12,8 @@ on: jobs: build: runs-on: ubuntu-latest + env: + ENABLE_MEGALINTER: true steps: - uses: actions/checkout@v4 - name: Add dependencies @@ -18,7 +21,7 @@ jobs: sudo apt-get update sudo apt-get install --no-install-recommends libudev-dev - name: Set up cargo cache - uses: actions/cache@v3 + uses: actions/cache@v4.2.0 continue-on-error: true with: path: | diff --git a/.github/workflows/release_trouble_host.yaml b/.github/workflows/release_trouble_host.yaml index 26be513f..35ad0638 100644 --- a/.github/workflows/release_trouble_host.yaml +++ b/.github/workflows/release_trouble_host.yaml @@ -1,13 +1,14 @@ -name: Trouble Host Release +--- +name: Trouble Host Release on: push: tags: - - 'trouble-host-v[0-9]+.[0-9]+.[0-9]+' + - "trouble-host-v[0-9]+.[0-9]+.[0-9]+" permissions: contents: write - + jobs: # Re Run the Checks build: @@ -19,7 +20,7 @@ jobs: sudo apt-get update sudo apt-get install --no-install-recommends libudev-dev - name: Set up cargo cache - uses: actions/cache@v3 + uses: actions/cache@v4.2.0 continue-on-error: true with: path: | @@ -43,48 +44,48 @@ jobs: timeout-minutes: 10 if: github.ref == 'refs/heads/main' steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - - name: Verify Version - run: | - TAG_VERSION=${GITHUB_REF#refs/tags/trouble-host-v} - CARGO_VERSION=$(grep '^version =' host/Cargo.toml | sed -E 's/version = "([^"]+)"/\1/') - if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then - echo "Version mismatch: tag is $TAG_VERSION but Cargo.toml is $CARGO_VERSION" - exit 1 # Exits with a non-zero status to fail the workflow - fi - shell: bash + - name: Verify Version + run: | + TAG_VERSION=${GITHUB_REF#refs/tags/trouble-host-v} + CARGO_VERSION=$(grep '^version =' host/Cargo.toml | sed -E 's/version = "([^"]+)"/\1/') + if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then + echo "Version mismatch: tag is $TAG_VERSION but Cargo.toml is $CARGO_VERSION" + exit 1 # Exits with a non-zero status to fail the workflow + fi + shell: bash - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable - - name: Build project - run: | - cd host - cargo build --release - - - name: Create GitHub release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - tag: ${{ github.ref_name }} - run: | - gh release create "$tag" \ - --repo="$GITHUB_REPOSITORY" \ - --title="${GITHUB_REPOSITORY#*/} host v${tag#trouble-host-v}" \ - --generate-notes + - name: Build project + run: | + cd host + cargo build --release - - name: Publish to crates.io - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - # Publish to the main registry - run: | - echo "Publishing to crates.io" - cargo publish - # To perform a dry run uncomment the following lines - # run: | - # echo "Performing dry-run publish to crates.io" - # cd host - # cargo publish --dry-run + - name: Create GitHub release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ github.ref_name }} + run: | + gh release create "$tag" \ + --repo="$GITHUB_REPOSITORY" \ + --title="${GITHUB_REPOSITORY#*/} host v${tag#trouble-host-v}" \ + --generate-notes + + - name: Publish to crates.io + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + # Publish to the main registry + run: | + echo "Publishing to crates.io" + cargo publish + # To perform a dry run uncomment the following lines + # run: | + # echo "Performing dry-run publish to crates.io" + # cd host + # cargo publish --dry-run diff --git a/.github/workflows/release_trouble_host_macros.yaml b/.github/workflows/release_trouble_host_macros.yaml index 7691aeab..20250343 100644 --- a/.github/workflows/release_trouble_host_macros.yaml +++ b/.github/workflows/release_trouble_host_macros.yaml @@ -1,13 +1,14 @@ +--- name: Trouble Host macros Release on: push: tags: - - 'trouble-host-macros-v[0-9]+.[0-9]+.[0-9]+' + - "trouble-host-macros-v[0-9]+.[0-9]+.[0-9]+" permissions: contents: write - + jobs: # Re Run the Checks build: @@ -19,7 +20,7 @@ jobs: sudo apt-get update sudo apt-get install --no-install-recommends libudev-dev - name: Set up cargo cache - uses: actions/cache@v3 + uses: actions/cache@v4.2.0 continue-on-error: true with: path: | @@ -43,48 +44,48 @@ jobs: timeout-minutes: 10 if: github.ref == 'refs/heads/main' steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - - name: Verify Version - run: | - TAG_VERSION=${GITHUB_REF#refs/tags/trouble-host-macros-v} - CARGO_VERSION=$(grep '^version =' host-macros/Cargo.toml | sed -E 's/version = "([^"]+)"/\1/') - if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then - echo "Version mismatch: tag is $TAG_VERSION but Cargo.toml is $CARGO_VERSION" - exit 1 # Exits with a non-zero status to fail the workflow - fi - shell: bash + - name: Verify Version + run: | + TAG_VERSION=${GITHUB_REF#refs/tags/trouble-host-macros-v} + CARGO_VERSION=$(grep '^version =' host-macros/Cargo.toml | sed -E 's/version = "([^"]+)"/\1/') + if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then + echo "Version mismatch: tag is $TAG_VERSION but Cargo.toml is $CARGO_VERSION" + exit 1 # Exits with a non-zero status to fail the workflow + fi + shell: bash - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable - - name: Build project - run: | - cd host-macros - cargo build --release - - - name: Create GitHub release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - tag: ${{ github.ref_name }} - run: | - gh release create "$tag" \ - --repo="$GITHUB_REPOSITORY" \ - --title="${GITHUB_REPOSITORY#*/} host macros v${tag#trouble-host-macros-v}" \ - --generate-notes + - name: Build project + run: | + cd host-macros + cargo build --release - - name: Publish to crates.io - env: - CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - # Publish to the main registry - run: | - echo "Publishing to crates.io" - cargo publish - # To perform a dry run uncomment the following lines - # run: | - # echo "Performing dry-run publish to crates.io" - # cd host-macros - # cargo publish --dry-run + - name: Create GitHub release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ github.ref_name }} + run: | + gh release create "$tag" \ + --repo="$GITHUB_REPOSITORY" \ + --title="${GITHUB_REPOSITORY#*/} host macros v${tag#trouble-host-macros-v}" \ + --generate-notes + + - name: Publish to crates.io + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + # Publish to the main registry + run: | + echo "Publishing to crates.io" + cargo publish + # To perform a dry run uncomment the following lines + # run: | + # echo "Performing dry-run publish to crates.io" + # cd host-macros + # cargo publish --dry-run diff --git a/.github/workflows/rodbot.yaml b/.github/workflows/rodbot.yaml index 330285cd..87f2e0bb 100644 --- a/.github/workflows/rodbot.yaml +++ b/.github/workflows/rodbot.yaml @@ -1,8 +1,9 @@ +--- name: rodbot on: issue_comment: - types: [ "created" ] + types: ["created"] jobs: rodbot: @@ -13,11 +14,11 @@ jobs: steps: - run: | - echo $GITHUB_EVENT_PATH - cat $GITHUB_EVENT_PATH + echo $"GITHUB_EVENT_PATH" + cat $"GITHUB_EVENT_PATH" - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - uses: ctron/rodbot-action@v0.1 with: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 17cba92d..db04969e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,3 +1,4 @@ +--- name: Tests on: @@ -23,7 +24,7 @@ jobs: sudo apt-get update sudo apt-get install --no-install-recommends libudev-dev - name: Set up cargo cache - uses: actions/cache@v3 + uses: actions/cache@v4.2.0 continue-on-error: true with: path: | @@ -62,7 +63,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=pending" -f "description=Running integration tests" -f "context=integration-tests" - name: Test env: @@ -78,7 +79,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=failure" -f "description=The integration tests failed" -f "context=integration-tests" - name: Update success status if: success() @@ -87,7 +88,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=success" -f "description=The integration tests succeeded!" -f "context=integration-tests" example-tests: @@ -108,7 +109,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=pending" -f "description=Running example tests" -f "context=example-tests" - uses: actions/download-artifact@v4 @@ -131,7 +132,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=failure" -f "description=The example tests failed" -f "context=example-tests" - name: Update success status if: success() @@ -140,5 +141,5 @@ jobs: GH_TOKEN: ${{ github.token }} run: | gh api --method POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/${COMMIT} \ + -H "X-GitHub-Api-Version: 2022-11-28" /repos/embassy-rs/trouble/statuses/"${COMMIT}" \ -f "state=success" -f "description=The example tests succeeded!" -f "context=example-tests" diff --git a/.gitignore b/.gitignore index 8671949c..c914eb9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ **/target **/target_ci Cargo.lock -.idea \ No newline at end of file +.idea +megalinter-reports/ +# Mac Users +.DS_Store \ No newline at end of file diff --git a/.markdownlint.json b/.markdownlint.json new file mode 100644 index 00000000..984d3733 --- /dev/null +++ b/.markdownlint.json @@ -0,0 +1,4 @@ +{ + "default": true, + "line-length": false +} diff --git a/.mega-linter.yaml b/.mega-linter.yaml new file mode 100644 index 00000000..32eb0b35 --- /dev/null +++ b/.mega-linter.yaml @@ -0,0 +1,47 @@ +--- +# Configuration file for MegaLinter +# +# See all available variables at https://megalinter.io/latest/config-file/ and in +# linters documentation + +# all, none, or list of linter keys +APPLY_FIXES: all + +# If you use ENABLE variable, all other languages/formats/tooling-formats will +# be disabled by default +# ENABLE: + +# If you use ENABLE_LINTERS variable, all other linters will be disabled by default +ENABLE_LINTERS: + - ACTION_ACTIONLINT + # - RUST_CLIPPY # Removed as doing inside ci.sh + - MARKDOWN_MARKDOWNLINT + - MARKDOWN_MARKDOWN_LINK_CHECK + - MARKDOWN_MARKDOWN_TABLE_FORMATTER + - YAML_YAMLLINT + - YAML_PRETTIER + - JSON_JSONLINT + - JSON_PRETTIER + - PYTHON_RUFF + - PYTHON_RUFF_FORMAT + - BASH_SHELLCHECK + - BASH_SHFMT + +# DISABLE: + +SHOW_ELAPSED_TIME: true + +FILEIO_REPORTER: false + +# Uncomment if you want MegaLinter to detect errors but not block CI to pass +# DISABLE_ERRORS: true +GITHUB_COMMENT_REPORTER: true +GITHUB_STATUS_REPORTER: true +VALIDATE_ALL_CODEBASE: true +OUTPUT_DETAIL: detailed + +# Linter Configuration +MARKDOWN_MARKDOWNLINT_CONFIG_FILE: .markdownlint.json + +JSON_JSONLINT_ARGUMENTS: + - --comments diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 4dadd879..85b8d01e 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,12 +1,18 @@ { - // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. - // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp - // List of extensions which should be recommended for users of this workspace. - "recommendations": [ - "rust-lang.rust-analyzer", - "tamasfe.even-better-toml", - "fill-labs.dependi", - ], - // List of extensions recommended by VS Code that should not be recommended for users of this workspace. - "unwantedRecommendations": [] -} \ No newline at end of file + // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "rust-lang.rust-analyzer", + "tamasfe.even-better-toml", + "fill-labs.dependi", + "tamasfe.even-better-toml", + "esbenp.prettier-vscode", + "foxundermoon.shell-format", + "charliermarsh.ruff", + "timonwong.shellcheck", + "davidanson.vscode-markdownlint" + ], + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. + "unwantedRecommendations": [] +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 40f3a478..922b66c7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,25 +1,25 @@ -{ - "[rust]": { - "editor.formatOnSave": true, - "editor.formatOnSaveMode": "file", - }, - "[toml]": { - "editor.formatOnSave": false - }, - "[markdown]": { - "editor.formatOnSave": false - }, - "rust-analyzer.check.allTargets": false, - "rust-analyzer.linkedProjects": [ - "host/Cargo.toml", - "host-macros/Cargo.toml", - "examples/apps/Cargo.toml", - // uncomment the examples you want to explore below - // "examples/esp32/Cargo.toml", - // "examples/nrf-sdc/Cargo.toml", - // "examples/rp-pico-w/Cargo.toml", - // "examples/rp-pico-2-w/Cargo.toml", - // "examples/serial-hci/Cargo.toml", - // "examples/apache-nimble/Cargo.toml", - ] -} \ No newline at end of file +{ + "[rust]": { + "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file" + }, + "[toml]": { + "editor.formatOnSave": false + }, + "[markdown]": { + "editor.formatOnSave": false + }, + "rust-analyzer.check.allTargets": false, + "rust-analyzer.linkedProjects": [ + "host/Cargo.toml", + "host-macros/Cargo.toml", + "examples/apps/Cargo.toml" + // uncomment the examples you want to explore below + // "examples/esp32/Cargo.toml", + // "examples/nrf-sdc/Cargo.toml", + // "examples/rp-pico-w/Cargo.toml", + // "examples/rp-pico-2-w/Cargo.toml", + // "examples/serial-hci/Cargo.toml", + // "examples/apache-nimble/Cargo.toml" + ] +} diff --git a/README.md b/README.md index 20f52b8d..308d1e45 100644 --- a/README.md +++ b/README.md @@ -47,11 +47,23 @@ See `examples` for example applications for different BLE controllers. * `serial-hci` which runs on std using a controller attached via a serial port (Such as [this Zephyr sample](https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/bluetooth/hci_uart/README.html)). * `apache-nimble` which uses the controller from the [NimBLE stack](https://github.com/apache/mynewt-nimble) through high-level bindings from the [`apache-nimble`](https://github.com/benbrittain/apache-nimble-sys) crate. * `esp32` which uses the BLE controller in the [esp-hal](https://github.com/esp-rs/esp-hal). + + * `rp-pico-w` which uses the BLE controller in the [Raspberry Pi Pico W](https://www.raspberrypi.com/documentation/microcontrollers/pico-series.html#raspberry-pi-pico-w). * `rp-pico-2-w` which uses the BLE controller in the [Raspberry Pi Pico 2 W](https://www.raspberrypi.com/documentation/microcontrollers/pico-series.html#raspberry-pi-pico-2-w). + Since a lot of the examples demo the same BLE functionality, they only contain basic wiring specific to the BLE controller, and share the 'business logic' within the `examples/apps` folder. +## Linting Process + +The project uses a variety of linters through the use of cargo and [MegaLinter](https://github.com/oxsecurity/megalinter). In order to use these locally, you simply run the [ci.sh](./ci.sh) file which will install the necessary tools. +If you want to use MegaLinter as well, you must set the following environment variable: + +```yaml +ENABLE_MEGALINTER: true +``` + ## License Trouble is licensed under either of diff --git a/ci.sh b/ci.sh index cb8d44de..718e223a 100755 --- a/ci.sh +++ b/ci.sh @@ -2,42 +2,165 @@ set -eo pipefail -if ! command -v cargo-batch &> /dev/null; then - mkdir -p $HOME/.cargo/bin - curl -L https://github.com/embassy-rs/cargo-batch/releases/download/batch-0.6.0/cargo-batch > $HOME/.cargo/bin/cargo-batch - chmod +x $HOME/.cargo/bin/cargo-batch +if ! command -v cargo-batch &>/dev/null; then + mkdir -p "$HOME"/.cargo/bin + curl -L https://github.com/embassy-rs/cargo-batch/releases/download/batch-0.6.0/cargo-batch >"$HOME"/.cargo/bin/cargo-batch + chmod +x "$HOME"/.cargo/bin/cargo-batch fi export RUSTFLAGS=-Dwarnings export DEFMT_LOG=trace export CARGO_NET_GIT_FETCH_WITH_CLI=true if [[ -z "${CARGO_TARGET_DIR}" ]]; then - export CARGO_TARGET_DIR=target_ci + export CARGO_TARGET_DIR=target_ci fi +echo "Running Cargo Build" +# cargo batch \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features peripheral \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features central \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,scan \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,peripheral \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,peripheral,defmt \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,central \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral,central,scan \ +# --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52840 \ +# --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52833 --artifact-dir tests/nrf-sdc \ +# --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52832 \ +# --- build --release --manifest-path examples/esp32/Cargo.toml --features esp32c3 --target riscv32imc-unknown-none-elf --artifact-dir tests/esp32 \ +# --- build --release --manifest-path examples/serial-hci/Cargo.toml \ +# --- build --release --manifest-path examples/tests/Cargo.toml \ +# --- build --release --manifest-path examples/rp-pico-w/Cargo.toml --target thumbv6m-none-eabi --features skip-cyw43-firmware \ +# --- build --release --manifest-path examples/rp-pico-2-w/Cargo.toml --target thumbv8m.main-none-eabihf --features skip-cyw43-firmware \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features peripheral \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features central \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,scan \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,peripheral \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,peripheral,defmt \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,central \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral,central,scan \ +# --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral,central,scan,controller-host-flow-control \ +# --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52840 \ +# --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52833 --artifact-dir tests/nrf-sdc \ +# --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52832 \ +# --- build --release --manifest-path examples/esp32/Cargo.toml --features esp32c3 --target riscv32imc-unknown-none-elf --artifact-dir tests/esp32 \ +# --- build --release --manifest-path examples/serial-hci/Cargo.toml \ +# --- build --release --manifest-path examples/tests/Cargo.toml \ +# --- build --release --manifest-path benchmarks/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52840 \ +# --- build --release --manifest-path examples/rp-pico-w/Cargo.toml --target thumbv6m-none-eabi --features skip-cyw43-firmware \ +# --- build --release --manifest-path examples/rp-pico-2-w/Cargo.toml --target thumbv8m.main-none-eabihf --features skip-cyw43-firmware +# # --- build --release --manifest-path examples/apache-nimble/Cargo.toml --target thumbv7em-none-eabihf -cargo batch \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features peripheral \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features central \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,scan \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,peripheral \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features central,peripheral,defmt \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,central \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral,central,scan \ - --- build --release --manifest-path host/Cargo.toml --no-default-features --features gatt,peripheral,central,scan,controller-host-flow-control \ - --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52840 \ - --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52833 --artifact-dir tests/nrf-sdc \ - --- build --release --manifest-path examples/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52832 \ - --- build --release --manifest-path examples/esp32/Cargo.toml --features esp32c3 --target riscv32imc-unknown-none-elf --artifact-dir tests/esp32 \ - --- build --release --manifest-path examples/serial-hci/Cargo.toml \ - --- build --release --manifest-path examples/tests/Cargo.toml \ - --- build --release --manifest-path benchmarks/nrf-sdc/Cargo.toml --target thumbv7em-none-eabihf --features nrf52840 \ - --- build --release --manifest-path examples/rp-pico-w/Cargo.toml --target thumbv6m-none-eabi --features skip-cyw43-firmware \ - --- build --release --manifest-path examples/rp-pico-2-w/Cargo.toml --target thumbv8m.main-none-eabihf --features skip-cyw43-firmware -# --- build --release --manifest-path examples/apache-nimble/Cargo.toml --target thumbv7em-none-eabihf - -cargo fmt --check --manifest-path ./host/Cargo.toml -cargo clippy --manifest-path ./host/Cargo.toml --features gatt,peripheral,central +# Run Cargo fmt +echo "Running Cargo fmt" +# cargo batch \ +# --- fmt --manifest-path host/Cargo.toml -- --check \ +# --- fmt --manifest-path host-macros/Cargo.toml -- --check \ +# --- fmt --manifest-path examples/apache-nimble/Cargo.toml -- --check \ +# --- fmt --manifest-path examples/apps/Cargo.toml -- --check \ +# --- fmt --manifest-path examples/esp32/Cargo.toml -- --check \ +# --- fmt --manifest-path examples/nrf-sdc/Cargo.toml -- --check \ +# --- fmt --manifest-path examples/rp-pico-2-w/Cargo.toml -- --check \ +# --- fmt --manifest-path examples/rp-pico-w/Cargo.toml -- --check \ +# --- fmt --manifest-path examples/serial-hci/Cargo.toml -- --check \ +# --- fmt --manifest-path examples/tests/Cargo.toml -- --check \ + +# Clippy Main Library +echo "Running Cargo Clippy" +cd host && cargo clippy -- -D warnings && cd .. +cd host-macros && cargo clippy -- -D warnings && cd .. + +# Clippy Examples +cd examples +echo "Running Cargo Clippy on the examples directory" +# cd apache-nimble && cargo clippy -- -D warnings && cd .. +cd apps && cargo clippy -- -D warnings && cd .. + +# ESP32 Examples +echo "Running Cargo Clippy on ESP32 examples" +cd esp32 +# cd esp32 && cargo clippy --no-default-features --features=esp32 --target=xtensa-esp32-none-elf -- -D warnings && cd .. +cargo clippy --no-default-features --features=esp32c2 --target=riscv32imc-unknown-none-elf -- -D warnings +cargo clippy --no-default-features --features=esp32c3 --target=riscv32imc-unknown-none-elf -- -D warnings +cargo clippy --no-default-features --features=esp32c6 --target=riscv32imac-unknown-none-elf -- -D warnings +cargo clippy --no-default-features --features=esp32h2 --target=riscv32imac-unknown-none-elf -- -D warnings +# cargo clippy --no-default-features --features=esp32s3 --target=xtensa-esp32s3-none-elf -- -D warnings +cd .. +# nrf-sdc +echo "Running Cargo Clippy on nrf-sdc example" +cd nrf-sdc +# cargo clippy --features=nrf52832 -- -D warnings +# cargo clippy --features=nrf52833 -- -D warnings +# cargo clippy --features=nrf52840 -- -D warnings +cd .. + +# rp-pico-2-w +echo "Running Cargo Clippy on rp-pico-2-w example" +cd rp-pico-2-w && cargo clippy -- --D warnings && cd .. + +# rp-pico-w +echo "Running Cargo Clippy on rp-pico-w example" +cd rp-pico-w && cargo clippy -- --D warnings && cd .. + +# serial-hci +echo "Running Cargo Clippy on serial-hci example" +cd serial-hci && cargo clippy -- --D warnings && cd .. + +# tests +echo "Running Cargo Clippy on tests example" +cd tests && cargo clippy -- --D warnings && cd .. +# Leave examples folder +cd .. + +# Enable MegaLinter (you can set this flag in your CI/CD or local environment) +ENABLE_MEGALINTER=${ENABLE_MEGALINTER:-true} # Use variable or default to true +# Run and install MegaLinter (if enabled) +# Check if MegaLinter should be enabled +if [ "$ENABLE_MEGALINTER" = true ]; then + echo "MegaLinter is enabled. Installing and running..." + + # Check if Node.js is installed; install if necessary + if ! command -v node >/dev/null 2>&1; then + install_node + fi + # Install MegaLinter globally (if not already installed) + if ! command -v mega-linter-runner >/dev/null 2>&1; then + echo "Installing MegaLinter..." + npm install -g mega-linter-runner + else + echo "MegaLinter is already installed." + fi + + # Run MegaLinter + echo "Running MegaLinter..." + mega-linter-runner +else + echo "MegaLinter is not enabled. Skipping..." +fi + +# Run tests +echo "Running Cargo test" cargo test --manifest-path ./host/Cargo.toml --lib -- --nocapture cargo test --manifest-path ./host/Cargo.toml --no-run -- --nocapture cargo test --manifest-path ./examples/tests/Cargo.toml --no-run -- --nocapture + +# Function to install Node.js if not installed +install_node() { + echo "Node.js is not installed. Installing..." + # Detect OS and install Node.js + if [ "$(uname)" = "Darwin" ]; then + brew install node + elif [ "$(uname -s)" = "Linux" ]; then + apt-get install nodejs + else + echo "Unsupported operating system. Please install Node.js manually." + exit 1 + fi + + # Confirm npm is now available after Node.js installation + if ! command -v npm >/dev/null 2>&1; then + echo "npm is not available even after Node.js installation. Please check your installation." + exit 1 + fi +} diff --git a/examples/apache-nimble/src/bin/ble_bas_peripheral.rs b/examples/apache-nimble/src/bin/ble_bas_peripheral.rs index 36ee65e7..5e56a9ff 100644 --- a/examples/apache-nimble/src/bin/ble_bas_peripheral.rs +++ b/examples/apache-nimble/src/bin/ble_bas_peripheral.rs @@ -1,8 +1,7 @@ #![no_main] #![no_std] -use apache_nimble::controller::NimbleController; -use apache_nimble::controller::NimbleControllerTask; +use apache_nimble::controller::{NimbleController, NimbleControllerTask}; use embassy_time::{Duration, Ticker, Timer}; use trouble_example_apps::ble_bas_peripheral; use {defmt_rtt as _, panic_probe as _}; diff --git a/examples/apps/src/ble_scanner.rs b/examples/apps/src/ble_scanner.rs index 75f00c37..9acf26f1 100644 --- a/examples/apps/src/ble_scanner.rs +++ b/examples/apps/src/ble_scanner.rs @@ -1,6 +1,7 @@ +use core::cell::RefCell; + use bt_hci::cmd::le::LeSetScanParams; use bt_hci::controller::ControllerCmdSync; -use core::cell::RefCell; use embassy_futures::join::join; use embassy_time::{Duration, Timer}; use heapless::Deque; @@ -31,11 +32,13 @@ where }; let mut scanner = Scanner::new(central); let _ = join(runner.run_with_handler(&printer), async { - let mut config = ScanConfig::default(); - config.active = true; - config.phys = PhySet::M1; - config.interval = Duration::from_secs(1); - config.window = Duration::from_secs(1); + let config = ScanConfig::<'_> { + active: true, + phys: PhySet::M1, + interval: Duration::from_secs(1), + window: Duration::from_secs(1), + ..Default::default() + }; let mut _session = scanner.scan(&config).await.unwrap(); // Scan forever loop { @@ -53,7 +56,7 @@ impl EventHandler for Printer { fn on_adv_reports(&self, mut it: LeAdvReportsIter<'_>) { let mut seen = self.seen.borrow_mut(); while let Some(Ok(report)) = it.next() { - if seen.iter().find(|b| b.raw() == report.addr.raw()).is_none() { + if !seen.iter().any(|b| b.raw() == report.addr.raw()) { info!("discovered: {:?}", report.addr); if seen.is_full() { seen.pop_front(); diff --git a/examples/apps/src/fmt.rs b/examples/apps/src/fmt.rs index c46fff33..6c8f7402 100644 --- a/examples/apps/src/fmt.rs +++ b/examples/apps/src/fmt.rs @@ -233,19 +233,19 @@ impl Try for Result { #[allow(unused)] pub(crate) struct Bytes<'a>(pub &'a [u8]); -impl<'a> Debug for Bytes<'a> { +impl Debug for Bytes<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{:#02x?}", self.0) } } -impl<'a> Display for Bytes<'a> { +impl Display for Bytes<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{:#02x?}", self.0) } } -impl<'a> LowerHex for Bytes<'a> { +impl LowerHex for Bytes<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{:#02x?}", self.0) } diff --git a/examples/esp32/build.rs b/examples/esp32/build.rs index d1771291..5efe9c99 100644 --- a/examples/esp32/build.rs +++ b/examples/esp32/build.rs @@ -1,3 +1,3 @@ fn main() { println!("cargo:rustc-link-arg-bins=-Tlinkall.x"); -} \ No newline at end of file +} diff --git a/examples/esp32/src/bin/ble_bas_central.rs b/examples/esp32/src/bin/ble_bas_central.rs index cc016c95..11d16ab1 100644 --- a/examples/esp32/src/bin/ble_bas_central.rs +++ b/examples/esp32/src/bin/ble_bas_central.rs @@ -3,7 +3,8 @@ use bt_hci::controller::ExternalController; use embassy_executor::Spawner; -use esp_hal::{clock::CpuClock, timer::timg::TimerGroup}; +use esp_hal::clock::CpuClock; +use esp_hal::timer::timg::TimerGroup; use esp_wifi::ble::controller::BleConnector; use trouble_example_apps::ble_bas_central; use {esp_alloc as _, esp_backtrace as _}; diff --git a/examples/esp32/src/bin/ble_bas_peripheral.rs b/examples/esp32/src/bin/ble_bas_peripheral.rs index ded57aa5..ec9f41d6 100644 --- a/examples/esp32/src/bin/ble_bas_peripheral.rs +++ b/examples/esp32/src/bin/ble_bas_peripheral.rs @@ -3,7 +3,8 @@ use bt_hci::controller::ExternalController; use embassy_executor::Spawner; -use esp_hal::{clock::CpuClock, timer::timg::TimerGroup}; +use esp_hal::clock::CpuClock; +use esp_hal::timer::timg::TimerGroup; use esp_wifi::ble::controller::BleConnector; use trouble_example_apps::ble_bas_peripheral; use {esp_alloc as _, esp_backtrace as _}; diff --git a/examples/esp32/src/bin/ble_l2cap_central.rs b/examples/esp32/src/bin/ble_l2cap_central.rs index 03024fe3..b0a10d4d 100644 --- a/examples/esp32/src/bin/ble_l2cap_central.rs +++ b/examples/esp32/src/bin/ble_l2cap_central.rs @@ -3,7 +3,8 @@ use bt_hci::controller::ExternalController; use embassy_executor::Spawner; -use esp_hal::{clock::CpuClock, timer::timg::TimerGroup}; +use esp_hal::clock::CpuClock; +use esp_hal::timer::timg::TimerGroup; use esp_wifi::ble::controller::BleConnector; use trouble_example_apps::ble_l2cap_central; use {esp_alloc as _, esp_backtrace as _}; diff --git a/examples/esp32/src/bin/ble_l2cap_peripheral.rs b/examples/esp32/src/bin/ble_l2cap_peripheral.rs index 4a0d19e0..49002078 100644 --- a/examples/esp32/src/bin/ble_l2cap_peripheral.rs +++ b/examples/esp32/src/bin/ble_l2cap_peripheral.rs @@ -3,7 +3,8 @@ use bt_hci::controller::ExternalController; use embassy_executor::Spawner; -use esp_hal::{clock::CpuClock, timer::timg::TimerGroup}; +use esp_hal::clock::CpuClock; +use esp_hal::timer::timg::TimerGroup; use esp_wifi::ble::controller::BleConnector; use trouble_example_apps::ble_l2cap_peripheral; use {esp_alloc as _, esp_backtrace as _}; diff --git a/examples/rp-pico-w/build.rs b/examples/rp-pico-w/build.rs index ff241da0..00e2b38c 100644 --- a/examples/rp-pico-w/build.rs +++ b/examples/rp-pico-w/build.rs @@ -48,7 +48,7 @@ fn download_cyw43_firmware() { "43439A0_clm.bin", "LICENSE-permissive-binary-license-1.0.txt", "README.md", - ]; + ]; println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed={}", download_folder); diff --git a/examples/tests/src/lib.rs b/examples/tests/src/lib.rs index dbccd3ee..5df228f7 100644 --- a/examples/tests/src/lib.rs +++ b/examples/tests/src/lib.rs @@ -31,3 +31,9 @@ impl TestContext { Ok(DeviceUnderTest::new(target)) } } + +impl Default for TestContext { + fn default() -> Self { + Self::new() + } +} diff --git a/examples/tests/src/probe/mod.rs b/examples/tests/src/probe/mod.rs index df369ad3..a9e4444a 100644 --- a/examples/tests/src/probe/mod.rs +++ b/examples/tests/src/probe/mod.rs @@ -1,13 +1,11 @@ use std::process::Stdio; -use tokio::io::AsyncBufReadExt; -use tokio::io::BufReader; + +use hilbench_agent::{ProbeConfig, Target}; +use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::process::Command; use tokio::select; use tokio_util::sync::CancellationToken; -use hilbench_agent::ProbeConfig; -use hilbench_agent::Target; - pub fn init(config: ProbeConfig) { hilbench_agent::init(config); } diff --git a/examples/tests/tests/ble_l2cap_central.rs b/examples/tests/tests/ble_l2cap_central.rs index ccc620c8..f5adb463 100644 --- a/examples/tests/tests/ble_l2cap_central.rs +++ b/examples/tests/tests/ble_l2cap_central.rs @@ -1,5 +1,6 @@ -use futures::future::join; use std::time::Duration; + +use futures::future::join; use tokio::select; use trouble_example_tests::{serial, TestContext}; use trouble_host::prelude::*; diff --git a/examples/tests/tests/ble_l2cap_peripheral.rs b/examples/tests/tests/ble_l2cap_peripheral.rs index 4601c0bd..cb6a828f 100644 --- a/examples/tests/tests/ble_l2cap_peripheral.rs +++ b/examples/tests/tests/ble_l2cap_peripheral.rs @@ -1,5 +1,6 @@ -use futures::future::join; use std::time::Duration; + +use futures::future::join; use tokio::select; use trouble_example_tests::{serial, TestContext}; use trouble_host::prelude::*; diff --git a/host/gen_config.py b/host/gen_config.py index 3a16efd5..5267eb4b 100644 --- a/host/gen_config.py +++ b/host/gen_config.py @@ -19,7 +19,7 @@ def feature(name, default, min=None, max=None, pow2=None, vals=None, factors=[]) for f in factors: if val*f <= max: vals.add(val*f) - if (pow2 == True or (isinstance(pow2, int) and val >= pow2)) and val > 0: + if (pow2 is True or (isinstance(pow2, int) and val >= pow2)) and val > 0: val *= 2 else: val += 1