diff --git a/.github/workflows/firmware.yml b/.github/workflows/firmware.yml index 730eaf1..5186d26 100644 --- a/.github/workflows/firmware.yml +++ b/.github/workflows/firmware.yml @@ -1,5 +1,4 @@ name: Firmware CI Checks - on: push @@ -9,54 +8,48 @@ env: jobs: building: - name: Building - continue-on-error: ${{ matrix.experimental || false }} + name: Build ${{ matrix.platform }} (${{ matrix.target }}) strategy: matrix: - # All generated code should be running on stable now - # TODO: Also test nightly - #rust: [nightly, stable] - rust: [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) - # # - macOS-latest - # - ubuntu-latest - # - windows-latest - runs-on: [ubuntu-latest] #${{ matrix.os }} + target: ['debug', 'release'] + platform: [b1display, c1minimal, ledmatrix] + runs-on: [ubuntu-latest] steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ matrix.rust }} - target: thumbv6m-none-eabi + + - name: Setup Rust toolchain + run: rustup show + - run: cargo install flip-link - - run: cargo build -p ledmatrix - - run: cargo build -p b1display - - run: cargo build -p c1minimal - # TODO: Also build release versions - #- run: cargo build --all --release - - run: | + - name: Build release firmware + if: ${{ matrix.target }} == 'release' + run: | + make PLATFORM=${{ matrix.platform }} release + + - name: Build debug firmware + if: ${{ matrix.target }} == 'debug' + run: | + cargo build -p ${{ matrix.platform }} + + - name: Convert to UF2 file + run: | sudo apt-get update sudo apt-get install -y libudev-dev cargo install elf2uf2-rs - elf2uf2-rs target/thumbv6m-none-eabi/debug/b1display b1display.uf2 - elf2uf2-rs target/thumbv6m-none-eabi/debug/c1minimal c1minimal.uf2 - elf2uf2-rs target/thumbv6m-none-eabi/debug/ledmatrix ledmatrix.uf2 + elf2uf2-rs target/thumbv6m-none-eabi/${{ matrix.target }}/${{ matrix.platform }} ${{ matrix.platform }}.uf2 + + - name: Show hash of firmare + run: | + sha256sum target/thumbv6m-none-eabi/${{ matrix.target }}/${{ matrix.platform }} + sha256sum ${{ matrix.platform }}.uf2 - name: Upload Linux tool uses: actions/upload-artifact@v3 with: - name: inputmodule_fw + name: ${{ matrix.platform }}.uf2 path: | - b1display.uf2 - c1minimal.uf2 - ledmatrix.uf2 + ${{ matrix.platform }}.uf2 linting: name: Linting @@ -65,10 +58,10 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - uses: dtolnay/rust-toolchain@stable - with: - components: clippy - target: thumbv6m-none-eabi + + - name: Setup Rust toolchain + run: rustup show + - run: | cargo clippy -p b1display -- --deny=warnings cargo clippy -p c1minimal -- --deny=warnings @@ -81,8 +74,8 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt - target: thumbv6m-none-eabi + + - name: Setup Rust toolchain + run: rustup show + - run: cargo fmt --all -- --check diff --git a/Cargo.lock b/Cargo.lock index 7923f8b..d19a1b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -583,55 +583,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6548a0ad5d2549e111e1f6a11a6c2e2d00ce6a3dafe22948d67c2b443f775e52" -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" -dependencies = [ - "autocfg 1.1.0", - "cfg-if", - "crossbeam-utils", - "memoffset", - "scopeguard 1.1.0", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - [[package]] name = "cxx" version = "1.0.94" @@ -827,22 +778,6 @@ dependencies = [ "backtrace", ] -[[package]] -name = "exr" -version = "1.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdd2162b720141a91a054640662d3edce3d50a944a50ffca5313cd951abb35b4" -dependencies = [ - "bit_field", - "flume", - "half", - "lebe", - "miniz_oxide 0.6.2", - "rayon-core", - "smallvec 1.10.0", - "zune-inflate", -] - [[package]] name = "ezconf" version = "0.3.0" @@ -911,19 +846,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "flume" -version = "0.10.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" -dependencies = [ - "futures-core", - "futures-sink", - "nanorand", - "pin-project", - "spin", -] - [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -978,15 +900,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "half" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0" -dependencies = [ - "crunchy", -] - [[package]] name = "hash32" version = "0.2.1" @@ -1030,15 +943,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.1" @@ -1202,15 +1106,6 @@ dependencies = [ "libc", ] -[[package]] -name = "jpeg-decoder" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" -dependencies = [ - "rayon", -] - [[package]] name = "js-sys" version = "0.3.61" @@ -1232,12 +1127,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" -[[package]] -name = "lebe" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" - [[package]] name = "ledmatrix" version = "0.1.4" @@ -1377,15 +1266,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "memoffset" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "micromath" version = "1.1.1" @@ -1682,26 +1562,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -[[package]] -name = "pin-project" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "pio" version = "0.2.1" @@ -1941,28 +1801,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" -[[package]] -name = "rayon" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" -dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "num_cpus", -] - [[package]] name = "rdrand" version = "0.4.0" @@ -2377,17 +2215,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "tiff" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7449334f9ff2baf290d55d73983a7d6fa15e01198faef72af07e2a8db851e471" -dependencies = [ - "flate2", - "jpeg-decoder", - "weezl", -] - [[package]] name = "time" version = "0.1.45" diff --git a/Cargo.toml b/Cargo.toml index ec5e8cb..176834e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,8 @@ incremental = false lto = 'fat' opt-level = 3 overflow-checks = false +# Don't need to strip +strip = false # do not optimize proc-macro crates = faster builds from scratch [profile.dev.build-override] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..09ed1c3 --- /dev/null +++ b/Makefile @@ -0,0 +1,59 @@ +# Makefile to build releases and check build reproducibility + +.PHONY: repro release uf2 repro_check +PLATFORM:=ledmatrix +RELEASE_BIN:=target/thumbv6m-none-eabi/release/$(PLATFORM) +TARGET_FOLDER:=target/thumbv6m-none-eabi/release +FIRST_BIN:=$(PLATFORM)_first + +clean: + rm -f $(RELEASE_BIN) + +# Simple reproducibility check +# Run clean build twice +repro: + # First build + cargo clean + $(MAKE) release + + # Back up, so that `cargo clean` won't remove it + cp $(RELEASE_BIN) $(FIRST_BIN) + # Sleep a bit to make sure timestamps are different + sleep 2 + + # Second build + cargo clean + $(MAKE) release + + # Move back into target, so that `cargo clean` can remove it next time + mv $(FIRST_BIN) $(TARGET_FOLDER) + + $(MAKE) repro_check + +repro_check: + # Make sure the username wasn't embedded + ! strings $(RELEASE_BIN) | grep $(shell whoami) + + # Check that both binaries are equivalent + sha256sum $(RELEASE_BIN) $(TARGET_FOLDER)/$(FIRST_BIN) + cmp $(RELEASE_BIN) $(TARGET_FOLDER)/$(FIRST_BIN) + +release: $(RELEASE_BIN) + +uf2: $(RELEASE_BIN) + elf2uf2-rs target/thumbv6m-none-eabi/release/$(PLATFORM) $(PLATFORM).uf2 + ls -lh $(PLATFORM).uf2 + sha256sum $(PLATFORM).uf2 + + +# Build release binary +# Need to remap paths to avoid local absolute paths being embedded in the binary +$(RELEASE_BIN): + # Need to provide the rustflags defined in .cargo/config.toml again because + # setting the environment variable overrides them + env \ + RUSTFLAGS="--remap-path-prefix=$$PWD=. --remap-path-prefix=$$CARGO_HOME=home --remap-path-prefix=$$HOME=home -C link-arg=--nmagic -C link-arg=-Tlink.x -C link-arg=-Tdefmt.x -C linker=flip-link -C inline-threshold=5 -C no-vectorize-loops" \ + cargo build --release -p $(PLATFORM) + + ls -lh $(RELEASE_BIN) + sha256sum $(RELEASE_BIN) diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..5ce400b --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.69.0" +targets = ["thumbv6m-none-eabi"] +components = ["clippy", "rustfmt"]