;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017, 2018, 2019 Ricardo Wurmus ;;; Copyright © 2018 Joshua Sierles, Nextjournal ;;; Copyright © 2018 Tobias Geerinckx-Rice ;;; Copyright © 2019 Efraim Flashner ;;; Copyright © 2019 Andreas Enge ;;; ;;; 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 . (define-module (gnu packages graph) #:use-module (guix download) #:use-module (guix git-download) #:use-module (guix packages) #:use-module (guix utils) #:use-module (guix build-system cmake) #:use-module (guix build-system gnu) #:use-module (guix build-system python) #:use-module (guix build-system r) #:use-module ((guix licenses) #:prefix license:) #:use-module (gnu packages) #:use-module (gnu packages gcc) #:use-module (gnu packages autotools) #:use-module (gnu packages bioconductor) #:use-module (gnu packages bioinformatics) #:use-module (gnu packages check) #:use-module (gnu packages compression) #:use-module (gnu packages cran) #:use-module (gnu packages graphviz) #:use-module (gnu packages maths) #:use-module (gnu packages multiprecision) #:use-module (gnu packages pkg-config) #:use-module (gnu packages python) #:use-module (gnu packages
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2020-2022, 2024 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2023 Andreas Enge <andreas@enge.fr>
;;;
;;; 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/>.

;;; This file returns a manifest containing release-critical bit, for all the
;;; supported architectures and cross-compilation targets.

(use-modules (gnu packages)
             (guix packages)
             (guix profiles)
             ((guix platform) #:select (targets))
             ((gnu services xorg) #:select (%default-xorg-modules))
             (guix utils)
             (guix gexp)
             (srfi srfi-1)
             (srfi srfi-26))

(define* (package->manifest-entry* package system
                                   #:key target)
  "Return a manifest entry for PACKAGE on SYSTEM, optionally cross-compiled to
TARGET."
  (manifest-entry
    (inherit (package->manifest-entry package))
    (name (string-append (package-name package) "." system
                         (if target
                             (string-append "." target)
                             "'")))
    (item (with-parameters ((%current-system system)
                            (%current-target-system target))
            package))))

(define %base-packages
  ;; Packages that must be substitutable on all the platforms Guix supports.
  (map specification->package
       '("bootstrap-tarballs" "gcc-toolchain" "nss-certs"
         "openssh" "emacs" "vim" "python" "guile" "guix")))

(define %base-packages/armhf
  ;; The guix package doesn't build natively on armhf due to Guile memory
  ;; issues compiling the package modules
  (remove (lambda (package)
            (string=? (package-name package) "guix"))
          %base-packages))

(define %base-packages/hurd
  ;; XXX: For now we are less demanding of "i586-gnu".
  (map specification->package
       '("coreutils" "grep" "findutils" "gawk" "make"
         #;"gcc-toolchain" "tar" "xz")))

(define %system-packages
  ;; Key packages proposed by the Guix System installer.
  (append (map specification->package
               '("xorg-server" "xfce" "gnome" "mate" "enlightenment"
                 "openbox" "awesome" "i3-wm" "ratpoison"
                 "emacs" "emacs-exwm" "emacs-desktop-environment"
                 "xlockmore" "slock" "libreoffice"
                 "connman" "network-manager" "network-manager-applet"
                 "openssh" "ntp" "tor"
                 "linux-libre" "grub-hybrid"
                 "icecat"))
          %default-xorg-modules))

(define %packages-to-cross-build
  ;; Packages that must be cross-buildable from x86_64-linux.
  ;; FIXME: Add (@ (gnu packages gcc) gcc) when <https://bugs.gnu.org/40463>
  ;; is fixed.
  (append (list (@ (gnu packages guile) guile-3.0/pinned))
          (map specification->package
               '("coreutils" "grep" "sed" "findutils" "diffutils" "patch"
                 "gawk" "gettext" "gzip" "xz"
                 "hello" "zlib"))))

(define %packages-to-cross-build-for-mingw
  ;; Many things don't build for MinGW.  Restrict to what's known to work.
  (map specification->package '("hello")))

(define %cross-bootstrap-targets
  ;; Cross-compilation triplets for which 'bootstrap-tarballs' must be
  ;; buildable.
  '("i586-pc-gnu"
    "arm-linux-gnueabihf"
    "aarch64-linux-gnu"))


;;;
;;; Manifests.
;;;

(define %base-manifest
  (manifest
   (append-map (lambda (system)
                 (map (cut package->manifest-entry* <> system)
                      (cond ((string=? system "i586-gnu")
                             %base-packages/hurd)
                            ((string=? system "armhf-linux")
                             %base-packages/armhf)
                            ((string=? system "powerpc64le-linux")
                             ;; FIXME: Drop 'bootstrap-tarballs' until
                             ;; <https://bugs.gnu.org/48055> is fixed.
                             (drop %base-packages 1))
                            (else
                             %base-packages))))
               %cuirass-supported-systems)))

(define %system-manifest
  (manifest
   (append-map (lambda (system)
                 ;; Some of %SYSTEM-PACKAGES are currently unsupported on some
                 ;; systems--e.g., GNOME on non-x86_64, due to Rust.  Filter
                 ;; them out.
                 (filter-map (lambda (package)
                               (and (supported-package? package system)
                                    (package->manifest-entry* package system)))
                             %system-packages))
               '("x86_64-linux" "i686-linux"))))  ;Guix System

(define %cross-manifest
  (manifest
   (append-map (lambda (target)
                 (map (cut package->manifest-entry* <> "x86_64-linux"
                           #:target target)
                      (if (target-mingw? target)
                          %packages-to-cross-build-for-mingw
                          %packages-to-cross-build)))
               (fold delete (targets)
                     '(;; Like in (gnu ci), dismiss cross-compilation to x86:
                       ;; it's pointless.
                       "x86_64-linux-gnu"
                       "i686-linux-gnu"

                       ;; Ignore obsolete systems, as in (gnu ci).
                       "mips64el-linux-gnu"
                       "powerpc-linux-gnu"
                       "powerpc64-linux-gnu"

                       ;; Ignore bare-metal targets.
                       "avr"
                       "or1k-elf"
                       "xtensa-ath9k-elf"

                       ;; XXX: Important bits like libsigsegv and libffi don't
                       ;; support RISCV at the moment, so don't require RISCV
                       ;; support.
                       "riscv64-linux-gnu")))))

(define %cross-bootstrap-manifest
  (manifest
   (map (lambda (target)
          (package->manifest-entry*
           (specification->package "bootstrap-tarballs")
           "x86_64-linux" #:target target))
        %cross-bootstrap-targets)))

;; Return the union of all three manifests.
(concatenate-manifests (list %base-manifest
                             %system-manifest
                             %cross-manifest
                             %cross-bootstrap-manifest))
ub.com/facebookresearch/faiss.git") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 "0pk15jfa775cy2pqmzq62nhd6zfjxmpvz5h731197c28aq3zw39w")) (modules '((guix build utils))) (snippet '(begin (substitute* "utils.cpp" (("#include ") "#ifdef __SSE__\n#include \n#endif")) #t)))) (build-system cmake-build-system) (arguments `(#:configure-flags (list "-DBUILD_WITH_GPU=OFF" ; thanks, but no thanks, CUDA. "-DBUILD_TUTORIAL=OFF") ; we don't need those #:phases (modify-phases %standard-phases (add-after 'unpack 'prepare-build (lambda _ (let ((features (list ,@(let ((system (or (%current-target-system) (%current-system)))) (cond ((string-prefix? "x86_64" system) '("-mavx" "-msse2" "-mpopcnt")) ((string-prefix? "i686" system) '("-msse2" "-mpopcnt")) (else '())))))) (substitute* "CMakeLists.txt" (("-m64") "") (("-mpopcnt") "") ; only some architectures (("-msse4") (string-append (string-join features) " -I" (getcwd))) ;; Build also the shared library (("ARCHIVE DESTINATION lib") "LIBRARY DESTINATION lib") (("add_library.*" m) "\ add_library(objlib OBJECT ${faiss_cpu_headers} ${faiss_cpu_cpp}) set_property(TARGET objlib PROPERTY POSITION_INDEPENDENT_CODE 1) add_library(${faiss_lib}_static STATIC $) add_library(${faiss_lib} SHARED $) install(TARGETS ${faiss_lib}_static ARCHIVE DESTINATION lib) \n"))) ;; See https://github.com/facebookresearch/faiss/issues/520 (substitute* "IndexScalarQuantizer.cpp" (("#define USE_AVX") "")) ;; Make header files available for compiling tests. (mkdir-p "faiss") (for-each (lambda (file) (mkdir-p (string-append "faiss/" (dirname file))) (copy-file file (string-append "faiss/" file))) (find-files "." "\\.h$")) #t)) (replace 'check (lambda _ (invoke "make" "-C" "tests" (format #f "-j~a" (parallel-job-count))))) (add-after 'install 'remove-tests (lambda* (#:key outputs #:allow-other-keys) (delete-file-recursively (string-append (assoc-ref outputs "out") "/test")) #t))))) (inputs `(("openblas" ,openblas))) (native-inputs `(("googletest" ,googletest))) (home-page "https://github.com/facebookresearch/faiss") (synopsis "Efficient similarity search and clustering of dense vectors") (description "Faiss is a library for efficient similarity search and clustering of dense vectors. It contains algorithms that search in sets of vectors of any size, up to ones that possibly do not fit in RAM. It also contains supporting code for evaluation and parameter tuning.") (license license:bsd-3))) (define-public python-faiss (package (inherit faiss) (name "python-faiss") (build-system python-build-system) (arguments `(#:phases (modify-phases %standard-phases (add-after 'unpack 'chdir (lambda _ (chdir "python") #t)) (add-after 'chdir 'build-swig (lambda* (#:key inputs #:allow-other-keys) (with-output-to-file "../makefile.inc" (lambda () (let ((python-version ,(version-major+minor (package-version python)))) (format #t "\ PYTHONCFLAGS =-I~a/include/python~am/ -I~a/lib/python~a/site-packages/numpy/core/include LIBS = -lpython~am -lfaiss SHAREDFLAGS = -shared -fopenmp CXXFLAGS = -fpermissive -std=c++11 -fopenmp -fPIC CPUFLAGS = ~{~a ~}~%" (assoc-ref inputs "python*") python-version (assoc-ref inputs "python-numpy") python-version python-version (list ,@(let ((system (or (%current-target-system) (%current-system)))) (cond ((string-prefix? "x86_64" system) '("-mavx" "-msse2" "-mpopcnt")) ((string-prefix? "i686" system) '("-msse2" "-mpopcnt")) (else '())))))))) (substitute* "Makefile" (("../libfaiss.a") "")) (invoke "make" "cpu")))))) (inputs `(("faiss" ,faiss) ("openblas" ,openblas) ("python*" ,python) ("swig" ,swig))) (propagated-inputs `(("python-matplotlib" ,python-matplotlib) ("python-numpy" ,python-numpy))) (description "Faiss is a library for efficient similarity search and clustering of dense vectors. This package provides Python bindings to the Faiss library."))) (define-public python-leidenalg (package (name "python-leidenalg") (version "0.7.0") (source (origin (method url-fetch) (uri (pypi-uri "leidenalg" version)) (sha256 (base32 "15fwld9hdw357rd026mzcwpah5liy4f33vc9x9kwy37g71b2rjf1")))) (build-system python-build-system) (arguments '(#:tests? #f)) ; tests are not included (native-inputs `(("pkg-config" ,pkg-config))) (inputs `(("igraph" ,igraph))) (propagated-inputs `(("python-igraph" ,python-igraph))) (home-page "https://github.com/vtraag/leidenalg") (synopsis "Community detection in large networks") (description "Leiden is a general algorithm for methods of community detection in large networks. This package implements the Leiden algorithm in C++ and exposes it to Python. Besides the relative flexibility of the implementation, it also scales well, and can be run on graphs of millions of nodes (as long as they can fit in memory). The core function is @code{find_partition} which finds the optimal partition using the Leiden algorithm, which is an extension of the Louvain algorithm, for a number of different methods.") (license license:gpl3+))) (define-public edge-addition-planarity-suite (package (name "edge-addition-planarity-suite") (version "3.0.0.5") (source (origin (method git-fetch) (uri (git-reference (url (string-append "https://github.com/graph-algorithms/" name)) (commit (string-append "Version_" version)))) (file-name (git-file-name name version)) (sha256 (base32 "01cm7ay1njkfsdnmnvh5zwc7wg7x189hq1vbfhh9p3ihrbnmqzh8")))) (build-system gnu-build-system) (native-inputs `(("autoconf" ,autoconf) ("automake" ,automake) ("libtool" ,libtool))) (synopsis "Embedding of planar graphs") (description "The package provides a reference implementation of the linear time edge addition algorithm for embedding planar graphs and isolating planarity obstructions.") (license license:bsd-3) (home-page "https://github.com/graph-algorithms/edge-addition-planarity-suite"))) (define-public rw (package (name "rw") ;; There is a version 0.8, but the tarball is broken with symlinks ;; to /usr/share. (version "0.7") (source (origin (method url-fetch) (uri (string-append "mirror://sourceforge/rankwidth/" "rw-" version ".tar.gz")) (sha256 (base32 "1rv2v42x2506x7f10349m1wpmmfxrv9l032bkminni2gbip9cjg0")))) (build-system gnu-build-system) (native-inputs `(("pkg-config" ,pkg-config))) (inputs `(("igraph" ,igraph))) (home-page "https://sourceforge.net/projects/rankwidth/") (synopsis "Rank-width and rank-decomposition of graphs") (description "rw computes rank-width and rank-decompositions of graphs.") (license license:gpl2+)))