mcu: fix cargo not building only the specified binary per job

This commit is contained in:
Harry Ho 2021-07-02 15:57:04 +08:00
parent 2835575ee4
commit e43223532c
1 changed files with 7 additions and 1 deletions

View File

@ -19,6 +19,12 @@ let
}.nix" $out }.nix" $out
''; '';
# If binaryName is specified as an arg of buildStm32Firmware, # If binaryName is specified as an arg of buildStm32Firmware,
# 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`; # 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. # otherwise, use the `name` arg (i.e. the Rust package name) as the ELF filename.
binaryName = if (args ? binaryName) then args.binaryName else name; binaryName = if (args ? binaryName) then args.binaryName else name;
@ -34,7 +40,7 @@ let
nativeBuildInputs = [ pkgs.llvm ] ++ extraNativeBuildInputs; nativeBuildInputs = [ pkgs.llvm ] ++ extraNativeBuildInputs;
buildPhase = '' buildPhase = ''
export CARGO_HOME=$(mktemp -d cargo-home.XXX) export CARGO_HOME=$(mktemp -d cargo-home.XXX)
cargo build --release cargo build --release ${extraCargoBuildArgs}
''; '';
inherit checkPhase doCheck; inherit checkPhase doCheck;