From 726ee7aa82f812f40f631b7c4e7040d84a1b627a Mon Sep 17 00:00:00 2001 From: Harry Ho Date: Tue, 2 Feb 2021 11:16:24 +0800 Subject: [PATCH] stm32: allow binary filename and package name to be different * The major motivation is that Stabilizer ( since https://github.com/quartiq/stabilizer/commit/f1f15aca65f8fe4677205adff8ef433aa6ba0c1c ) now contains multiple binaries, and the filenames of the generated ELFs (e.g. `dual-iir`, `lockin-internal`) do not necessarily contain the project name as a substring. --- stm32/default.nix | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/stm32/default.nix b/stm32/default.nix index 90dd57e..dd1547e 100644 --- a/stm32/default.nix +++ b/stm32/default.nix @@ -8,9 +8,20 @@ let rustPlatform = pkgs.recurseIntoAttrs (pkgs.callPackage ./rustPlatform.nix { inherit rustManifest; }); - buildStm32Firmware = { name, src, patchPhase ? "", extraNativeBuildInputs ? [], checkPhase ? "" }: + buildStm32Firmware = { name, src, patchPhase ? "", extraNativeBuildInputs ? [], checkPhase ? "", ... } @ args: let - cargoSha256Drv = pkgs.runCommand "${name}-cargosha256" { } ''cp "${src}/cargosha256.nix" $out''; + # If binaryName is specified as an arg of buildStm32Firmware, + # then the .nix containing the cargoSha256 must be named "cargosha256-${binaryName}.nix"; + # otherwise, the .nix must be named "cargosha256.nix". + cargoSha256Drv = pkgs.runCommand "${name}-cargosha256" { } '' + cp "${src}/cargosha256${ + if (args ? binaryName) then "-" + args.binaryName else "" + }.nix" $out + ''; + # If binaryName is specified as an arg of buildStm32Firmware, + # then use it as the filename of the ELF generated from `cargo build`; + # otherwise, use the `name` arg (i.e. the Rust package name) as the ELF filename. + binaryName = if (args ? binaryName) then args.binaryName else name; in rustPlatform.buildRustPackage rec { inherit name; @@ -29,9 +40,9 @@ let inherit checkPhase; installPhase = '' mkdir -p $out $out/nix-support - cp target/thumbv7em-none-eabihf/release/${name} $out/${name}.elf + cp target/thumbv7em-none-eabihf/release/${binaryName} $out/${name}.elf echo file binary-dist $out/${name}.elf >> $out/nix-support/hydra-build-products - llvm-objcopy -O binary target/thumbv7em-none-eabihf/release/${name} $out/${name}.bin + llvm-objcopy -O binary target/thumbv7em-none-eabihf/release/${binaryName} $out/${name}.bin echo file binary-dist $out/${name}.bin >> $out/nix-support/hydra-build-products ''; @@ -40,8 +51,9 @@ let migen = (import ../artiq-fast/pkgs/python-deps.nix { inherit (pkgs) stdenv fetchgit fetchFromGitHub python3Packages; misoc-new = true; }).migen; in { - stabilizer = buildStm32Firmware { - name = "stabilizer"; + stabilizer-dual-iir = buildStm32Firmware { + name = "stabilizer-dual-iir"; + binaryName = "dual-iir"; src = ; patchPhase = '' substituteInPlace src/hardware/configuration.rs \