Skip to content

WIP: Try to make the firmware build reproducible #39

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

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
79 changes: 36 additions & 43 deletions .github/workflows/firmware.yml
Original file line number Diff line number Diff line change
@@ -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
173 changes: 0 additions & 173 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
59 changes: 59 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "1.69.0"
targets = ["thumbv6m-none-eabi"]
components = ["clippy", "rustfmt"]