diff options
author | Thomas Heijligen <src@posteo.de> | 2024-02-19 20:17:42 +0000 |
---|---|---|
committer | sternenseemann <sternenseemann@systemli.org> | 2024-02-25 18:19:50 +0100 |
commit | f2a142727cc0fbc92a9b420567418df9dd36e568 (patch) | |
tree | b682a81e81f481982046e52f820210c5549933a0 /pkgs/development/ada-modules | |
parent | c02503b58237072965308415f87e709af128516c (diff) |
gnatPackages: Add scope for all ada packages
Ada depencencies musst be build with the same gnat version as the project. Use a namespace as preperation to build with different gnat versions. gprbuild and gnatprove are still globaly visable.
Diffstat (limited to 'pkgs/development/ada-modules')
11 files changed, 622 insertions, 0 deletions
diff --git a/pkgs/development/ada-modules/gnatcoll/bindings.nix b/pkgs/development/ada-modules/gnatcoll/bindings.nix new file mode 100644 index 0000000000000..c8896c14c32f9 --- /dev/null +++ b/pkgs/development/ada-modules/gnatcoll/bindings.nix @@ -0,0 +1,89 @@ +{ stdenv +, lib +, fetchFromGitHub +, gnat +, gprbuild +, gnatcoll-core +, component +# component dependencies +, gmp +, libiconv +, xz +, gcc-unwrapped +, readline +, zlib +, python3 +, ncurses +, darwin +}: + +let + # omit python (2.7), no need to introduce a + # dependency on an EOL package for no reason + libsFor = { + iconv = [ libiconv ]; + gmp = [ gmp ]; + lzma = [ xz ]; + readline = [ readline ]; + python3 = [ python3 ncurses ]; + syslog = [ ]; + zlib = [ zlib ]; + }; +in + + +stdenv.mkDerivation rec { + pname = "gnatcoll-${component}"; + version = "24.0.0"; + + src = fetchFromGitHub { + owner = "AdaCore"; + repo = "gnatcoll-bindings"; + rev = "v${version}"; + sha256 = "00aakpmr67r72l1h3jpkaw83p1a2mjjvfk635yy5c1nss3ji1qjm"; + }; + + nativeBuildInputs = [ + gprbuild + gnat + python3 + ]; + + buildInputs = lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.CoreFoundation + ]; + + # propagate since gprbuild needs to find referenced .gpr files + # and all dependency C libraries when statically linking a + # downstream executable. + propagatedBuildInputs = [ + gnatcoll-core + ] ++ libsFor."${component}" or []; + + # explicit flag for GPL acceptance because upstreams + # allows a gcc runtime exception for all bindings + # except for readline (since it is GPL w/o exceptions) + buildFlags = lib.optionals (component == "readline") [ + "--accept-gpl" + ]; + + buildPhase = '' + runHook preBuild + ${python3.interpreter} ${component}/setup.py build --prefix $out $buildFlags + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + ${python3.interpreter} ${component}/setup.py install --prefix $out + runHook postInstall + ''; + + meta = with lib; { + description = "GNAT Components Collection - Bindings to C libraries"; + homepage = "https://github.com/AdaCore/gnatcoll-bindings"; + license = licenses.gpl3Plus; + platforms = platforms.all; + maintainers = [ maintainers.sternenseemann ]; + }; +} diff --git a/pkgs/development/ada-modules/gnatcoll/core.nix b/pkgs/development/ada-modules/gnatcoll/core.nix new file mode 100644 index 0000000000000..7fdd4e99d550b --- /dev/null +++ b/pkgs/development/ada-modules/gnatcoll/core.nix @@ -0,0 +1,47 @@ +{ stdenv +, lib +, gnat +, gprbuild +, fetchFromGitHub +, xmlada +, which +}: + +stdenv.mkDerivation rec { + pname = "gnatcoll-core"; + version = "24.0.0"; + + src = fetchFromGitHub { + owner = "AdaCore"; + repo = "gnatcoll-core"; + rev = "v${version}"; + sha256 = "1cks2w0inj9hvamsdxjriwxnx1igmx2khhr6kwxshsl30rs8nzvb"; + }; + + nativeBuildInputs = [ + gprbuild + which + gnat + ]; + + # propagate since gprbuild needs to find + # referenced GPR project definitions + propagatedBuildInputs = [ + gprbuild # libgpr + ]; + + makeFlags = [ + "prefix=${placeholder "out"}" + "PROCESSORS=$(NIX_BUILD_CORES)" + # confusingly, for gprbuild --target is autoconf --host + "TARGET=${stdenv.hostPlatform.config}" + ]; + + meta = with lib; { + homepage = "https://github.com/AdaCore/gnatcoll-core"; + description = "GNAT Components Collection - Core packages"; + license = licenses.gpl3Plus; + maintainers = [ maintainers.sternenseemann ]; + platforms = platforms.all; + }; +} diff --git a/pkgs/development/ada-modules/gnatcoll/db.nix b/pkgs/development/ada-modules/gnatcoll/db.nix new file mode 100644 index 0000000000000..6eacff1ddb82f --- /dev/null +++ b/pkgs/development/ada-modules/gnatcoll/db.nix @@ -0,0 +1,107 @@ +{ stdenv +, lib +, fetchFromGitHub +, gnat +, gprbuild +, which +, gnatcoll-core +, xmlada +, component +# components built by this derivation other components depend on +, gnatcoll-sql +, gnatcoll-sqlite +, gnatcoll-xref +# component specific extra dependencies +, gnatcoll-iconv +, gnatcoll-readline +, sqlite +, postgresql +}: + +let + libsFor = { + gnatcoll_db2ada = [ + gnatcoll-sql + ]; + gnatinspect = [ + gnatcoll-sqlite + gnatcoll-readline + gnatcoll-xref + ]; + postgres = [ + gnatcoll-sql + postgresql + ]; + sqlite = [ + gnatcoll-sql + sqlite + ]; + xref = [ + gnatcoll-iconv + gnatcoll-sqlite + ]; + }; + + # These components are just tools and don't install a library + onlyExecutable = builtins.elem component [ + "gnatcoll_db2ada" + "gnatinspect" + ]; +in + +stdenv.mkDerivation rec { + # executables don't adhere to the string gnatcoll-* scheme + pname = + if onlyExecutable + then builtins.replaceStrings [ "_" ] [ "-" ] component + else "gnatcoll-${component}"; + version = "24.0.0"; + + src = fetchFromGitHub { + owner = "AdaCore"; + repo = "gnatcoll-db"; + rev = "v${version}"; + sha256 = "0jq76s4s7q2x93jh8la6r0i3jkpvgsfj12vbbaqabh410xccyr3p"; + }; + + # Link executables dynamically unless specified by the platform, + # as we usually do in nixpkgs where possible + postPatch = lib.optionalString (!stdenv.hostPlatform.isStatic) '' + for f in gnatcoll_db2ada/Makefile gnatinspect/Makefile; do + substituteInPlace "$f" --replace "=static" "=relocatable" + done + ''; + + nativeBuildInputs = [ + gnat + gprbuild + which + ]; + + # Propagate since GPRbuild needs to find referenced .gpr files + # and other libraries to link against when static linking is used. + # For executables this is of course not relevant and we can reduce + # the closure size dramatically + ${if onlyExecutable then "buildInputs" else "propagatedBuildInputs"} = [ + gnatcoll-core + ] ++ libsFor."${component}" or []; + + makeFlags = [ + "-C" component + "PROCESSORS=$(NIX_BUILD_CORES)" + # confusingly, for gprbuild --target is autoconf --host + "TARGET=${stdenv.hostPlatform.config}" + "prefix=${placeholder "out"}" + ] ++ lib.optionals (component == "sqlite") [ + # link against packaged, not vendored libsqlite3 + "GNATCOLL_SQLITE=external" + ]; + + meta = with lib; { + description = "GNAT Components Collection - Database packages"; + homepage = "https://github.com/AdaCore/gnatcoll-db"; + license = licenses.gpl3Plus; + maintainers = [ maintainers.sternenseemann ]; + platforms = platforms.all; + }; +} diff --git a/pkgs/development/ada-modules/gnatprove/default.nix b/pkgs/development/ada-modules/gnatprove/default.nix new file mode 100644 index 0000000000000..884406d3342e2 --- /dev/null +++ b/pkgs/development/ada-modules/gnatprove/default.nix @@ -0,0 +1,96 @@ +{ stdenv +, lib +, fetchFromGitHub +, gnat +, gnatcoll-core +, gprbuild +, python3 +, ocamlPackages +, makeWrapper +}: +let + gnat_version = lib.versions.major gnat.version; + + fetchSpark2014 = { rev, sha256 } : fetchFromGitHub { + owner = "AdaCore"; + repo = "spark2014"; + fetchSubmodules = true; + inherit rev sha256; + }; + + spark2014 = { + "12" = { + src = fetchSpark2014 { + rev = "ab34e07080a769b63beacc141707b5885c49d375"; # branch fsf-12 + sha256 = "sha256-7pe3eWitpxmqzjW6qEIEuN0qr2IR+kJ7Ssc9pTBcCD8="; + }; + commit_date = "2022-05-25"; + }; + "13" = { + src = fetchSpark2014 { + rev = "12db22e854defa9d1c993ef904af1e72330a68ca"; # branch fsf-13 + sha256 = "sha256-mZWP9yF1O4knCiXx8CqolnS+93bM+hTQy40cd0HZmwI="; + }; + commit_date = "2023-01-05"; + }; + }; + + thisSpark = spark2014.${gnat_version} or + (builtins.throw "GNATprove depend on a specific GNAT version and can't be built using GNAT ${gnat_version}."); + +in +stdenv.mkDerivation rec { + pname = "gnatprove"; + version = "fsf-${gnat_version}_${thisSpark.commit_date}"; + + src = thisSpark.src; + + nativeBuildInputs = [ + gnat + gprbuild + python3 + ocamlPackages.ocaml + makeWrapper + ]; + + buildInputs = [ + gnatcoll-core + ocamlPackages.camlzip + ocamlPackages.findlib + ocamlPackages.menhir + ocamlPackages.menhirLib + ocamlPackages.num + ocamlPackages.yojson + ocamlPackages.zarith + ]; + + propagatedBuildInputs = [ + gprbuild + ]; + + postPatch = '' + # gnat2why/gnat_src points to the GNAT sources + tar xf ${gnat.cc.src} gcc-${gnat.cc.version}/gcc/ada + mv gcc-${gnat.cc.version}/gcc/ada gnat2why/gnat_src + ''; + + configurePhase = '' + make setup + ''; + + installPhase = '' + make install-all + cp -a ./install/. $out + mkdir $out/share/gpr + ln -s $out/lib/gnat/* $out/share/gpr/ + ''; + + meta = with lib; { + description = "a software development technology specifically designed for engineering high-reliability applications"; + homepage = "https://github.com/AdaCore/spark2014"; + maintainers = [ maintainers.jiegec ]; + license = licenses.gpl3; + platforms = platforms.all; + }; +} + diff --git a/pkgs/development/ada-modules/gprbuild/boot.nix b/pkgs/development/ada-modules/gprbuild/boot.nix new file mode 100644 index 0000000000000..4207b3649594f --- /dev/null +++ b/pkgs/development/ada-modules/gprbuild/boot.nix @@ -0,0 +1,97 @@ +{ stdenv +, lib +, fetchFromGitHub +, gnat +, which +, xmlada # for src +}: + +let + version = "24.0.0"; + + gprConfigKbSrc = fetchFromGitHub { + name = "gprconfig-kb-${version}-src"; + owner = "AdaCore"; + repo = "gprconfig_kb"; + rev = "v${version}"; + sha256 = "1vnjv2q63l8nq2w4wya75m40isvs78j5ss9b5ga3zx3cpdx3xh09"; + }; +in + +stdenv.mkDerivation { + pname = "gprbuild-boot"; + inherit version; + + src = fetchFromGitHub { + name = "gprbuild-${version}"; + owner = "AdaCore"; + repo = "gprbuild"; + rev = "v${version}"; + sha256 = "096a43453z2xknn6x4hyk2ldp2wh0qhfdfmzsrks50zqcvmkq4v7"; + }; + + nativeBuildInputs = [ + gnat + which + ]; + + postPatch = '' + # The Makefile uses gprbuild to build gprbuild which + # we can't do at this point, delete it to prevent the + # default phases from failing. + rm Makefile + + # make sure bootstrap script runs + patchShebangs --build bootstrap.sh + ''; + + # This setupHook populates GPR_PROJECT_PATH which is used by + # gprbuild to find dependencies. It works quite similar to + # the pkg-config setupHook in the sense that it also splits + # dependencies into GPR_PROJECT_PATH and GPR_PROJECT_PATH_FOR_BUILD, + # but gprbuild itself doesn't support this, so we'll need to + # introducing a wrapper for it in the future remains TODO. + # For the moment this doesn't matter since we have no situation + # were gprbuild is used to build something used at build time. + setupHooks = [ + ./gpr-project-path-hook.sh + ] ++ lib.optionals stdenv.targetPlatform.isDarwin [ + # This setupHook replaces the paths of shared libraries starting + # with @rpath with the absolute paths on Darwin, so that the + # binaries can be run without additional setup. + ./gpr-project-darwin-rpath-hook.sh + ]; + + installPhase = '' + runHook preInstall + + ./bootstrap.sh \ + --with-xmlada=${xmlada.src} \ + --with-kb=${gprConfigKbSrc} \ + --prefix=$out + + # Install custom compiler description which can detect nixpkgs' + # GNAT wrapper as a proper Ada compiler. The default compiler + # description expects the runtime library to be installed in + # the same prefix which isn't the case for nixpkgs. As a + # result, it would detect the unwrapped GNAT as a proper + # compiler which is unable to produce working binaries. + # + # Our compiler description is very similar to the upstream + # GNAT description except that we use a symlink in $out/nix-support + # created by the cc-wrapper to find the associated runtime + # libraries and use gnatmake instead of gnatls to find GNAT's + # bin directory. + install -m644 ${./nixpkgs-gnat.xml} $out/share/gprconfig/nixpkgs-gnat.xml + + runHook postInstall + ''; + + meta = with lib; { + description = "Multi-language extensible build tool"; + homepage = "https://github.com/AdaCore/gprbuild"; + license = licenses.gpl3Plus; + maintainers = [ maintainers.sternenseemann ]; + platforms = platforms.all; + }; +} diff --git a/pkgs/development/ada-modules/gprbuild/default.nix b/pkgs/development/ada-modules/gprbuild/default.nix new file mode 100644 index 0000000000000..aad1157012634 --- /dev/null +++ b/pkgs/development/ada-modules/gprbuild/default.nix @@ -0,0 +1,64 @@ +{ 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 + setupHooks + 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. Based on the AUR's patch: + # https://aur.archlinux.org/cgit/aur.git/plain/0001-Makefile-build-relocatable-instead-of-static-binary.patch?h=gprbuild&id=bac524c76cd59c68fb91ef4dfcbe427357b9f850 + patches = lib.optionals (!stdenv.hostPlatform.isStatic) [ + ./gprbuild-relocatable-build.patch + ]; + + 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 + ''; +} diff --git a/pkgs/development/ada-modules/gprbuild/gpr-project-darwin-rpath-hook.sh b/pkgs/development/ada-modules/gprbuild/gpr-project-darwin-rpath-hook.sh new file mode 100644 index 0000000000000..73be2eb5960aa --- /dev/null +++ b/pkgs/development/ada-modules/gprbuild/gpr-project-darwin-rpath-hook.sh @@ -0,0 +1,10 @@ +fixGprProjectDarwinRpath() { + for f in $(find $out -type f -executable); do + install_name_tool -id $f $f || true + for rpath in $(otool -L $f | grep @rpath | awk '{print $1}'); do + install_name_tool -change $rpath ${!outputLib}/lib/$(basename $rpath) $f || true + done + done +} + +preFixupPhases+=" fixGprProjectDarwinRpath" diff --git a/pkgs/development/ada-modules/gprbuild/gpr-project-path-hook.sh b/pkgs/development/ada-modules/gprbuild/gpr-project-path-hook.sh new file mode 100644 index 0000000000000..f98b2ab9e58d3 --- /dev/null +++ b/pkgs/development/ada-modules/gprbuild/gpr-project-path-hook.sh @@ -0,0 +1,8 @@ +addAdaObjectsPath() { + local role_post + getHostRoleEnvHook + + addToSearchPath "GPR_PROJECT_PATH${role_post}" "$1/share/gpr" +} + +addEnvHooks "$targetOffset" addAdaObjectsPath diff --git a/pkgs/development/ada-modules/gprbuild/gprbuild-relocatable-build.patch b/pkgs/development/ada-modules/gprbuild/gprbuild-relocatable-build.patch new file mode 100644 index 0000000000000..f49478f6e38c4 --- /dev/null +++ b/pkgs/development/ada-modules/gprbuild/gprbuild-relocatable-build.patch @@ -0,0 +1,13 @@ +diff --git a/Makefile b/Makefile +index 8c542078..e91cef5e 100644 +--- a/Makefile ++++ b/Makefile +@@ -82,7 +82,7 @@ LIB_INSTALLER=gprinstall -p -f --target=$(TARGET) $(RBD) "--prefix=${prefix}" + CLEANER=gprclean -q $(RBD) + + GPRBUILD_BUILDER=$(BUILDER) $(GPRBUILD_GPR) \ +- -XLIBRARY_TYPE=static -XXMLADA_BUILD=static ++ -XLIBRARY_TYPE=relocatable -XXMLADA_BUILD=relocatable + LIBGPR_BUILDER=$(BUILDER) $(GPR_GPR) $(LIBGPR_OS) + LIBGPR_INSTALLER=$(LIB_INSTALLER) $(GPR_GPR) $(LIBGPR_OS) -XBUILD=${BUILD} \ + --install-name=gpr \ diff --git a/pkgs/development/ada-modules/gprbuild/nixpkgs-gnat.xml b/pkgs/development/ada-modules/gprbuild/nixpkgs-gnat.xml new file mode 100644 index 0000000000000..ead88dc365c1e --- /dev/null +++ b/pkgs/development/ada-modules/gprbuild/nixpkgs-gnat.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" ?> +<gprconfig> + <!-- This differs from the default GNAT compiler description + in the following ways: + + * gnatmake is used over gnatls to detect the GNAT version + since the latter is not part of the wrapper. + * to find the runtime libraries, we rely on the symlink + ../nix-support/gprconfig-gnat-unwrapped which is a + gprconfig-specific addition to the cc-wrapper we employ + for Ada compilers (which is only GNAT at the moment). + + For documentation on this file format and its use refer to + https://docs.adacore.com/gprbuild-docs/html/gprbuild_ug/companion_tools.html#the-gprconfig-knowledge-base + --> + <compiler_description> + <!-- We would like to name this something different, so users + of gprconfig know this is something custom, nixpkgs-related, + but unfortunately the knowledge base depends on the name of + the compiler for e. g. linker settings. + --> + <name>GNAT</name> + <executable prefix="1">(.*-.*-.*)?gnatmake</executable> + <version> + <external>${PREFIX}gnatmake -v</external> + <grep regexp="^GNATMAKE.+?(\d+(\.\d+)?)" group="1"></grep> + </version> + <languages>Ada</languages> + <variable name="gcc_version"> + <external>${PREFIX}gcc -v</external> + <grep regexp="^[-\w]*gcc \S+ (\S+)" group="1"></grep> + </variable> + <!-- The ada runtime libraries and objects are only part of the unwrapped + GNAT derivation. We can't symlink them into the wrapper derivation + (at least not the canonical location) since that screws with linking + against libraries distributed with gcc. + + As a workaround, we create a symlink to the unwrapped GNAT's "out" + output in the cc-wrapper which we can read into a variable here and + use to find GNAT's Ada runtime. + --> + <variable name="gnat_unwrapped"> + <external>readlink -n ${PATH}/../nix-support/gprconfig-gnat-unwrapped</external> + </variable> + <runtimes default="default,kernel,native"> + <directory group="default" >$gnat_unwrapped/lib/gcc(-lib)?/$TARGET/$gcc_version/adalib/</directory> + <directory group="default" contents="^rts-">$gnat_unwrapped/lib/gcc(-lib)?/$TARGET/$gcc_version/ada_object_path</directory> + <directory group="2" >$gnat_unwrapped/lib/gcc(-lib)?/$TARGET/$gcc_version/rts-(.*)/adalib/</directory> + <directory group="1" >$gnat_unwrapped/$TARGET/lib/gnat/(.*)/adalib/</directory> + </runtimes> + <target> + <external>${PREFIX}gcc -dumpmachine</external> + <grep regexp="[^\r\n]+"></grep> + </target> + </compiler_description> +</gprconfig> diff --git a/pkgs/development/ada-modules/xmlada/default.nix b/pkgs/development/ada-modules/xmlada/default.nix new file mode 100644 index 0000000000000..77e8094277a71 --- /dev/null +++ b/pkgs/development/ada-modules/xmlada/default.nix @@ -0,0 +1,35 @@ +{ stdenv +, lib +, fetchFromGitHub +, gnat +# use gprbuild-boot since gprbuild proper depends +# on this xmlada derivation. +, gprbuild-boot +}: + +stdenv.mkDerivation rec { + pname = "xmlada"; + version = "24.0.0"; + + src = fetchFromGitHub { + name = "xmlada-${version}-src"; + owner = "AdaCore"; + repo = "xmlada"; + rev = "v${version}"; + sha256 = "sha256-vvM7bdf3dAa3zKgxbGeAGlBT6fvafzmleimJHyRdlvc="; + }; + + nativeBuildInputs = [ + gnat + gprbuild-boot + ]; + + meta = with lib; { + description = "XML/Ada: An XML parser for Ada"; + homepage = "https://github.com/AdaCore/xmlada"; + maintainers = [ maintainers.sternenseemann ]; + license = licenses.gpl3Plus; + platforms = platforms.all; + }; +} + |