mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-25 15:13:46 +00:00
c3c4ef859a
GPRbuild is a multi language build system developed by AdaCore which is mostly used for build Ada-related projects using GNAT. Since GPRbuild is used to build itself and its dependency library XML/Ada we first build a bootstrap version of it using the provided bash build script bootstrap.sh as the gprbuild-boot derivation. gprbuild-boot is then used to build xmlada and the proper gprbuild derivation. GPRbuild has its own search path mechanism via GPR_PROJECT_PATH which we address via a setupHook. It currently works quite similar to the pkg-config one: It accumulates all inputs into GPR_PROJECT_PATH, GPR_PROJECT_PATH_FOR_BUILD etc. However this is quite limited at the moment as we don't have a gprbuild wrapper yet which understands the _FOR_BUILD suffix. However, we'll need to address this in the future as it is currently basically impossible to test since the distinction only affects cross-compilation, but it is not possible to build a GNAT cross-compiler in nixpkgs at the moment (I'm working on changing that, however). Another issue we had to solve was GPRbuild not finding the right GNAT via its gprconfig tool: GPRbuild has a knowledge base with compiler definitions which run some checks and collect info about binaries which are in PATH. In the end the first compiler in PATH that supports the desired language is selected. We want GPRbuild to discover our wrapped GNAT since the unwrapped one is incapable of producing working binaries since it won't find the crt*.o objects distributed with libc. GPRbuild however needs to find the Ada runtime distributed with GNAT which is not part of the wrapper derivation, so it will skip the wrapper and select the unwrapped GNAT. Symlinking the unwrapped's lib directory into the wrapper fixes this problem, but breaks linking in some cases (e. g. when linking against OMP from gcc, the runtime variant will shadow the problem dynamic lib from buildInputs). Additionally it uses gnatls as an indicator it has found GNAT which is not part of the wrapper. The solution we opted to adopt here is to install a custom compiler description into gprbuild's knowledge base which properly detects the nixpkgs GNAT wrapper: It uses gnatmake to detect GNAT instead of gnatls and discovers the runtime via a symlink we add to `$out/nix-support`. This additional definition is enough to properly detect GNAT, since the plain wrapped gcc detection works out of the box. It may, however, be necessary to add special definitions for other languages in the future where gprbuild also needs to discover the runtime. One future improvement would be to install libgpr into a separate output or split it into a separate derivation (which would require to link gprbuild statically always since otherwise we end up with a cyclical dependency).
66 lines
1.5 KiB
Nix
66 lines
1.5 KiB
Nix
{ lib
|
|
, stdenv
|
|
, fetchFromGitHub
|
|
, fetchpatch
|
|
, gprbuild-boot
|
|
, which
|
|
, gnat
|
|
, xmlada
|
|
}:
|
|
|
|
stdenv.mkDerivation {
|
|
pname = "gprbuild";
|
|
|
|
# See ./boot.nix for an explanation of the gprbuild setupHook,
|
|
# our custom knowledge base entry and the situation wrt a
|
|
# (future) gprbuild wrapper.
|
|
inherit (gprbuild-boot)
|
|
version
|
|
src
|
|
setupHook
|
|
meta
|
|
;
|
|
|
|
nativeBuildInputs = [
|
|
gnat
|
|
gprbuild-boot
|
|
which
|
|
];
|
|
|
|
propagatedBuildInputs = [
|
|
xmlada
|
|
];
|
|
|
|
makeFlags = [
|
|
"ENABLE_SHARED=${if stdenv.hostPlatform.isStatic then "no" else "yes"}"
|
|
"PROCESSORS=$(NIX_BUILD_CORES)"
|
|
# confusingly, for gprbuild --target is autoconf --host
|
|
"TARGET=${stdenv.hostPlatform.config}"
|
|
"prefix=${placeholder "out"}"
|
|
] ++ lib.optionals (!stdenv.hostPlatform.isStatic) [
|
|
"LIBRARY_TYPE=relocatable"
|
|
];
|
|
|
|
# Fixes gprbuild being linked statically always
|
|
patches = lib.optional (!stdenv.hostPlatform.isStatic) (fetchpatch {
|
|
name = "gprbuild-relocatable-build.patch";
|
|
url = "https://aur.archlinux.org/cgit/aur.git/plain/relocatable-build.patch?h=gprbuild&id=1d4e8a5cb982e79135a0aaa3ef87654bed1fe4f0";
|
|
sha256 = "1r3xsp1pk9h666mm8mdravkybmd5gv2f751x2ffb1kxnwq1rwiyn";
|
|
});
|
|
|
|
buildFlags = [ "all" "libgpr.build" ];
|
|
|
|
installFlags = [ "all" "libgpr.install" ];
|
|
|
|
# link gprconfig_kb db from gprbuild-boot into build dir,
|
|
# the install process copies its contents to $out
|
|
preInstall = ''
|
|
ln -sf ${gprbuild-boot}/share/gprconfig share/gprconfig
|
|
'';
|
|
|
|
# no need for the install script
|
|
postInstall = ''
|
|
rm $out/doinstall
|
|
'';
|
|
}
|