pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / development / compilers / swi-prolog / default.nix
blob9336adb1cd760c3d5c174e269973db844721579b
2   lib, stdenv, fetchFromGitHub,
3   cmake, ninja,
5   libxcrypt, zlib, openssl,
6   gmp, gperftools, readline,
7   libedit, libarchive, Security,
9   # optional dependencies
10   withDb ? true,
11   db,
13   withJava ? true,
14   jdk,
16   withOdbc ? true,
17   unixODBC,
19   withPcre ? true,
20   pcre2,
22   withPython ? true,
23   python3,
25   withYaml ? true,
26   libyaml,
29   withGui ? false,
30   libX11, libXpm, libXext, libXft, libXinerama, libjpeg, libXt, libSM, freetype, fontconfig,
32   # gcc/g++ as runtime dependency
33   withNativeCompiler ? true
35 # Packs must be installed from a local directory during the build, with dependencies
36 # resolved manually, e.g. to install the 'julian' pack, which depends on the 'delay', 'list_util' and 'typedef' packs:
37 #   julian = pkgs.fetchzip {
38 #     name = "swipl-pack-julian";
39 #     url = "https://github.com/mndrix/julian/archive/v0.1.3.zip";
40 #     sha256 = "1sgql7c21p3c5m14kwa0bcmlwn9fql612krn9h36gla1j9yjdfgy";
41 #   };
42 #   delay = pkgs.fetchzip {
43 #     name = "swipl-pack-delay";
44 #     url = "https://github.com/mndrix/delay/archive/v0.3.3.zip";
45 #     sha256 = "0ira87afxnc2dnbbmgwmrr8qvary8lhzvhqwd52dccm6yqd3nybg";
46 #   };
47 #   list_util = pkgs.fetchzip {
48 #     name = "swipl-pack-list_util";
49 #     url = "https://github.com/mndrix/list_util/archive/v0.13.0.zip";
50 #     sha256 = "0lx7vffflak0y8l8vg8k0g8qddwwn23ksbz02hi3f8rbarh1n89q";
51 #   };
52 #   typedef = builtins.fetchTarball {
53 #     name = "swipl-pack-typedef";
54 #     url = "https://raw.githubusercontent.com/samer--/prolog/master/typedef/release/typedef-0.1.9.tgz";
55 #     sha256 = "056nqjn01g18fb1b2qivv9s7hb4azk24nx2d4kvkbmm1k91f44p3";
56 #   };
57 #   swi-prolog = pkgs.swi-prolog.override { extraPacks = map (dep-path: "'file://${dep-path}'") [
58 #     julian delay list_util typedef
59 #   ]; };
60 , extraPacks ? []
61 , extraLibraries ? [] # removed option - see below
64 let
65   # minorVersion is even for stable, odd for unstable
66   version = "9.2.7";
68   # This package provides several with* options, which replaces the old extraLibraries option.
69   # This error should help users that still use this option find their way to these flags.
70   # We can probably remove this after one NixOS version.
71   extraLibraries' = if extraLibraries == [] then [] else throw
72     "option 'extraLibraries' removed - use 'with*' options (e.g., 'withJava'), or overrideAttrs to inject extra build dependencies";
74   packInstall = swiplPath: pack: ''
75     ${swiplPath}/bin/swipl -g "pack_install(${pack}, [package_directory(\"${swiplPath}/lib/swipl/extra-pack\"), silent(true), interactive(false), git(false)])." -t "halt."
76   '';
77   withGui' = withGui && !stdenv.hostPlatform.isDarwin;
78   optionalDependencies = []
79                          ++ (lib.optional withDb db)
80                          ++ (lib.optional withJava jdk)
81                          ++ (lib.optional withOdbc unixODBC)
82                          ++ (lib.optional withPcre pcre2)
83                          ++ (lib.optional withPython python3)
84                          ++ (lib.optional withYaml libyaml)
85                          ++ (lib.optionals withGui' [ libXt libXext libXpm libXft libXinerama
86                                                       libjpeg libSM freetype fontconfig
87                                                     ])
88                          ++ (lib.optional stdenv.hostPlatform.isDarwin Security)
89                          ++ extraLibraries';
91 stdenv.mkDerivation {
92   pname = "swi-prolog";
93   inherit version;
95   # SWI-Prolog has two repositories: swipl and swipl-devel.
96   # - `swipl`, which tracks stable releases and backports
97   # - `swipl-devel` which tracks continuous development
98   src = fetchFromGitHub {
99     owner = "SWI-Prolog";
100     repo = "swipl";
101     rev = "V${version}";
102     hash = "sha256-O9ogltcbBST111FA85jEVW6jGOLJSt/5PeBABtMu2Ws=";
103     fetchSubmodules = true;
104   };
106   # Add the packInstall path to the swipl pack search path
107   postPatch = ''
108     echo "user:file_search_path(pack, '$out/lib/swipl/extra-pack')." >> boot/init.pl
109   '';
111   nativeBuildInputs = [ cmake ninja ];
113   buildInputs = [
114     libarchive
115     libxcrypt
116     zlib
117     openssl
118     gperftools
119     gmp
120     readline
121     libedit
122   ] ++ optionalDependencies;
124   hardeningDisable = [ "format" ];
126   cmakeFlags = [ "-DSWIPL_INSTALL_IN_LIB=ON" ]
127                ++ lib.optionals (!withNativeCompiler) [
128                  # without these options, the build will embed full compiler paths
129                  "-DSWIPL_CC=${if stdenv.hostPlatform.isDarwin then "clang" else "gcc"}"
130                  "-DSWIPL_CXX=${if stdenv.hostPlatform.isDarwin then "clang++" else "g++"}"
131                ];
133   preInstall = ''
134     mkdir -p $out/lib/swipl/extra-pack
135   '';
137   postInstall = builtins.concatStringsSep "\n"
138   ( builtins.map (packInstall "$out") extraPacks
139   );
141   meta = {
142     homepage = "https://www.swi-prolog.org";
143     description = "Prolog compiler and interpreter";
144     license = lib.licenses.bsd2;
145     mainProgram = "swipl";
146     platforms = lib.platforms.linux ++ lib.optionals (!withGui) lib.platforms.darwin;
147     maintainers = [ lib.maintainers.meditans lib.maintainers.matko ];
148   };