about summary refs log tree commit diff
path: root/pkgs/development/compilers/silice/default.nix
blob: fd3d0ba1538db73629d36bcb21f5cc9d7a1f1c31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{ stdenv, fetchFromGitHub, lib
, cmake, pkg-config, openjdk
, libuuid, python3
, glfw
, yosys, nextpnr, verilator
, dfu-util, icestorm, trellis
, unstableGitUpdater
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "silice";
  version = "0-unstable-2024-06-23";

  src = fetchFromGitHub {
    owner = "sylefeb";
    repo = "silice";
    rev = "5ba9ef0d03b3c8d4a43efe10acfb51c97d3679ef";
    hash = "sha256-LrLUaCpwzaxH02TGyEfARIumPi0s2REc1g79fSxJjFc=";
    fetchSubmodules = true;
  };

  nativeBuildInputs = [
    cmake
    pkg-config
    openjdk
    glfw
  ];
  buildInputs = [
    libuuid
  ];
  propagatedBuildInputs = [
    (python3.withPackages (p: [
      p.edalize
      p.termcolor
    ]))
  ];

  postPatch = ''
    patchShebangs antlr/antlr.sh
    # use nixpkgs version
    rm -r python/pybind11
  '';

  installPhase = ''
    runHook preInstall

    make install
    mkdir -p $out
    cp -ar ../{bin,frameworks,lib} $out/

    runHook postInstall
  '';

  passthru.tests =
    let
      silice = finalAttrs.finalPackage;
      testProject = project: stdenv.mkDerivation {
        name = "${silice.name}-test-${project}";
        nativeBuildInputs = [
          silice
          yosys
          nextpnr
          verilator
          dfu-util
          icestorm
          trellis
        ];
        src = "${silice.src}/projects";
        sourceRoot = "projects/${project}";
        buildPhase = ''
          targets=()
          for target in $(cat configs | tr -d '\r') ; do
            [[ $target != Makefile* ]] || continue
            make $target ARGS="--no_program"
            targets+=($target)
          done
          if test "''${#targets[@]}" -eq 0; then
            >&2 echo "ERROR: no target found!"
            false
          fi
        '';
        installPhase = ''
          mkdir $out
          for target in "''${targets[@]}" ; do
            [[ $target != Makefile* ]] || continue
          done
        '';
      };
    in {
      # a selection of test projects that build with the FPGA tools in
      # nixpkgs
      audio_sdcard_streamer = testProject "audio_sdcard_streamer";
      bram_interface = testProject "bram_interface";
      blinky = testProject "blinky";
      pipeline_sort = testProject "pipeline_sort";
    };

  passthru.updateScript = unstableGitUpdater { };

  meta = {
    description = "Open source language that simplifies prototyping and writing algorithms on FPGA architectures";
    homepage = "https://github.com/sylefeb/Silice";
    license = lib.licenses.bsd2;
    mainProgram = "silice";
    maintainers = with lib.maintainers; [
      astro
      pbsds
    ];
    platforms = lib.platforms.all;
  };
})