zynq-rs/default.nix

64 lines
2.2 KiB
Nix
Raw Permalink 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-04-25 08:03:57 +08:00
# master of 2020-04-25
2020-04-25 08:16:33 +08:00
rev = "14b15521c52549ebbb113173b4abecd124b5a823";
sha256 = "0a6bi8g636cajpdrpcfkpza95b7ss7041m9cs6hxcd7h8bf6xhwi";
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;
2020-08-03 14:59:49 +08:00
cargoSha256 = "1c1qpg9by8bg93yhgllb5xs155g27qmh99pbrb681wazm8k7nwim";
2020-01-26 08:45:02 +08:00
cargoFeatures = features;
2019-09-26 23:54:37 +08:00
doCheck = false;
dontFixup = true;
2019-09-26 23:54:37 +08:00
};
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
}