1{ lib, stdenv, fetchFromGitHub, cmake
2, boost, python3, eigen, python3Packages
3, icestorm, trellis
4, llvmPackages
5
6, enableGui ? false
7, wrapQtAppsHook ? null
8, qtbase ? null
9, OpenGL ? null
10}:
11
12let
13 boostPython = boost.override { python = python3; enablePython = true; };
14
15 pname = "nextpnr";
16 version = "0.6";
17
18 main_src = fetchFromGitHub {
19 owner = "YosysHQ";
20 repo = "nextpnr";
21 rev = "${pname}-${version}";
22 hash = "sha256-S6qvTzvkS2tBMvuTpmuCx6h0OcKP5NBbmgRgOpAVtnA=";
23 name = "nextpnr";
24 };
25
26 test_src = fetchFromGitHub {
27 owner = "YosysHQ";
28 repo = "nextpnr-tests";
29 rev = "00c55a9eb9ea2e062b51fe0d64741412b185d95d";
30 sha256 = "sha256-83suMftMtnaRFq3T2/I7Uahb11WZlXhwYt6Q/rqi2Yo=";
31 name = "nextpnr-tests";
32 };
33in
34
35stdenv.mkDerivation rec {
36 inherit pname version;
37
38 srcs = [ main_src test_src ];
39
40 sourceRoot = main_src.name;
41
42 nativeBuildInputs
43 = [ cmake ]
44 ++ (lib.optional enableGui wrapQtAppsHook);
45 buildInputs
46 = [ boostPython python3 eigen python3Packages.apycula ]
47 ++ (lib.optional enableGui qtbase)
48 ++ (lib.optional stdenv.cc.isClang llvmPackages.openmp);
49
50 cmakeFlags =
51 [ "-DCURRENT_GIT_VERSION=${lib.substring 0 7 (lib.elemAt srcs 0).rev}"
52 "-DARCH=generic;ice40;ecp5;gowin"
53 "-DBUILD_TESTS=ON"
54 "-DICESTORM_INSTALL_PREFIX=${icestorm}"
55 "-DTRELLIS_INSTALL_PREFIX=${trellis}"
56 "-DTRELLIS_LIBDIR=${trellis}/lib/trellis"
57 "-DGOWIN_BBA_EXECUTABLE=${python3Packages.apycula}/bin/gowin_bba"
58 "-DUSE_OPENMP=ON"
59 # warning: high RAM usage
60 "-DSERIALIZE_CHIPDBS=OFF"
61 ]
62 ++ (lib.optional enableGui "-DBUILD_GUI=ON")
63 ++ (lib.optional (enableGui && stdenv.isDarwin)
64 "-DOPENGL_INCLUDE_DIR=${OpenGL}/Library/Frameworks");
65
66 patchPhase = with builtins; ''
67 # use PyPy for icestorm if enabled
68 substituteInPlace ./ice40/CMakeLists.txt \
69 --replace ''\'''${PYTHON_EXECUTABLE}' '${icestorm.pythonInterp}'
70 '';
71
72 preBuild = ''
73 ln -s ../${test_src.name} tests
74 '';
75
76 doCheck = true;
77
78 postFixup = lib.optionalString enableGui ''
79 wrapQtApp $out/bin/nextpnr-generic
80 wrapQtApp $out/bin/nextpnr-ice40
81 wrapQtApp $out/bin/nextpnr-ecp5
82 wrapQtApp $out/bin/nextpnr-gowin
83 '';
84
85 meta = with lib; {
86 description = "Place and route tool for FPGAs";
87 homepage = "https://github.com/yosyshq/nextpnr";
88 license = licenses.isc;
89 platforms = platforms.all;
90 maintainers = with maintainers; [ thoughtpolice emily ];
91 };
92}