nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 stdenv,
3 fetchFromGitHub,
4 callPackage,
5 gnat,
6 zlib,
7 llvm,
8 lib,
9 gcc-unwrapped,
10 texinfo,
11 gmp,
12 mpfr,
13 libmpc,
14 gnutar,
15 glibc,
16 makeWrapper,
17 backend ? "mcode",
18}:
19
20assert backend == "mcode" || backend == "llvm" || backend == "gcc";
21
22stdenv.mkDerivation (finalAttrs: {
23 pname = "ghdl-${backend}";
24 version = "5.1.1";
25
26 src = fetchFromGitHub {
27 owner = "ghdl";
28 repo = "ghdl";
29 rev = "v${finalAttrs.version}";
30 hash = "sha256-vPeODNTptxIjN6qLoIHaKOFf3P3iAK2GloVreHPaAz8=";
31 };
32
33 LIBRARY_PATH = "${stdenv.cc.libc}/lib";
34
35 nativeBuildInputs = [
36 gnat
37 ]
38 ++ lib.optionals (backend == "gcc") [
39 texinfo
40 makeWrapper
41 ];
42 buildInputs = [
43 zlib
44 ]
45 ++ lib.optionals (backend == "llvm") [
46 llvm
47 ]
48 ++ lib.optionals (backend == "gcc") [
49 gmp
50 mpfr
51 libmpc
52 ];
53 propagatedBuildInputs = [
54 ]
55 ++ lib.optionals (backend == "llvm" || backend == "gcc") [
56 zlib
57 ];
58
59 preConfigure = ''
60 # If llvm 7.0 works, 7.x releases should work too.
61 sed -i 's/check_version 7.0/check_version 7/g' configure
62 ''
63 + lib.optionalString (backend == "gcc") ''
64 ${gnutar}/bin/tar -xf ${gcc-unwrapped.src}
65 '';
66
67 configureFlags = [
68 # See https://github.com/ghdl/ghdl/pull/2058
69 "--disable-werror"
70 "--enable-synth"
71 ]
72 ++ lib.optionals (backend == "llvm") [
73 "--with-llvm-config=${llvm.dev}/bin/llvm-config"
74 ]
75 ++ lib.optionals (backend == "gcc") [
76 "--with-gcc=gcc-${gcc-unwrapped.version}"
77 ];
78
79 buildPhase = lib.optionalString (backend == "gcc") ''
80 make copy-sources
81 mkdir gcc-objs
82 cd gcc-objs
83 ../gcc-${gcc-unwrapped.version}/configure \
84 --with-native-system-header-dir=/include \
85 --with-build-sysroot=${lib.getDev glibc} \
86 --prefix=$out \
87 --enable-languages=c,vhdl \
88 --disable-bootstrap \
89 --disable-lto \
90 --disable-multilib \
91 --disable-libssp \
92 --disable-libgomp \
93 --disable-libquadmath
94 make -j $NIX_BUILD_CORES
95 make install
96 cd ../
97 make -j $NIX_BUILD_CORES ghdllib
98 '';
99
100 postFixup = lib.optionalString (backend == "gcc") ''
101 wrapProgram $out/bin/ghdl \
102 --set LIBRARY_PATH ${
103 lib.makeLibraryPath [
104 glibc
105 ]
106 }
107 '';
108
109 hardeningDisable = [
110 ]
111 ++ lib.optionals (backend == "gcc") [
112 # GCC compilation fails with format errors
113 "format"
114 ];
115
116 enableParallelBuilding = true;
117
118 passthru = {
119 # run with:
120 # nix-build -A ghdl-mcode.passthru.tests
121 # nix-build -A ghdl-llvm.passthru.tests
122 # nix-build -A ghdl-gcc.passthru.tests
123 tests = {
124 simple = callPackage ./test-simple.nix { inherit backend; };
125 };
126 };
127
128 meta = {
129 homepage = "https://github.com/ghdl/ghdl";
130 description = "VHDL 2008/93/87 simulator";
131 license = lib.licenses.gpl2Plus;
132 mainProgram = "ghdl";
133 maintainers = with lib.maintainers; [
134 lucus16
135 thoughtpolice
136 ];
137 platforms =
138 lib.platforms.linux ++ lib.optionals (backend == "mcode" || backend == "llvm") [ "x86_64-darwin" ];
139 };
140})