From d3b4ce4f68fd66567e0b3e5594a30c92941b20ed Mon Sep 17 00:00:00 2001 From: sempiternal-aurora <78790545+sempiternal-aurora@users.noreply.github.com> Date: Fri, 5 Jun 2026 17:09:08 +1000 Subject: [PATCH] ghdl-llvm-jit: init at 6.0.0 Add the new backend added to ghdl in 5.0.1. Also cleanup the various code, and fix the platforms now that gnat may soon be available on aarch64-linux. Furthermore, sets the default ghdl backend to "llvm-jit" on aarch64 platforms, as mcode doesn't build there, and llvm-jit has the same compile and run in memory structure so it should be a drop in replacement. --- pkgs/by-name/gh/ghdl/package.nix | 45 +++++++++++++++++++--------- pkgs/by-name/gh/ghdl/test-simple.nix | 7 +++-- pkgs/top-level/all-packages.nix | 2 ++ 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/pkgs/by-name/gh/ghdl/package.nix b/pkgs/by-name/gh/ghdl/package.nix index b4f754b8e423..3f843bafb4da 100644 --- a/pkgs/by-name/gh/ghdl/package.nix +++ b/pkgs/by-name/gh/ghdl/package.nix @@ -13,11 +13,21 @@ libmpc, gnutar, makeWrapper, - backend ? "mcode", + backend ? if stdenv.hostPlatform.isAarch64 then "llvm-jit" else "mcode", }: -assert backend == "mcode" || backend == "llvm" || backend == "gcc"; +assert lib.asserts.assertOneOf "backend" backend [ + "mcode" + "llvm" + "llvm-jit" + "gcc" +]; +let + backendIsLLVM = backend == "llvm"; + backendIsLLVMJit = backend == "llvm-jit"; + backendIsGCC = backend == "gcc"; +in stdenv.mkDerivation (finalAttrs: { pname = "ghdl-${backend}"; version = "6.0.0"; @@ -37,17 +47,17 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ gnat ] - ++ lib.optionals (backend == "llvm" || backend == "gcc") [ + ++ lib.optionals (backendIsLLVM || backendIsGCC) [ makeWrapper ] - ++ lib.optionals (backend == "gcc") [ + ++ lib.optionals backendIsGCC [ texinfo ]; buildInputs = [ zlib ] - ++ lib.optionals (backend == "gcc") [ + ++ lib.optionals backendIsGCC [ gmp mpfr libmpc @@ -57,7 +67,7 @@ stdenv.mkDerivation (finalAttrs: { # 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") '' + + lib.optionalString backendIsGCC '' ${gnutar}/bin/tar -xf ${gcc13.cc.src} ''; @@ -66,14 +76,17 @@ stdenv.mkDerivation (finalAttrs: { "--disable-werror" "--enable-synth" ] - ++ lib.optionals (backend == "llvm") [ + ++ lib.optionals (backendIsLLVM || backendIsLLVMJit) [ "--with-llvm-config=${llvm.dev}/bin/llvm-config" ] - ++ lib.optionals (backend == "gcc") [ + ++ lib.optionals backendIsLLVMJit [ + "--with-llvm-jit" + ] + ++ lib.optionals backendIsGCC [ "--with-gcc=gcc-${gcc13.cc.version}" ]; - buildPhase = lib.optionalString (backend == "gcc") '' + buildPhase = lib.optionalString backendIsGCC '' make copy-sources mkdir gcc-objs cd gcc-objs @@ -93,14 +106,14 @@ stdenv.mkDerivation (finalAttrs: { --with-mpfr-include=${mpfr.dev}/include \ --with-mpfr-lib=${mpfr.out}/lib \ --with-mpc=${libmpc} \ - --enable-default-pie=${if stdenv.targetPlatform.hasSharedLibraries then "yes" else "no"} + --enable-default-pie=${lib.boolToYesNo stdenv.targetPlatform.hasSharedLibraries} make -j $NIX_BUILD_CORES make install cd ../ make -j $NIX_BUILD_CORES ghdllib ''; - postFixup = lib.optionalString (backend == "llvm" || backend == "gcc") '' + postFixup = lib.optionalString (backendIsLLVM || backendIsGCC) '' wrapProgram $out/bin/ghdl \ --set LIBRARY_PATH ${lib.makeLibraryPath [ zlib ]} \ --prefix PATH : ${lib.makeBinPath [ stdenv.cc ]} @@ -108,7 +121,7 @@ stdenv.mkDerivation (finalAttrs: { hardeningDisable = [ ] - ++ lib.optionals (backend == "gcc") [ + ++ lib.optionals backendIsGCC [ # GCC compilation fails with format errors "format" ]; @@ -135,7 +148,11 @@ stdenv.mkDerivation (finalAttrs: { thoughtpolice sempiternal-aurora ]; - platforms = - lib.platforms.linux ++ lib.optionals (backend == "mcode" || backend == "llvm") [ "x86_64-darwin" ]; + platforms = [ + "x86_64-linux" + "x86_64-darwin" + ] + ++ lib.optionals (backendIsLLVM || backendIsLLVMJit || backendIsGCC) [ "aarch64-linux" ] + ++ lib.optionals (backendIsLLVM || backendIsLLVMJit) [ "aarch64-darwin" ]; }; }) diff --git a/pkgs/by-name/gh/ghdl/test-simple.nix b/pkgs/by-name/gh/ghdl/test-simple.nix index f83891172d28..341e141823fd 100644 --- a/pkgs/by-name/gh/ghdl/test-simple.nix +++ b/pkgs/by-name/gh/ghdl/test-simple.nix @@ -1,6 +1,7 @@ { - stdenv, + stdenvNoCC, ghdl-llvm, + ghdl-llvm-jit, ghdl-mcode, ghdl-gcc, backend, @@ -10,12 +11,14 @@ let ghdl = if backend == "llvm" then ghdl-llvm + else if backend == "llvm-jit" then + ghdl-llvm-jit else if backend == "gcc" then ghdl-gcc else ghdl-mcode; in -stdenv.mkDerivation { +stdenvNoCC.mkDerivation { name = "ghdl-test-simple"; meta.timeout = 300; nativeBuildInputs = [ ghdl ]; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index cdbd50d537e5..eaf25f21810c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3707,6 +3707,8 @@ with pkgs; ghdl-llvm = ghdl.override { backend = "llvm"; }; + ghdl-llvm-jit = ghdl.override { backend = "llvm-jit"; }; + gcc-arm-embedded = gcc-arm-embedded-15; # Haskell and GHC