Ada: Difference between revisions

From NixOS Wiki
imported>Blitz
Add a link to an Ada example.
m minor cleanup
Line 3: Line 3:
The GNAT Ada toolchain is fully packaged in NixOS and can be used to build software. It has a bit less convenience than typical C/C++ toolchains due to its small user base. A simple Ada program using GPR can be built as follows:
The GNAT Ada toolchain is fully packaged in NixOS and can be used to build software. It has a bit less convenience than typical C/C++ toolchains due to its small user base. A simple Ada program using GPR can be built as follows:


<syntaxHighlight lang=nix>
<syntaxHighlight lang="nix">
{ stdenv, gnat, gprbuild, glibc }:
{ stdenv, gnat, gprbuild, glibc }:


Line 45: Line 45:
== Building Static Binaries ==
== Building Static Binaries ==


If you try to build static binaries, you need to add the static version of libc manually. For this add <syntaxHighlight lang=nix>glibc</syntaxHighlight> to the derivation parameters (at the top) and add the following to the derivation itself.
If you try to build static binaries, you need to add the static version of libc manually. For this, add <code>glibc</code> to the derivation parameters (at the top) and add the following to the derivation itself.


<syntaxHighlight lang=nix>
<syntaxHighlight lang="nix">
   buildInputs = [
   buildInputs = [
     glibc.static
     glibc.static
Line 53: Line 53:
</syntaxHighlight>
</syntaxHighlight>


There is an example on [https://github.com/blitz/adahello Github].
There is an example on [https://github.com/blitz/adahello GitHub].

Revision as of 18:42, 21 June 2024

Ada / Gnat Support

The GNAT Ada toolchain is fully packaged in NixOS and can be used to build software. It has a bit less convenience than typical C/C++ toolchains due to its small user base. A simple Ada program using GPR can be built as follows:

{ stdenv, gnat, gprbuild, glibc }:

stdenv.mkDerivation {
  pname = "an-ada-program";
  version = "1.2.3";

  src = ...;

  nativeBuildInputs = [
    gprbuild
    gnat
  ];

  dontConfigure = true;

  buildPhase = ''
    runHook preBuild

    gprbuild

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    mkdir -p $out/bin

    # Only install what we need to run the binary.
    gprinstall --prefix=$out hello.gpr \
      --no-project \
      --no-manifest \
      --mode=usage

    runHook postInstall
  '';
}

Building Static Binaries

If you try to build static binaries, you need to add the static version of libc manually. For this, add glibc to the derivation parameters (at the top) and add the following to the derivation itself.

  buildInputs = [
    glibc.static
  ];

There is an example on GitHub.