comp.lang.ada
 help / color / mirror / Atom feed
From: Felix Krause <contact@flyx.org>
Subject: Getting GNAT GPL 2017 to run on NixOS
Date: Tue, 10 Oct 2017 12:13:45 +0200
Date: 2017-10-10T12:13:45+02:00	[thread overview]
Message-ID: <2017101012134578343-contact@flyx.org> (raw)

NixOS provides a pretty old GNAT version, so I decided to try and 
install AdaCore's GNAT GPL 2017 release.

I came up with the following nix expression which fetches the 64bit 
release from AdaCore, patches the ELF binaries to use the correct 
interpreter for NixOS, and sets some environment variables so that the 
tools find resources:

    { stdenv, fetchurl, patchelf, gnugrep, file, makeWrapper, ncurses5 }:
    stdenv.mkDerivation {
      name = "gnat-gpl-2017";
      src = fetchurl {
        url = "http://mirrors.cdn.adacore.com/art/591c6d80c7a447af2deed1d7";
        sha1 = "9682e2e1f2f232ce03fe21d77b14c37a0de5649b";
      };
      dontBuild = true;
      dontStrip = true;
      unpackCmd = "tar -xzf $curSrc";
      buildInputs = [ gnugrep file patchelf makeWrapper ];
      installPhase = ''
        set -e
        make ins-all prefix="$out"
        for path in 
$out/{bin,libexec/gcc/x86_64-pc-linux-gnu/6.3.1,libexec/gprbuild}/*; do
          if file "$path" | grep -q -i "elf"; then
            echo "Patching $path"
            if file "$path" | grep -q -i "executable"; then
              patchelf --set-interpreter 
"${stdenv.glibc}/lib/ld-linux-x86-64.so.2" "$path"
            fi
            patchelf --set-rpath "${stdenv.glibc}/lib" "$path"
          fi
        done
        mkdir -p $out/share/gnat/bin
        mv $out/bin/* $out/share/gnat/bin
        for path in $out/share/gnat/bin/{gnat,gpr}*; do
          if file "$path" | grep -q -i "elf"; then
            makeWrapper $path $out/bin/$(basename $path) --prefix PATH 
: $out/share/gnat/bin --set GNAT_ROOT $out --set GCC_ROOT $out --set 
LIBRARY_PATH "${stdenv.glibc}/lib"
          fi
        done
        makeWrapper $out/share/gnat/bin/gps $out/bin/gps --prefix PATH 
: $out/share/gnat/bin --set GNAT_ROOT $out --set GCC_ROOT $out --set 
GPS_ROOT $out --prefix LD_LIBRARY_PATH : $out/lib/gps/
      '';
    }

I move all binaries into $out/share/gnat/bin because everything in 
$out/bin would be added to my environment which is undesirable (some 
tools collide with existing ones). Then I create wrappers for all gnat* 
and gpr* tools in $out/bin. The wrapper prepends $out/share/gnat/bin to 
PATH so that the tools can find the accompanying binaries.

So far, so good; this got me a working gnatmake. However, the binary 
gnatmake creates references /lib64/ld-linux-x86-64.so.2 as interpreter 
instead of the correct NixOS interpreter. Is there a way to teach 
gnatmake which interpreter to write into the resulting binary?

I also tried to use gprbuild, which fails with these lines when called 
on an existing project:

    No valid configuration found
    Generation of configuration files failed
    GNAT-TEMP-000001.TMP:1:01: "project" expected
    gprbuild: processing of configuration project 
"/tmp/GNAT-TEMP-000001.TMP" failed

The file in /tmp does not exist (and is not the project I called 
gprbuild with). I am unsure what goes wrong here, any suggestions?

I also did not get GPS to start yet due to a missing libncurses.so.5 
which does not seem to be part of the distribution – strange as 
everything else is bundled. I will try to load NixOS' native ncurses.


-- 
Regards,
Felix Krause


                 reply	other threads:[~2017-10-10 10:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox