zynq-rs/default.nix

63 lines
2.1 KiB
Nix
Raw Normal View History

2019-05-05 20:56:23 +08:00
{ # Use master branch of the overlay by default
mozillaOverlay ? import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz),
rustManifest ? ./channel-rust-nightly.toml,
2019-05-05 20:56:23 +08:00
}:
let
pkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; };
rustcSrc = pkgs.fetchgit {
url = https://github.com/rust-lang/rust.git;
2020-01-26 08:18:57 +08:00
# master of 2020-01-25
rev = "c2d141df59703393c0c683abc259f9a8c3be041a";
sha256 = "0v23ia4sp436yjksbq5m5vdarj481w2z8q3px51kidabdd2282yr";
fetchSubmodules = true;
};
targets = [];
rustChannelOfTargets = _channel: _date: targets:
(pkgs.lib.rustLib.fromManifestFile rustManifest {
inherit (pkgs) stdenv fetchurl patchelf;
}).rust.override { inherit targets; };
2019-05-05 20:56:23 +08:00
rust =
rustChannelOfTargets "nightly" null targets;
rustPlatform = pkgs.recurseIntoAttrs (pkgs.makeRustPlatform {
rustc = rust // { src = rustcSrc; };
2019-05-05 20:56:23 +08:00
cargo = rust;
});
gcc = pkgs.pkgsCross.armv7l-hf-multiplatform.buildPackages.gcc;
2020-01-26 08:45:02 +08:00
xbuildRustPackage = { cargoFeatures, crateSubdir, ... } @ attrs:
let
buildPkg = rustPlatform.buildRustPackage attrs;
in
buildPkg.overrideAttrs ({ name, nativeBuildInputs, ... }: {
2019-09-26 23:54:37 +08:00
nativeBuildInputs =
nativeBuildInputs ++ [ pkgs.cargo-xbuild ];
2019-09-26 23:54:37 +08:00
buildPhase = ''
2020-01-26 08:45:02 +08:00
pushd ${crateSubdir}
cargo xbuild --release --frozen \
--no-default-features \
--features=${cargoFeatures}
popd
2019-09-26 23:54:37 +08:00
'';
XARGO_RUST_SRC = "${rustcSrc}/src";
installPhase = ''
mkdir $out
2020-01-26 08:45:02 +08:00
ls -la target/armv7-none-eabihf/release/
2019-09-26 23:54:37 +08:00
cp target/armv7-none-eabihf/release/${name} $out/${name}.elf
'';
});
2020-01-26 08:50:14 +08:00
xbuildCrate = name: crate: features: xbuildRustPackage rec {
2020-01-26 08:45:02 +08:00
name = "${crate}";
2019-09-26 23:54:37 +08:00
src = ./.;
2020-01-26 08:45:02 +08:00
crateSubdir = crate;
cargoSha256 = "1wvj585vylbjlab7cxbkr4f60km5y7s8knxxvcixmqywdldnh7g2";
cargoFeatures = features;
2019-09-26 23:54:37 +08:00
doCheck = false;
};
2019-05-05 20:56:23 +08:00
in {
2020-01-26 08:45:02 +08:00
inherit pkgs rustPlatform rustcSrc gcc;
zc706 = {
2020-01-26 08:50:14 +08:00
experiments-zc706 = xbuildCrate "experiments-zc706" "experiments" "target_zc706";
experiments-cora = xbuildCrate "experiments-cora" "experiments" "target_cora_z7_10";
2020-01-26 08:45:02 +08:00
};
2019-05-05 20:56:23 +08:00
}