From cb4adcb1b6cb95c8243c1883c402e0fbc79c742e Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:16:46 +0000 Subject: [PATCH 01/11] Add github workflow. --- .cargo/{config => config.toml} | 0 .github/workflows/ci_checks.yml | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) rename .cargo/{config => config.toml} (100%) create mode 100644 .github/workflows/ci_checks.yml diff --git a/.cargo/config b/.cargo/config.toml similarity index 100% rename from .cargo/config rename to .cargo/config.toml diff --git a/.github/workflows/ci_checks.yml b/.github/workflows/ci_checks.yml new file mode 100644 index 0000000..2e78421 --- /dev/null +++ b/.github/workflows/ci_checks.yml @@ -0,0 +1,67 @@ +name: CI Checks + +on: [push, pull_request] + +env: + CARGO_TERM_COLOR: always + +jobs: + building: + name: Building + continue-on-error: ${{ matrix.experimental || false }} + strategy: + matrix: + # All generated code should be running on stable now + rust: [nightly, stable] + include: + # Nightly is only for reference and allowed to fail + - rust: nightly + experimental: true + os: + # Check compilation works on common OSes + # (i.e. no path issues) + - ubuntu-latest + - macOS-latest + - windows-latest + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.rust }} + override: true + - run: cargo build --all + - run: cargo build --all --release + testing: + name: Testing + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + - run: cargo test + linting: + name: Linting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - uses: actions-rs/toolchain@v1 + with: + components: clippy + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-targets --all-features -- -D warnings + formatting: + name: Formatting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - uses: actions-rs/toolchain@v1 + with: + components: rustfmt + - run: cargo fmt -- --check From e7ed6855c9ddf97697db459986ec38c2ae39a5c9 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:25:26 +0000 Subject: [PATCH 02/11] Need to add target --- .github/workflows/ci_checks.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci_checks.yml b/.github/workflows/ci_checks.yml index 2e78421..6958ae2 100644 --- a/.github/workflows/ci_checks.yml +++ b/.github/workflows/ci_checks.yml @@ -31,6 +31,7 @@ jobs: profile: minimal toolchain: ${{ matrix.rust }} override: true + - run: rustup target install --toolchain=${{ matrix.rust }} thumbv6m-none-eabi - run: cargo build --all - run: cargo build --all --release testing: From 5b961db0ad2430354a7bc6aa6f8e8ecb6ca18a7a Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:26:44 +0000 Subject: [PATCH 03/11] OK, it seems we have to specify a toolchain. --- .github/workflows/ci_checks.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_checks.yml b/.github/workflows/ci_checks.yml index 6958ae2..0103945 100644 --- a/.github/workflows/ci_checks.yml +++ b/.github/workflows/ci_checks.yml @@ -40,6 +40,8 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 + with: + toolchain: stable - run: cargo test linting: name: Linting @@ -50,7 +52,8 @@ jobs: submodules: true - uses: actions-rs/toolchain@v1 with: - components: clippy + toolchain: stable + components: clippy - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -64,5 +67,6 @@ jobs: submodules: true - uses: actions-rs/toolchain@v1 with: + toolchain: stable components: rustfmt - run: cargo fmt -- --check From 44fc2a6d839558d11d330fa168d62eeccadec379 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:28:19 +0000 Subject: [PATCH 04/11] Oh, we need flip-link. --- .github/workflows/ci_checks.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci_checks.yml b/.github/workflows/ci_checks.yml index 0103945..1e0fffe 100644 --- a/.github/workflows/ci_checks.yml +++ b/.github/workflows/ci_checks.yml @@ -31,6 +31,7 @@ jobs: profile: minimal toolchain: ${{ matrix.rust }} override: true + - run: cargo install flip-link - run: rustup target install --toolchain=${{ matrix.rust }} thumbv6m-none-eabi - run: cargo build --all - run: cargo build --all --release From 1213a20d2cd43621172f8c9bd8a4c99a9a2deaa8 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:29:25 +0000 Subject: [PATCH 05/11] Clippy needs a valid target core file. --- .github/workflows/ci_checks.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci_checks.yml b/.github/workflows/ci_checks.yml index 1e0fffe..470c6e2 100644 --- a/.github/workflows/ci_checks.yml +++ b/.github/workflows/ci_checks.yml @@ -70,4 +70,5 @@ jobs: with: toolchain: stable components: rustfmt + - run: rustup target install --toolchain=${{ matrix.rust }} thumbv6m-none-eabi - run: cargo fmt -- --check From 93c6da2dd1690cade7defe5503a184a5e8959c07 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:33:33 +0000 Subject: [PATCH 06/11] Set the target for testing. Having a .cargo/config.toml file is annoying if you want to run tests, as it will attempt to compile the tests for the embedded target. --- .github/workflows/ci_checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_checks.yml b/.github/workflows/ci_checks.yml index 470c6e2..dcf94ab 100644 --- a/.github/workflows/ci_checks.yml +++ b/.github/workflows/ci_checks.yml @@ -43,7 +43,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: toolchain: stable - - run: cargo test + - run: cargo test --target=x86_64-unknown-linux-gnu linting: name: Linting runs-on: ubuntu-latest From 515afd53c0ebe4c2d24727937bac3ff82e88de38 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:34:46 +0000 Subject: [PATCH 07/11] No matrix for rustfmt. --- .github/workflows/ci_checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_checks.yml b/.github/workflows/ci_checks.yml index dcf94ab..8f2b012 100644 --- a/.github/workflows/ci_checks.yml +++ b/.github/workflows/ci_checks.yml @@ -70,5 +70,5 @@ jobs: with: toolchain: stable components: rustfmt - - run: rustup target install --toolchain=${{ matrix.rust }} thumbv6m-none-eabi + - run: rustup target install thumbv6m-none-eabi - run: cargo fmt -- --check From 3c87ecdbb7d44f0696c1faa849a3b752253b128d Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:39:12 +0000 Subject: [PATCH 08/11] Clippy needs core too. --- .github/workflows/ci_checks.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci_checks.yml b/.github/workflows/ci_checks.yml index 8f2b012..bb41e32 100644 --- a/.github/workflows/ci_checks.yml +++ b/.github/workflows/ci_checks.yml @@ -55,6 +55,7 @@ jobs: with: toolchain: stable components: clippy + - run: rustup target install thumbv6m-none-eabi - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} From 4e2c6324855d681097533acbc9c1c5ce0178e561 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:47:34 +0000 Subject: [PATCH 09/11] Add a lib that you can test. --- .github/workflows/ci_checks.yml | 2 +- Cargo.toml | 6 ++---- src/lib.rs | 20 ++++++++++++++++++++ src/main.rs | 6 ++++-- 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 src/lib.rs diff --git a/.github/workflows/ci_checks.yml b/.github/workflows/ci_checks.yml index bb41e32..baa2a00 100644 --- a/.github/workflows/ci_checks.yml +++ b/.github/workflows/ci_checks.yml @@ -43,7 +43,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: toolchain: stable - - run: cargo test --target=x86_64-unknown-linux-gnu + - run: cargo test --lib --target=x86_64-unknown-linux-gnu linting: name: Linting runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index 2c7d046..8ea83e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,10 +23,8 @@ pico = { git = "https://github.com/rp-rs/rp-hal", branch="main"} # pro_micro_rp2040 = { git = "https://github.com/rp-rs/rp-hal", branch="main"} # If you're not going to use a Board Support Package you'll need these: -#rp2040-hal = { git = "https://github.com/rp-rs/rp-hal", branch="main", features=["rt"] } -#rp2040-boot2 = { git = "https://github.com/rp-rs/rp2040-boot2-rs", branch="main" } - - +# rp2040-hal = { git = "https://github.com/rp-rs/rp-hal", branch="main", features=["rt"] } +# rp2040-boot2 = { git = "https://github.com/rp-rs/rp2040-boot2-rs", branch="main" } # cargo build/run [profile.dev] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..f37054e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,20 @@ +//! # Library Code for the rp2040-project-template application +//! +//! Code in this file can be tested on the host with `cargo +//! test --lib --target=` + +#[cfg_attr(not(test), no_std)] + +/// LED on-period and off-period, in milliseconds +pub const LED_DELAY_MS: u32 = 500; + +#[cfg(test)] +mod test { + #[test] + fn it_works() { + let sum = 2 + 2; + assert_eq!(4, sum); + } +} + +// End of file \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index c3c8b90..5157f03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,9 +59,11 @@ fn main() -> ! { loop { info!("on!"); led_pin.set_high().unwrap(); - delay.delay_ms(500); + delay.delay_ms(rp2040_project_template::LED_DELAY_MS); info!("off!"); led_pin.set_low().unwrap(); - delay.delay_ms(500); + delay.delay_ms(rp2040_project_template::LED_DELAY_MS); } } + +// End of file \ No newline at end of file From 550578afdee231d060c5a8316ad1095414804157 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:49:59 +0000 Subject: [PATCH 10/11] OK, fine. No testing. --- .github/workflows/ci_checks.yml | 11 +---------- src/lib.rs | 20 -------------------- src/main.rs | 4 ++-- 3 files changed, 3 insertions(+), 32 deletions(-) delete mode 100644 src/lib.rs diff --git a/.github/workflows/ci_checks.yml b/.github/workflows/ci_checks.yml index baa2a00..b397f4b 100644 --- a/.github/workflows/ci_checks.yml +++ b/.github/workflows/ci_checks.yml @@ -35,15 +35,6 @@ jobs: - run: rustup target install --toolchain=${{ matrix.rust }} thumbv6m-none-eabi - run: cargo build --all - run: cargo build --all --release - testing: - name: Testing - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - - run: cargo test --lib --target=x86_64-unknown-linux-gnu linting: name: Linting runs-on: ubuntu-latest @@ -59,7 +50,7 @@ jobs: - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --all-targets --all-features -- -D warnings + args: --all-features -- -D warnings formatting: name: Formatting runs-on: ubuntu-latest diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index f37054e..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,20 +0,0 @@ -//! # Library Code for the rp2040-project-template application -//! -//! Code in this file can be tested on the host with `cargo -//! test --lib --target=` - -#[cfg_attr(not(test), no_std)] - -/// LED on-period and off-period, in milliseconds -pub const LED_DELAY_MS: u32 = 500; - -#[cfg(test)] -mod test { - #[test] - fn it_works() { - let sum = 2 + 2; - assert_eq!(4, sum); - } -} - -// End of file \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5157f03..9da151b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,10 +59,10 @@ fn main() -> ! { loop { info!("on!"); led_pin.set_high().unwrap(); - delay.delay_ms(rp2040_project_template::LED_DELAY_MS); + delay.delay_ms(500); info!("off!"); led_pin.set_low().unwrap(); - delay.delay_ms(rp2040_project_template::LED_DELAY_MS); + delay.delay_ms(500); } } From 3625260815a9bc4c3168f321b6dc96cff19e2794 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sun, 5 Dec 2021 18:50:26 +0000 Subject: [PATCH 11/11] Formatting --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9da151b..d509231 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,4 +66,4 @@ fn main() -> ! { } } -// End of file \ No newline at end of file +// End of file