default.nix 1.55 KB
Newer Older
Astro's avatar
Astro committed
1
2
3
4
5
6
let
  mozillaOverlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
  pkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; };
in
with pkgs;
let
Astro's avatar
Astro committed
7
  rust = rustChannelOfTargets "nightly" null [ "thumbv7em-none-eabi" ];
Astro's avatar
Astro committed
8
9
10
11
  rustPlatform = makeRustPlatform {
    rustc = rust;
    cargo = rust;
  };
Astro's avatar
updates    
Astro committed
12
13
14
15
16
17
18
19
20
21
22
23
  epic-stubs = stdenv.mkDerivation {
    name = "epic-stubs";
    src = ./c;
    buildInputs = [ gcc python3 ];
    buildPhase = ''
      ${python3}/bin/python epicardium/api/genapi.py -H epicardium/epicardium.h -c client.c -s server.c
    '';
    installPhase = ''
      mkdir $out
      cp client.c server.c $out/
    '';
  };
24
  l0dables = rustPlatform.buildRustPackage rec {
Astro's avatar
Astro committed
25
26
27
    name = "rust-card10";
    version = "0.0.0";
    src = ./.;
Astro's avatar
Astro committed
28
29
    cargoSha256 = "10nims5j9r0d7pcfbbj8ycqxhcx7n07958jvkib29b0sf9c6qh3z";
    buildInputs = [ pkgsCross.arm-embedded.stdenv.cc ];
Astro's avatar
updates    
Astro committed
30
31
32
    prePatch = ''
      cp ${epic-stubs}/client.c l0dable/src/
    '';
Astro's avatar
Astro committed
33
34
35
    NIX_DEBUG=1;
    LIBCLANG_PATH="${llvmPackages.libclang}/lib";
    CARGO_HOME="$(mktemp -d cargo-home.XXX)";
Astro's avatar
updates    
Astro committed
36
    preBuild = ''
Astro's avatar
Astro committed
37
      export CPATH="${glibc_multi.dev}/include:${stdenv.cc.cc}/lib/gcc/$(cc -dumpmachine)/${lib.getVersion pkgsCross.arm-embedded.stdenv.cc.cc}/include"
Astro's avatar
updates    
Astro committed
38
    '';
Astro's avatar
Astro committed
39
40
    doCheck = false;
    installPhase = ''
Astro's avatar
Astro committed
41
      mkdir -p $out/apps
Astro's avatar
Astro committed
42
43
44
45
46
      for f in target/thumbv7em-none-eabi/release/* ; do
        if [ -x $f ] && [ ! -d $f ] ; then
          cp $f $out/apps/$(basename $f).elf
        fi
      done
Astro's avatar
Astro committed
47
48
49
    '';
  };
in {
50
  inherit rust rustPlatform l0dables epic-stubs;
Astro's avatar
Astro committed
51
}