aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013, 2014, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
;;; Copyright © 2022, 2024 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2023 Zheng Junjie <873216071@qq.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu packages pkg-config)
  #:use-module (guix licenses)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix gexp)
  #:use-module (guix search-paths)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system trivial)
  #:use-module (gnu packages bash)

  ;; Note: Because this module defines the 'pkg-config' macro, it cannot be
  ;; caught in a cycle with other package modules or the macro wouldn't be
  ;; visible at the time those other modules are compiled.  To fulfill that
  ;; constraint, load (gnu packages check) lazily.
  #:autoload   (gnu packages check) (atf kyua)

  #:use-module (guix memoization)
  #:export (pkg-config))

;; This is the "primitive" pkg-config package.  People should use `pkg-config'
;; (see below) rather than `%pkg-config', but we export `%pkg-config' so that
;; `fold-packages' finds it.
(define-public %pkg-config
  (package
   (name "pkg-config")
   (version "0.29.2")
   (source (origin
            (method url-fetch)
            (uri (list
                  (string-append
                   "http://fossies.org/linux/misc/pkg-config-" version
                   ".tar.gz")

                  ;; FIXME: The following URL redirects to HTTPS, which
                  ;; creates bootstrapping problems:
                  ;; <http://bugs.gnu.org/22774>.
                  (string-append
                   "http://pkgconfig.freedesktop.org/releases/pkg-config-"
                   version ".tar.gz")))
            (sha256
             (base32
              "14fmwzki1rlz8bs2p810lk6jqdxsk966d8drgsjmi54cd00rrikg"))))
   (build-system gnu-build-system)
   (arguments
    `(#:configure-flags
      '("--with-internal-glib"
        ;; Those variables are guessed incorrectly when cross-compiling.
        ;; See: https://developer.gimp.org/api/2.0/glib/glib-cross-compiling.html.
        ,@(if (%current-target-system)
              '("glib_cv_stack_grows=no"
                "glib_cv_uscore=no"
                "ac_cv_func_posix_getpwuid_r=yes"
                "ac_cv_func_posix_getgrgid_r=yes")
              '()))))
   (native-search-paths
    (list $PKG_CONFIG_PATH))
   (home-page "https://www.freedesktop.org/wiki/Software/pkg-config")
   (license gpl2+)
   (synopsis "Helper tool used when compiling applications and libraries")
   (description
    "pkg-config is a helper tool used when compiling applications and
libraries.  It helps you insert the correct compiler options on the
command line so an application can use gcc -o test test.c `pkg-config
--libs --cflags glib-2.0` for instance, rather than hard-coding values
on where to find glib (or other libraries).  It is language-agnostic, so
it can be used for defining the location of documentation tools, for
instance.")))

(define cross-pkg-config
  (mlambda (target)
    "Return a pkg-config for TARGET, essentially just a wrapper called
`TARGET-pkg-config', as `configure' scripts like it."
    ;; See <http://www.flameeyes.eu/autotools-mythbuster/pkgconfig/cross-compiling.html>
    ;; for details.
    (package
      (inherit %pkg-config)
      (name (string-append (package-name %pkg-config) "-" target))
      (build-system trivial-build-system)
      (arguments
       `(#:modules ((guix build utils))
         #:builder (begin
                     (use-modules (guix build utils))

                     (let* ((in     (assoc-ref %build-inputs "pkg-config"))
                            (out    (assoc-ref %outputs "out"))
                            (bin    (string-append out "/bin"))
                            (prog   (string-append ,target "-pkg-config"))
                            (native (string-append in "/bin/pkg-config")))

                       (mkdir-p bin)

                       ;; Create a `TARGET-pkg-config' -> `pkg-config' symlink.
                       ;; This satisfies the pkg.m4 macros, which use
                       ;; AC_PROG_TOOL to determine the `pkg-config' program
                       ;; name.
                       (symlink native (string-append bin "/" prog))

                       ;; Also make 'pkg.m4' available, some packages might
                       ;; expect it.
                       (mkdir-p (string-append out "/share"))
                       (symlink (string-append in "/share/aclocal")
                                (string-append out "/share/aclocal"))
                       #t))))
      (native-inputs `(("pkg-config" ,%pkg-config)))

      ;; Ignore native inputs, and set `PKG_CONFIG_PATH' for target inputs.
      (native-search-paths '())
      (search-paths (package-native-search-paths %pkg-config)))))

(define (pkg-config-for-target target)
  "Return a pkg-config package for TARGET, which may be either #f for a native
build, or a GNU triplet."
  (if target
      (cross-pkg-config target)
      %pkg-config))

;; This hack allows us to automatically choose the native or the cross
;; `pkg-config' depending on whether it's being used in a cross-build
;; environment or not.
(define-syntax pkg-config
  (identifier-syntax (pkg-config-for-target (%current-target-system))))

;; This hack allows for using both "pkg-config" and "TARGET-pkg-config"
;; at the same time.  Simply using '%pkg-config' and 'pkg-config' won't
;; work because they both use the "PKG_CONFIG_PATH" environment variable.
(define-public pkg-config-for-build
  (package
    (inherit (hidden-package %pkg-config))
    (name "pkg-config-for-build")
    (version "0")
    (source #f)
    (build-system trivial-build-system)
    (inputs
     (list bash-minimal %pkg-config))
    (arguments
     `(#:modules ((guix build utils))
       #:builder
       ,#~(begin
            (use-modules (guix build utils))
            (define where (string-append #$output "/bin/pkg-config"))
            (mkdir-p (dirname where))
            (call-with-output-file where
              (lambda (port)
                (format port "#!~a
export PKG_CONFIG_PATH=\"$PKG_CONFIG_PATH_FOR_BUILD\"
exec ~a \"$@\""
                        (search-input-file %build-inputs "bin/bash")
                        (search-input-file %build-inputs "bin/pkg-config"))))
            (chmod where #o500))))
    (native-search-paths
     (map (lambda (original)
            (search-path-specification
             (inherit original)
             (variable "PKG_CONFIG_PATH_FOR_BUILD")))
          (package-native-search-paths %pkg-config)))))

(define-public pkgconf
  (package
    (name "pkgconf")
    (version "2.1.0")
    (source (origin
              (method url-fetch)
              (uri (string-append  "https://distfiles.dereferenced.org/"
                                   name "/" name "-" version ".tar.xz"))
              (sha256
               (base32
                "0qbpczwrrsq2981mdv3iil26vq9ac8v1sfi9233jpiaixrhmhv96"))))
    (build-system gnu-build-system)
    (arguments
     (list #:phases #~(modify-phases %standard-phases
                        (add-after 'unpack 'set-HOME
                          (lambda _
                            ;; Kyua requires a writable HOME.
                            (setenv "HOME" "/tmp"))))))
    (native-inputs (list atf kyua))
    (native-search-paths (list $PKG_CONFIG_PATH))
    (home-page "http://pkgconf.org/")
    (synopsis "Package compiler and linker metadata toolkit")
    (description "@command{pkgconf} is a program which helps to configure
compiler and linker flags for development libraries.  It is similar to
pkg-config from freedesktop.org.  @code{libpkgconf} is a library which
provides access to most of pkgconf's functionality, to allow other tooling
such as compilers and IDEs to discover and use libraries configured by
pkgconf.")
    (license isc)))
(properties ;; Tell the 'generic-html' updater to monitor this URL for updates. `((release-monitoring-url . "https://www.open-mpi.org/software/ompi/current"))) (build-system gnu-build-system) (inputs (let ((if-supported (lambda (package) (if (and (not (%current-target-system)) (member (%current-system) (package-supported-systems package))) (list package) '())))) (append (list `(,hwloc-2 "lib") gfortran libfabric libevent opensm) (if-supported psm) (if-supported psm2) (if-supported ucx) (if-supported valgrind) (list rdma-core slurm)))) ;for PMI support (launching via "srun") (native-inputs (list pkg-config perl)) (outputs '("out" "debug")) (arguments (list #:configure-flags #~`("--enable-mpi-ext=affinity" ;cr doesn't work "--with-sge" #$@(if (package? (this-package-input "valgrind")) #~("--enable-memchecker" "--with-valgrind") #~("--without-valgrind")) "--with-hwloc=external" "--with-libevent" ;; Help 'orterun' and 'mpirun' find their tools ;; under $prefix by default. "--enable-mpirun-prefix-by-default" ;; InfiniBand support "--enable-openib-control-hdr-padding" "--enable-openib-dynamic-sl" "--enable-openib-udcm" "--enable-openib-rdmacm" "--enable-openib-rdmacm-ibaddr" ;; Enable support for the 'Process Management ;; Interface for Exascale' (PMIx) used e.g. by ;; Slurm for the management communication and ;; coordination of MPI processes. "--with-pmix=internal" ;; Enable support for SLURM's Process Manager ;; Interface (PMI). ,(string-append "--with-pmi=" #$(this-package-input "slurm"))) #:phases #~(modify-phases %standard-phases ;; opensm is needed for InfiniBand support. (add-after 'unpack 'find-opensm-headers (lambda* (#:key inputs #:allow-other-keys) (setenv "C_INCLUDE_PATH" (search-input-directory inputs "/include/infiniband")) (setenv "CPLUS_INCLUDE_PATH" (search-input-directory inputs "/include/infiniband")))) (add-before 'build 'remove-absolute (lambda _ ;; Remove compiler absolute file names (OPAL_FC_ABSOLUTE ;; etc.) to reduce the closure size. See ;; <https://lists.gnu.org/archive/html/guix-devel/2017-07/msg00388.html> ;; and ;; <https://www.mail-archive.com/users@lists.open-mpi.org//msg31397.html>. (substitute* '("orte/tools/orte-info/param.c" "oshmem/tools/oshmem_info/param.c" "ompi/tools/ompi_info/param.c") (("_ABSOLUTE") "")) ;; Avoid valgrind (which pulls in gdb etc.). (substitute* '("./ompi/mca/io/romio321/src/io_romio321_component.c") (("MCA_io_romio321_COMPLETE_CONFIGURE_FLAGS") "\"[elided to reduce closure]\"")))) (add-before 'build 'scrub-timestamps ;reproducibility (lambda _ (substitute* '("ompi/tools/ompi_info/param.c" "orte/tools/orte-info/param.c" "oshmem/tools/oshmem_info/param.c") ((".*(Built|Configured) on.*") "")))) (add-after 'install 'remove-logs ;reproducibility (lambda* (#:key outputs #:allow-other-keys) (let ((out (assoc-ref outputs "out"))) (for-each delete-file (find-files out "config.log")))))))) (home-page "https://www.open-mpi.org") (synopsis "MPI-3 implementation") (description "The Open MPI Project is an MPI-3 implementation that is developed and maintained by a consortium of academic, research, and industry partners. Open MPI is therefore able to combine the expertise, technologies, and resources from all across the High Performance Computing community in order to build the best MPI library available. Open MPI offers advantages for system and software vendors, application developers and computer science researchers.") ;; See file://LICENSE (license license:bsd-2))) (define-public openmpi openmpi-4) (define-public openmpi-5 (package (inherit openmpi) (version "5.0.3") (source (origin (method url-fetch) (uri (string-append "https://www.open-mpi.org/software/ompi/v" (version-major+minor version) "/downloads/openmpi-" version ".tar.bz2")) (sha256 (base32 "02x9xmpggw77mdpikjjx83j6i4v3gkqbncda73lk5axk0vr841cr")))) (inputs (modify-inputs (package-inputs openmpi) ;; As of Open MPI 5.0.X, PMIx is used to communicate ;; with SLURM, so SLURM'S PMI is no longer needed. (delete "slurm") (append ucx) ;for Infiniband support (append openpmix) ;for PMI support (launching via "srun") (append prrte))) ;for PMI support (launching via "srun") (native-inputs (modify-inputs (package-native-inputs openmpi) (append python))) (outputs '("out" "debug")) (arguments (substitute-keyword-arguments (package-arguments openmpi) ((#:configure-flags _) #~(list "--enable-mpi-ext=affinity" ;cr doesn't work "--with-sge" #$@(if (package? (this-package-input "valgrind")) #~("--enable-memchecker" "--with-valgrind") #~("--without-valgrind")) "--with-hwloc=external" "--with-libevent" ;; This replaces --enable-mpirun-prefix-by-default wich is deprecated ;; since 5.x. "--enable-prte-prefix-by-default" ;; Enable support for the 'Process Management Interface for Exascale' ;; (PMIx) used e.g. by Slurm for the management communication and ;; coordination of MPI processes. (string-append "--with-pmix=" #$(this-package-input "openpmix")) (string-append "--with-prrte=" #$(this-package-input "prrte")) ;; Since 5.x, Infiniband support is provided by ucx. ;; See https://docs.open-mpi.org/en/main/release-notes/networks.html#miscellaneous-network-notes (string-append "--with-ucx=" #$(this-package-input "ucx")))) ((#:phases phases) #~(modify-phases #$phases (delete 'remove-absolute) (delete 'scrub-timestamps))))))) (define-public openmpi-c++ (package/inherit openmpi (name "openmpi-c++") (outputs '("out")) (arguments (substitute-keyword-arguments (package-arguments openmpi) ((#:configure-flags flags) #~(cons "--enable-mpi-cxx" #$flags)))) (synopsis "C++ bindings for MPI"))) ;; TODO: javadoc files contain timestamps. (define-public java-openmpi (package/inherit openmpi (name "java-openmpi") (inputs `(("openmpi" ,openmpi) ,@(package-inputs openmpi))) (native-inputs `(("jdk" ,openjdk11 "jdk") ("zip" ,(@ (gnu packages compression) zip)) ,@(package-native-inputs openmpi))) (outputs '("out")) (arguments (cons* #:modules '((guix build gnu-build-system) ((guix build ant-build-system) #:prefix ant:) (guix build utils)) #:imported-modules `((guix build ant-build-system) ,@%default-gnu-imported-modules) (substitute-keyword-arguments (package-arguments openmpi) ((#:configure-flags flags) #~(cons "--enable-mpi-java" #$flags)) ((#:make-flags flags ''()) #~(append '("-C" "ompi/mpi/java") #$flags)) ((#:phases phases) #~(modify-phases #$phases ;; We could provide the location of the JDK in the configure ;; flags, but since the configure flags are embedded in the ;; info binaries that would leave a reference to the JDK in ;; the "out" output. To avoid this we set JAVA_HOME. (add-after 'unpack 'set-JAVA_HOME (lambda* (#:key inputs #:allow-other-keys) (setenv "JAVA_HOME" (assoc-ref inputs "jdk")) #t)) (add-after 'unpack 'link-with-existing-mpi-libraries (lambda* (#:key inputs #:allow-other-keys) (substitute* "ompi/mpi/java/c/Makefile.in" (("\\$\\(top_builddir\\)/ompi/lib@OMPI_LIBMPI_NAME@.la") (search-input-file inputs "/lib/libmpi.la"))))) (add-after 'install 'strip-jar-timestamps (assoc-ref ant:%standard-phases 'strip-jar-timestamps))))))) (synopsis "Java bindings for MPI"))) (define-public openmpi-thread-multiple (package/inherit openmpi (name "openmpi-thread-multiple") (arguments (substitute-keyword-arguments (package-arguments openmpi) ((#:configure-flags flags) #~(cons "--enable-mpi-thread-multiple" #$flags)))) (description "This version of Open@tie{}MPI has an implementation of @code{MPI_Init_thread} that provides @code{MPI_THREAD_MULTIPLE}. This won't work correctly with all transports (such as @code{openib}), and the performance is generally worse than the vanilla @code{openmpi} package, which only provides @code{MPI_THREAD_FUNNELED}."))) ;;; Build phase to be used for packages that execute MPI code. (define-public %openmpi-setup '(lambda _ ;; By default, running the test suite would fail because 'ssh' could not ;; be found in $PATH. Define this variable to placate Open MPI without ;; adding a dependency on OpenSSH (the agent isn't used anyway.) (setenv "OMPI_MCA_plm_rsh_agent" (which "false")) ;; Allow oversubscription in case there are less physical cores available ;; in the build environment than the package wants while testing. (setenv "OMPI_MCA_rmaps_base_mapping_policy" "core:OVERSUBSCRIBE") ;; UCX sometimes outputs uninteresting warnings such as: ;; ;; mpool.c:38 UCX WARN object 0x7ffff44fffc0 was not returned to mpool ucp_am_bufs ;; ;; These in turn leads to failures of test suites that capture and ;; compare stdout, such as that of 'hdf5-parallel-openmpi'. Thus, tell ;; UCX to not emit those warnings. (setenv "UCX_LOG_LEVEL" "error") ;; Starting from 2.9.0, hwloc fails when /sys is unavailable: ;; ;; [hwloc/linux] failed to find sysfs cpu topology directory, aborting linux discovery. ;; ;; This in turn breaks Open MPI users. To work around it, define a fake ;; topology with 4 cores. That silently disables CPU binding, though ;; 'get_cpubind' will report there's no binding. (setenv "HWLOC_SYNTHETIC" "4") #t)) (define-public python-mpi4py (package (name "python-mpi4py") (version "3.1.4") (source (origin (method url-fetch) (uri (pypi-uri "mpi4py" version)) (sha256 (base32 "101lz7bnm9l17nrkbg6497kxscyh53aah7qd2b820ck2php8z18p")))) (build-system python-build-system) (arguments `(#:phases (modify-phases %standard-phases (add-after 'build 'mpi-setup ,%openmpi-setup) (add-before 'check 'pre-check (lambda _ ;; Skip BaseTestSpawn class (causes error 'ompi_dpm_dyn_init() ;; failed --> Returned "Unreachable"' in chroot environment). (substitute* "test/test_spawn.py" (("unittest.skipMPI\\('openmpi\\(<3.0.0\\)'\\)") "unittest.skipMPI('openmpi')")) #t))))) (inputs (list openmpi)) (properties '((updater-extra-inputs . ("openmpi")))) (home-page "https://github.com/mpi4py/mpi4py") (synopsis "Python bindings for the Message Passing Interface standard") (description "MPI for Python (mpi4py) provides bindings of the Message Passing Interface (MPI) standard for the Python programming language, allowing any Python program to exploit multiple processors. mpi4py is constructed on top of the MPI-1/MPI-2 specification and provides an object oriented interface which closely follows MPI-2 C++ bindings. It supports point-to-point and collective communications of any picklable Python object as well as optimized communications of Python objects (such as NumPy arrays) that expose a buffer interface.") (license license:bsd-3))) (define-public mpich (package (name "mpich") (version "4.2.2") (source (origin (method url-fetch) (uri (string-append "http://www.mpich.org/static/downloads/" version "/mpich-" version ".tar.gz")) (sha256 (base32 "0h8xg1wi2d88hnfmj3xydf1hj78r7fh05jljhk5jgxmbmsrmngw8")))) (build-system gnu-build-system) (inputs `(,zlib (,hwloc-2 "lib") ,slurm ,@(if (and (not (%current-target-system)) (member (%current-system) (package-supported-systems ucx))) (list ucx) '()))) (native-inputs (list perl which gfortran python-minimal)) (outputs '("out" "debug")) (arguments `(#:configure-flags (list "--disable-silent-rules" ;let's see what's happening "--enable-debuginfo" ;; Default to "ch4", as will be the case in 3.4. It also works ;; around issues when running test suites of packages that use ;; MPICH: <https://issues.guix.gnu.org/39588#15>. "--with-device=ch4:ucx" ; --with-device=ch4:ofi segfaults in tests (string-append "--with-hwloc-prefix=" (assoc-ref %build-inputs "hwloc")) ,@(if (assoc "ucx" (package-inputs this-package)) `((string-append "--with-ucx=" (assoc-ref %build-inputs "ucx"))) '())) #:phases (modify-phases %standard-phases (add-after 'unpack 'patch-sources (lambda _ (substitute* "./maint/gen_subcfg_m4" (("/usr/bin/env") (which "env"))) (substitute* "src/glue/romio/all_romio_symbols" (("/usr/bin/env") (which "env"))) (substitute* (find-files "." "buildiface") (("/usr/bin/env") (which "env"))) (substitute* "maint/extracterrmsgs" (("/usr/bin/env") (which "env"))) (substitute* (find-files "." "f77tof90") (("/usr/bin/env") (which "env"))) (substitute* (find-files "." "\\.sh$") (("/bin/sh") (which "sh"))))) (add-before 'configure 'fix-makefile (lambda _ ;; Remove "@hwloclib@" from 'pmpi_convenience_libs'. ;; This fixes "No rule to make target '-lhwloc', needed ;; by 'lib/libmpi.la'". (substitute* "Makefile.in" (("^pmpi_convenience_libs = (.*) @hwloclib@ (.*)$" _ before after) (string-append "pmpi_convenience_libs = " before " " after))))) (add-before 'configure 'define-gfortran-wrapper (lambda* (#:key inputs #:allow-other-keys) ;; 'configure' checks whether the Fortran compiler ;; allows argument type mismatch. Since gfortran >= 10 ;; does not, provide a wrapper that passes ;; '-fallow-argument-mismatch' to get the desired ;; behavior. (mkdir-p ".gfortran-wrapper/bin") (call-with-output-file ".gfortran-wrapper/bin/gfortran" (lambda (port) (display (string-append "#!" (which "sh") "\n") port) (display (string-append "exec \"" (which "gfortran") "\" -fallow-argument-mismatch" " \"$@\"\n") port) (chmod port #o755))) (setenv "PATH" (string-append (getcwd) "/" ".gfortran-wrapper/bin:" (getenv "PATH")))))))) (home-page "https://www.mpich.org/") (synopsis "Implementation of the Message Passing Interface (MPI)") (description "MPICH is a high-performance and portable implementation of the Message Passing Interface (MPI) standard (MPI-1, MPI-2 and MPI-3). MPICH provides an MPI implementation that efficiently supports different computation and communication platforms including commodity clusters, high-speed networks (10 Gigabit Ethernet, InfiniBand, Myrinet, Quadrics), and proprietary high-end computing systems (Blue Gene, Cray). It enables research in MPI through a modular framework for other derived implementations.") (license license:bsd-2))) (define-public mpich-ofi (package/inherit mpich (name "mpich-ofi") (inputs (modify-inputs (package-inputs mpich) (delete ucx) (append libfabric) (append rdma-core) (append psm2))) (arguments (substitute-keyword-arguments (package-arguments mpich) ((#:configure-flags flags) #~(list "--disable-silent-rules" ;let's see what's happening "--enable-debuginfo" "--with-device=ch4:ofi" (string-append "--with-hwloc-prefix=" #$(this-package-input "hwloc")) (string-append "--with-libfabric=" #$(this-package-input "libfabric")))) ((#:phases phases '%standard-phases) phases))) (synopsis "Implementation of the Message Passing Interface (MPI) for OmniPath")))