diff --git a/pkgs/development/compilers/ghdl/expected-output.txt b/pkgs/by-name/gh/ghdl/expected-output.txt similarity index 100% rename from pkgs/development/compilers/ghdl/expected-output.txt rename to pkgs/by-name/gh/ghdl/expected-output.txt diff --git a/pkgs/by-name/gh/ghdl/package.nix b/pkgs/by-name/gh/ghdl/package.nix new file mode 100644 index 000000000000..5125f463e6d9 --- /dev/null +++ b/pkgs/by-name/gh/ghdl/package.nix @@ -0,0 +1,125 @@ +{ stdenv +, fetchFromGitHub +, callPackage +, gnat +, zlib +, llvm +, lib +, gcc-unwrapped +, texinfo +, gmp +, mpfr +, libmpc +, gnutar +, glibc +, makeWrapper +, backend ? "mcode" +}: + +assert backend == "mcode" || backend == "llvm" || backend == "gcc"; + +stdenv.mkDerivation (finalAttrs: { + pname = "ghdl-${backend}"; + version = "4.1.0"; + + src = fetchFromGitHub { + owner = "ghdl"; + repo = "ghdl"; + rev = "v${finalAttrs.version}"; + hash = "sha256-tPSHer3qdtEZoPh9BsEyuTOrXgyENFUyJqnUS3UYAvM="; + }; + + LIBRARY_PATH = "${stdenv.cc.libc}/lib"; + + nativeBuildInputs = [ + gnat + ] ++ lib.optionals (backend == "gcc") [ + texinfo + makeWrapper + ]; + buildInputs = [ + zlib + ] ++ lib.optionals (backend == "llvm") [ + llvm + ] ++ lib.optionals (backend == "gcc") [ + gmp + mpfr + libmpc + ]; + propagatedBuildInputs = [ + ] ++ lib.optionals (backend == "llvm" || backend == "gcc") [ + zlib + ]; + + preConfigure = '' + # If llvm 7.0 works, 7.x releases should work too. + sed -i 's/check_version 7.0/check_version 7/g' configure + '' + lib.optionalString (backend == "gcc") '' + ${gnutar}/bin/tar -xf ${gcc-unwrapped.src} + ''; + + configureFlags = [ + # See https://github.com/ghdl/ghdl/pull/2058 + "--disable-werror" + "--enable-synth" + ] ++ lib.optionals (backend == "llvm") [ + "--with-llvm-config=${llvm.dev}/bin/llvm-config" + ] ++ lib.optionals (backend == "gcc") [ + "--with-gcc=gcc-${gcc-unwrapped.version}" + ]; + + buildPhase = lib.optionalString (backend == "gcc") '' + make copy-sources + mkdir gcc-objs + cd gcc-objs + ../gcc-${gcc-unwrapped.version}/configure \ + --with-native-system-header-dir=/include \ + --with-build-sysroot=${lib.getDev glibc} \ + --prefix=$out \ + --enable-languages=c,vhdl \ + --disable-bootstrap \ + --disable-lto \ + --disable-multilib \ + --disable-libssp \ + --disable-libgomp \ + --disable-libquadmath + make -j $NIX_BUILD_CORES + make install + cd ../ + make -j $NIX_BUILD_CORES ghdllib + ''; + + postFixup = lib.optionalString (backend == "gcc") '' + wrapProgram $out/bin/ghdl \ + --set LIBRARY_PATH ${lib.makeLibraryPath [ + glibc + ]} + ''; + + hardeningDisable = [ + ] ++ lib.optionals (backend == "gcc") [ + # GCC compilation fails with format errors + "format" + ]; + + enableParallelBuilding = true; + + passthru = { + # run with: + # nix-build -A ghdl-mcode.passthru.tests + # nix-build -A ghdl-llvm.passthru.tests + # nix-build -A ghdl-gcc.passthru.tests + tests = { + simple = callPackage ./test-simple.nix { inherit backend; }; + }; + }; + + meta = { + homepage = "https://github.com/ghdl/ghdl"; + description = "VHDL 2008/93/87 simulator"; + license = lib.licenses.gpl2Plus; + mainProgram = "ghdl"; + maintainers = with lib.maintainers; [ lucus16 thoughtpolice ]; + platforms = lib.platforms.linux; + }; +}) diff --git a/pkgs/development/compilers/ghdl/simple-tb.vhd b/pkgs/by-name/gh/ghdl/simple-tb.vhd similarity index 100% rename from pkgs/development/compilers/ghdl/simple-tb.vhd rename to pkgs/by-name/gh/ghdl/simple-tb.vhd diff --git a/pkgs/development/compilers/ghdl/simple.vhd b/pkgs/by-name/gh/ghdl/simple.vhd similarity index 100% rename from pkgs/development/compilers/ghdl/simple.vhd rename to pkgs/by-name/gh/ghdl/simple.vhd diff --git a/pkgs/development/compilers/ghdl/test-simple.nix b/pkgs/by-name/gh/ghdl/test-simple.nix similarity index 72% rename from pkgs/development/compilers/ghdl/test-simple.nix rename to pkgs/by-name/gh/ghdl/test-simple.nix index 8d3c3d3095f2..ae265cfba82c 100644 --- a/pkgs/development/compilers/ghdl/test-simple.nix +++ b/pkgs/by-name/gh/ghdl/test-simple.nix @@ -1,7 +1,7 @@ -{ stdenv, ghdl-llvm, ghdl-mcode, backend }: +{ stdenv, lib, ghdl-llvm, ghdl-mcode, ghdl-gcc, backend }: let - ghdl = if backend == "llvm" then ghdl-llvm else ghdl-mcode; + ghdl = if backend == "llvm" then ghdl-llvm else if backend == "gcc" then ghdl-gcc else ghdl-mcode; in stdenv.mkDerivation { name = "ghdl-test-simple"; @@ -13,7 +13,7 @@ stdenv.mkDerivation { mkdir -p ghdlwork ghdl -a --workdir=ghdlwork --ieee=synopsys simple.vhd simple-tb.vhd ghdl -e --workdir=ghdlwork --ieee=synopsys -o sim-simple tb - '' + (if backend == "llvm" then '' + '' + (if backend == "llvm" || backend == "gcc" then '' ./sim-simple --assert-level=warning > output.txt '' else '' ghdl -r --workdir=ghdlwork --ieee=synopsys tb > output.txt diff --git a/pkgs/development/compilers/ghdl/default.nix b/pkgs/development/compilers/ghdl/default.nix deleted file mode 100644 index 3a28aa03c110..000000000000 --- a/pkgs/development/compilers/ghdl/default.nix +++ /dev/null @@ -1,71 +0,0 @@ -{ stdenv -, fetchFromGitHub -, callPackage -, gnat -, zlib -, llvm -, lib -, backend ? "mcode" -}: - -assert backend == "mcode" || backend == "llvm"; - -stdenv.mkDerivation (finalAttrs: { - pname = "ghdl-${backend}"; - version = "4.1.0"; - - src = fetchFromGitHub { - owner = "ghdl"; - repo = "ghdl"; - rev = "v${finalAttrs.version}"; - hash = "sha256-tPSHer3qdtEZoPh9BsEyuTOrXgyENFUyJqnUS3UYAvM="; - }; - - LIBRARY_PATH = "${stdenv.cc.libc}/lib"; - - nativeBuildInputs = [ - gnat - ]; - buildInputs = [ - zlib - ] ++ lib.optionals (backend == "llvm") [ - llvm - ]; - propagatedBuildInputs = [ - ] ++ lib.optionals (backend == "llvm") [ - zlib - ]; - - preConfigure = '' - # If llvm 7.0 works, 7.x releases should work too. - sed -i 's/check_version 7.0/check_version 7/g' configure - ''; - - configureFlags = [ - # See https://github.com/ghdl/ghdl/pull/2058 - "--disable-werror" - "--enable-synth" - ] ++ lib.optionals (backend == "llvm") [ - "--with-llvm-config=${llvm.dev}/bin/llvm-config" - ]; - - enableParallelBuilding = true; - - passthru = { - # run with either of - # nix-build -A ghdl-mcode.passthru.tests - # nix-build -A ghdl-llvm.passthru.tests - tests = { - simple = callPackage ./test-simple.nix { inherit backend; }; - }; - }; - - meta = { - homepage = "https://github.com/ghdl/ghdl"; - description = "VHDL 2008/93/87 simulator"; - license = lib.licenses.gpl2Plus; - mainProgram = "ghdl"; - maintainers = with lib.maintainers; [ lucus16 thoughtpolice ]; - platforms = lib.platforms.linux; - }; -}) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 87c4cf2733f8..a3b00aebac9d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15666,13 +15666,11 @@ with pkgs; meta.broken = stdenv.hostPlatform.isDarwin; }); - ghdl = ghdl-mcode; + ghdl-mcode = callPackage ../by-name/gh/ghdl/package.nix { backend = "mcode"; }; - ghdl-mcode = callPackage ../development/compilers/ghdl { - backend = "mcode"; - }; + ghdl-gcc = callPackage ../by-name/gh/ghdl/package.nix { backend = "gcc"; }; - ghdl-llvm = callPackage ../development/compilers/ghdl { + ghdl-llvm = callPackage ../by-name/gh/ghdl/package.nix { backend = "llvm"; inherit (llvmPackages_15) llvm; };