forked from M-Labs/nix-scripts
stm32: allow binary filename and package name to be different
* The major motivation is that Stabilizer ( since f1f15aca65
) 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.
This commit is contained in:
parent
21f5362b6f
commit
726ee7aa82
|
@ -8,9 +8,20 @@ let
|
||||||
rustPlatform = pkgs.recurseIntoAttrs (pkgs.callPackage ./rustPlatform.nix {
|
rustPlatform = pkgs.recurseIntoAttrs (pkgs.callPackage ./rustPlatform.nix {
|
||||||
inherit rustManifest;
|
inherit rustManifest;
|
||||||
});
|
});
|
||||||
buildStm32Firmware = { name, src, patchPhase ? "", extraNativeBuildInputs ? [], checkPhase ? "" }:
|
buildStm32Firmware = { name, src, patchPhase ? "", extraNativeBuildInputs ? [], checkPhase ? "", ... } @ args:
|
||||||
let
|
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
|
in
|
||||||
rustPlatform.buildRustPackage rec {
|
rustPlatform.buildRustPackage rec {
|
||||||
inherit name;
|
inherit name;
|
||||||
|
@ -29,9 +40,9 @@ let
|
||||||
inherit checkPhase;
|
inherit checkPhase;
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out $out/nix-support
|
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
|
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
|
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;
|
migen = (import ../artiq-fast/pkgs/python-deps.nix { inherit (pkgs) stdenv fetchgit fetchFromGitHub python3Packages; misoc-new = true; }).migen;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
stabilizer = buildStm32Firmware {
|
stabilizer-dual-iir = buildStm32Firmware {
|
||||||
name = "stabilizer";
|
name = "stabilizer-dual-iir";
|
||||||
|
binaryName = "dual-iir";
|
||||||
src = <stabilizerSrc>;
|
src = <stabilizerSrc>;
|
||||||
patchPhase = ''
|
patchPhase = ''
|
||||||
substituteInPlace src/hardware/configuration.rs \
|
substituteInPlace src/hardware/configuration.rs \
|
||||||
|
|
Loading…
Reference in New Issue