Skip to content

Commit

Permalink
Make firmware builds reproducible
Browse files Browse the repository at this point in the history
  • Loading branch information
afilini committed Apr 30, 2024
1 parent 615032a commit 6331f8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions firmware/.cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down

0 comments on commit 6331f8b

Please sign in to comment.