From 92911099d907bd5490b4f1cb57cacdb059422087 Mon Sep 17 00:00:00 2001 From: Harry Ho Date: Tue, 20 Jul 2021 16:33:56 +0800 Subject: [PATCH 1/2] mcu: fix Stabilizer extraCargoBuildArgs not passed to buildStm32Firmware --- mcu/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mcu/default.nix b/mcu/default.nix index 44b05ae..4ca46e0 100644 --- a/mcu/default.nix +++ b/mcu/default.nix @@ -53,10 +53,10 @@ let in pkgs.lib.attrsets.mapAttrs' (name: value: pkgs.lib.attrsets.nameValuePair ("stabilizer-" + name) - (buildStm32Firmware { + (buildStm32Firmware ({ name = "stabilizer-" + name; # If binaryName is not specified, use the attribute name as binaryName by default. - binaryName = if (value ? binaryName) then value.binaryName else name; + binaryName = name; cargoDepsName = "stabilizer"; src = ; patchPhase = '' @@ -67,7 +67,7 @@ in "Ipv4Address::new(192, 168, 1, 1)" ''; doCheck = false; - })) { + } // value))) { dual-iir = {}; dual-iir-pounder_v1_1 = { binaryName = "dual-iir"; -- 2.42.0 From 64bc97bf2a3805a67616e65b33dda6e4b4121f36 Mon Sep 17 00:00:00 2001 From: Harry Ho Date: Tue, 20 Jul 2021 16:38:50 +0800 Subject: [PATCH 2/2] mcu: simplify buildStm32Firmware * binaryName and extraCargoBuildArgs are no longer variadic. * `cargo build` simply always uses binaryName (defaults to the package name) as `--bin` argument. --- mcu/default.nix | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/mcu/default.nix b/mcu/default.nix index 4ca46e0..c6e6cbc 100644 --- a/mcu/default.nix +++ b/mcu/default.nix @@ -8,21 +8,11 @@ let rustPlatform = pkgs.recurseIntoAttrs (pkgs.callPackage ./rustPlatform.nix { inherit rustManifest; }); - buildStm32Firmware = { name, src, cargoDepsName ? name, patchPhase ? "", extraNativeBuildInputs ? [], checkPhase ? "", doCheck ? true, ... } @ args: + buildStm32Firmware = { name, src, cargoDepsName ? name, patchPhase ? "", extraNativeBuildInputs ? [], checkPhase ? "", doCheck ? true, binaryName ? name, extraCargoBuildArgs ? "" }: let cargoSha256Drv = pkgs.runCommand "${name}-cargosha256" { } '' cp "${src}/cargosha256.nix" $out ''; - # If binaryName is specified, - # then pass it as an argument for `cargo build`; otherwise, do not add such argument. - extraCargoBuildArgs = ( - (if (args ? extraCargoBuildArgs) then (args.extraCargoBuildArgs + " ") else "") + - (if (args ? binaryName) then ("--bin " + binaryName) else "") - ); - # If binaryName is specified, - # 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 cargoDepsName; @@ -35,10 +25,12 @@ let nativeBuildInputs = [ pkgs.llvm ] ++ extraNativeBuildInputs; buildPhase = '' export CARGO_HOME=$(mktemp -d cargo-home.XXX) - cargo build --release ${extraCargoBuildArgs} + cargo build --release --bin ${binaryName} ${extraCargoBuildArgs} ''; inherit checkPhase doCheck; + # binaryName defaults to the `name` arg (i.e. the Rust package name); + # it is used as the Cargo binary filename installPhase = '' mkdir -p $out $out/nix-support cp target/thumbv7em-none-eabihf/release/${binaryName} $out/${name}.elf -- 2.42.0