From 6331f8b56c78ab7d5e419e4c88d362221b1b015f Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Mon, 29 Apr 2024 21:36:27 +0200 Subject: [PATCH] Make firmware builds reproducible --- .github/workflows/ci.yml | 3 ++- firmware/.cargo/config | 4 ++-- flake.nix | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d49df5..bc9088a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,7 +81,8 @@ jobs: ./target ./firmware/target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - run: nix develop .#embedded --command bash -c "cd firmware && cargo build --no-default-features --features ${{ matrix.target }} --release" + - run: nix develop .#embedded-reproducible --command bash -c "cd firmware && cargo build --no-default-features --features ${{ matrix.target }} --release" + - run: sha256sum ./firmware/target/thumbv7em-none-eabihf/release/firmware - uses: actions/upload-artifact@v2 with: name: firmware-${{ matrix.target }} diff --git a/firmware/.cargo/config b/firmware/.cargo/config index 033b16e..318df6a 100644 --- a/firmware/.cargo/config +++ b/firmware/.cargo/config @@ -4,9 +4,9 @@ target = "thumbv7em-none-eabihf" rustflags = [ # use the Tlink.x scrip from the cortex-m-rt crate - "-C", "link-arg=-Tlink.x", + "-C", "link-arg=-Tlink.x" # Use v0 symbol mangling style (https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html). This allows recovering the full monomorphized type from the symbol name - "-C", "symbol-mangling-version=v0" + # "-C", "symbol-mangling-version=v0" ] # Doesn't seem to work but let's keep it here so we can find it when needed diff --git a/flake.nix b/flake.nix index d4fb3b3..b2bfded 100644 --- a/flake.nix +++ b/flake.nix @@ -75,7 +75,7 @@ }; defaultDeps = with pkgs; [ cmake SDL2 fltk pango rust-analyzer pkg-config libusb ]; - embeddedDeps = with pkgs; [ probe-rs gcc-arm-embedded qemu gdb openocd clang (getRust { withEmbedded = true; }) ]; + embeddedDeps = with pkgs; [ probe-rs gcc-arm-embedded qemu gdb openocd clang_17 (getRust { withEmbedded = true; }) ]; androidDeps = with pkgs; [ cargo-ndk jdk gnupg (getRust { fullAndroid = true; }) ]; iosDeps = with pkgs; [ (getRust { withIos = true; }) ]; in @@ -89,6 +89,19 @@ CC_thumbv7em_none_eabihf = "${pkgs.gcc-arm-embedded}/bin/arm-none-eabi-gcc"; }; + devShells.embedded-reproducible = pkgs.mkShell { + buildInputs = defaultDeps ++ embeddedDeps; + + + shellHook = '' + export MAIN_DIR=$PWD + + export CRATE_CC_NO_DEFAULTS="true" + export CC_thumbv7em_none_eabihf="clang-17" + export CFLAGS_thumbv7em_none_eabihf="-fno-PIC -fno-stack-protector -v -frandom-seed=22 -I${pkgs.clang_17}/resource-root/include/ -I${pkgs.gcc-arm-embedded}/arm-none-eabi/include -target thumbv7em-none-eabihf -ffile-prefix-map=$HOME/.cargo=" + export RUSTFLAGS="-Clink-arg=-Tlink.x --remap-path-prefix $HOME/.cargo= --remap-path-prefix $MAIN_DIR/firmware=firmware --remap-path-prefix $MAIN_DIR/model=model --remap-path-prefix $MAIN_DIR/gui=gui"; + ''; + }; devShells.android = pkgs.mkShell rec { buildInputs = defaultDeps ++ androidDeps;