2019-08-21 16:59:58 +08:00
|
|
|
{ # Use master branch of the overlay by default
|
|
|
|
mozillaOverlay ? import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz),
|
2019-10-01 02:43:03 +08:00
|
|
|
rustManifest ? ./channel-rust-nightly.toml,
|
2019-08-21 16:59:58 +08:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
pkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; };
|
|
|
|
in
|
|
|
|
with pkgs;
|
|
|
|
let
|
2019-10-01 02:43:03 +08:00
|
|
|
rustcSrc = pkgs.fetchgit {
|
2019-08-21 16:59:58 +08:00
|
|
|
url = https://github.com/rust-lang/rust.git;
|
2019-11-11 06:01:10 +08:00
|
|
|
# master of 2019-11-09
|
|
|
|
rev = "ac162c6abe34cdf965afc0389f6cefa79653c63b";
|
|
|
|
sha256 = "06c5gws1mrpr69z1gzs358zf7hcsg6ky8n4ha0vv2s9d9w93x1kj";
|
2019-08-21 16:59:58 +08:00
|
|
|
fetchSubmodules = true;
|
|
|
|
};
|
2019-10-01 02:43:03 +08:00
|
|
|
target = "thumbv7em-none-eabihf";
|
|
|
|
targets = [ target ];
|
|
|
|
rustChannelOfTargets = _channel: _date: targets:
|
|
|
|
(pkgs.lib.rustLib.fromManifestFile rustManifest {
|
|
|
|
inherit (pkgs) stdenv fetchurl patchelf;
|
|
|
|
}).rust.override { inherit targets; };
|
2019-08-21 16:59:58 +08:00
|
|
|
rust =
|
|
|
|
rustChannelOfTargets "nightly" null targets;
|
|
|
|
rustPlatform = recurseIntoAttrs (makeRustPlatform {
|
|
|
|
rustc = rust // { src = rustcSrc; };
|
|
|
|
cargo = rust;
|
|
|
|
});
|
2019-10-01 02:43:03 +08:00
|
|
|
gcc = pkgsCross.armv7l-hf-multiplatform.buildPackages.gcc;
|
|
|
|
xbuildRustPackage = attrs:
|
|
|
|
let
|
|
|
|
buildPkg = rustPlatform.buildRustPackage attrs;
|
|
|
|
in
|
|
|
|
buildPkg.overrideAttrs ({ name, nativeBuildInputs, ... }: {
|
|
|
|
nativeBuildInputs =
|
|
|
|
nativeBuildInputs ++ [ cargo-xbuild ];
|
|
|
|
buildPhase = ''
|
|
|
|
cargo xbuild --release --frozen
|
|
|
|
'';
|
|
|
|
XARGO_RUST_SRC = "${rustcSrc}/src";
|
|
|
|
installPhase = ''
|
|
|
|
mkdir $out
|
|
|
|
cp target/${target}/release/${name} $out/${name}.elf
|
|
|
|
'';
|
|
|
|
});
|
|
|
|
firmware = xbuildRustPackage {
|
|
|
|
name = "firmware";
|
|
|
|
src = ./firmware;
|
2019-11-14 02:46:14 +08:00
|
|
|
cargoSha256 = "0lf8h5g8sas36cxzqy0p65qqivnihh4gn4mkc1k210xp7niaymc5";
|
2019-10-01 02:43:03 +08:00
|
|
|
nativeBuildInputs = [
|
|
|
|
gcc
|
|
|
|
];
|
|
|
|
"CC_${target}" = "${gcc}/bin/armv7l-unknown-linux-gnueabihf-gcc";
|
|
|
|
RUST_COMPILER_RT_ROOT = "${rustcSrc}/src/llvm-project/compiler-rt";
|
2019-10-03 03:30:44 +08:00
|
|
|
checkPhase = ''
|
|
|
|
cargo test --target=${hostPlatform.config}
|
|
|
|
'';
|
2019-10-01 02:43:03 +08:00
|
|
|
};
|
2019-08-21 16:59:58 +08:00
|
|
|
in {
|
2019-10-01 02:43:03 +08:00
|
|
|
inherit pkgs rustPlatform rustcSrc gcc firmware;
|
2019-08-21 16:59:58 +08:00
|
|
|
}
|