• # Paquets pour Guix

    Posté par . En réponse à la dépêche Gestion de paquets et DevOps avec Nix, tour d’horizon sur un cas concret. Évalué à 4. Dernière modification le 28 janvier 2020 à 19:08.

    Le projet jouet mymathserver dépend de cpprestsdk qui est le point sensible à empaqueter car le code n'est pas très robuste. Pour s'en convaincre, il suffit d'aller faire un tour sur les issues GitHub.

    https://github.com/microsoft/cpprestsdk/issues

    Donc, il faut un peu tricoter avec la version de Boost.

    Du côté de Guix, le paquet websocketpp est dans disponible après la bonne version de Boost. Donc on pourrait s'en sortir avec guix time-machine. Mais beaucoup de substituts ne sont plus disponibles donc il y aurait beaucoup de compilations à faire—ce qui n'est pas un problème en soi mais pas le but ici.

    Bref! en plus du projet jouet mymathserver et de cpprestsdk comme dans l'article initial, j'ai "empaqueté" websocketpp et une vieille version de boost. Empaqueter est un bien grand mot puisque ce sont les vieux paquets dépoussiérés à coup de git show.

    Finalement, on compare des pommes et des oranges puisque le tour d'horizon a été fait avec ce qui était facile pour Nix (2 paquets personnalisés) et donc dans une autre configuration, cela aurait été Nix qui aurait dû fournir plus de paquets personnalisés. Donc il faut s'arrêter après les 2 mêmes paquets, les 2 autres derniers sont juste là pour éviter de recompiler le monde entier.

    Ceci dit, avec ces définitions, on est capable de reproduire la première partie.


    Le fichier disons /tmp/test/linuxfr.scm contient les paquets personnalisés ci-dessous.

    Pour tout construire, il faut faire:

     guix build -L /tmp/test mymathserver
    

    En terme de reproductibilité, si vous utilisez la time-machine :

     guix time-machine --commit=b3e28b5ef5e23e564eeac8823ad2c837f7c40650 \
     -- build -L /tmp/test mymathserver
    

    vous devriez compiler au bit près la même chose que moi. Donc normalement, vous devriez avoir: /gnu/store/hqhsc61v4xpj1ld0dwvf8gabxr3x0dwc-mymathserver-0.1 comme résultat. Sinon, il ya une source de non-déterminisme.

    Je ferai un autre commentaire pour donner l'équivalent des commandes. :-)


    (define-module (linuxfr)
     #:use-module (guix download)
     #:use-module (guix git-download)
     #:use-module (guix packages)
     #:use-module (guix build-system cmake)
     ;; boost
     #:use-module (guix build-system gnu)
     #:use-module (gnu packages)
     #:use-module (gnu packages perl)
     #:use-module (gnu packages python)
     #:use-module (gnu packages shells)
     #:use-module (gnu packages icu4c)
     #:use-module (gnu packages tls)
     #:use-module (gnu packages compression)
     #:use-module (gnu packages check)
     )
    (define-public mymathserver
     (package
     (name "mymathserver")
     (version "0.1")
     (source (origin
     (method git-fetch)
     (uri (git-reference
     (url "https://gitlab.com/nokomprendo/mymathserver")
     (commit (string-append "v" version))))
     (file-name (git-file-name name version))
     (sha256
     (base32 "0vvq2z2pjdr7dm6s4d6a3ikp7lw391lk4mdlqd18rgmr2jqfhl0b"))))
     (build-system cmake-build-system)
     (arguments '(#:tests? #f))
     (native-inputs
     `(("boost" ,boost-old)
     ("cpprestsdk" ,cpprestsdk)
     ("gtest" ,googletest)
     ("openssl" ,openssl)))
     (synopsis "Toy example")
     (description "Nothing relevant")
     (home-page "https://gitlab.com/nokomprendo/mymathserver")
     (license #f)))
    (define-public cpprestsdk
     (package
     (name "cpprestsdk")
     (version "v2.10.14")
     (source (origin
     (method git-fetch)
     (uri (git-reference
     (url "https://github.com/microsoft/cpprestsdk")
     (commit version)))
     (file-name (git-file-name name version))
     (sha256
     (base32 "0z1yblqszs7ig79l6lky02jmrs8zmpi7pnzns237p0w59pipzrvs"))))
     (build-system cmake-build-system)
     (native-inputs
     `(("websocketpp" ,my-websocketpp)
     ("boost" ,boost-old)
     ("openssl" ,openssl)
     ("zlib" ,zlib)))
     (arguments '(#:tests? #f
     ;; Warnings not always addressed by upstream, see:
     ;; https://github.com/microsoft/cpprestsdk/issues/724
     #:configure-flags '("-DWERROR=OFF")))
     (synopsis "C++ REST SDK by Microsoft")
     (description "The C++ REST SDK is a Microsoft project for cloud-based
    client-server communication in native code using a modern asynchronous C++ API
    design. This project aims to help C++ developers connect to and interact with
    services.")
     (home-page "https://github.com/microsoft/cpprestsdk")
     (license #f)))
    ;;;
    ;;; End here. 
    ;;; Below hack to build cpprestsdk with the correct versions
    ;;; without rebuilding the world.
    ;;;
    (define-public my-websocketpp
     (package
     (name "websocketpp")
     (version "0.8.1")
     (source
     (origin
     (method git-fetch)
     (uri (git-reference
     (url "https://github.com/zaphoyd/websocketpp.git")
     (commit version)))
     (file-name (git-file-name name version))
     (sha256
     (base32 "12ffczcrryh74c1xssww35ic6yiy2l2xgdd30lshiq9wnzl2brgy"))))
     (build-system cmake-build-system)
     (native-inputs
     `(("boost" ,boost-old)
     ("openssl" ,openssl)))
     (arguments '(#:configure-flags '("-DBUILD_TESTS=ON")
     #:phases
     (modify-phases %standard-phases
     (add-after 'install 'remove-tests
     (lambda* (#:key outputs #:allow-other-keys)
     (let* ((install-dir (assoc-ref outputs "out"))
     (bin-dir (string-append install-dir "/bin")))
     (delete-file-recursively bin-dir)
     #t))))))
     (home-page "https://www.zaphoyd.com/websocketpp/")
     (synopsis "C++ library implementing the WebSocket protocol")
     (description "WebSocket++ is a C++ library that can be used to implement
    WebSocket functionality. The goals of the project are to provide a WebSocket
    implementation that is simple, portable, flexible, lightweight, low level, and
    high performance.")
     (license #f))) ;license:bsd-3
    (define-public boost-old
     (package
     (name "boost")
     (version "1.67.0")
     (source (origin
     (method url-fetch)
     (uri (string-append
     "mirror://sourceforge/boost/boost/" version "/boost_"
     (string-map (lambda (x) (if (eq? x #\.) #\_ x)) version)
     ".tar.bz2"))
     (sha256
     (base32
     "1fmdlmkzsrd46wwk834jsi2ypxj68w2by0rfcg2pzrafk5rck116"))
     (patches '("/tmp/test/patches/boost-fix-icu-build.patch"))))
     (build-system gnu-build-system)
     (inputs `(("icu4c" ,icu4c)
     ("zlib" ,zlib)))
     (native-inputs
     `(("perl" ,perl)
     ("python" ,python-2)
     ("tcsh" ,tcsh)))
     (arguments
     `(#:tests? #f
     #:make-flags
     (list "threading=multi" "link=shared"
     ;; Set the RUNPATH to $libdir so that the libs find each other.
     (string-append "linkflags=-Wl,-rpath="
     (assoc-ref %outputs "out") "/lib")
     ;; Boost's 'context' library is not yet supported on mips64, so
     ;; we disable it. The 'coroutine' library depends on 'context',
     ;; so we disable that too.
     ,@(if (string-prefix? "mips64" (or (%current-target-system)
     (%current-system)))
     '("--without-context"
     "--without-coroutine" "--without-coroutine2")
     '()))
     #:phases
     (modify-phases %standard-phases
     (delete 'bootstrap)
     (replace 'configure
     (lambda* (#:key inputs outputs #:allow-other-keys)
     (let ((icu (assoc-ref inputs "icu4c"))
     (out (assoc-ref outputs "out")))
     (substitute* '("libs/config/configure"
     "libs/spirit/classic/phoenix/test/runtest.sh"
     "tools/build/doc/bjam.qbk"
     "tools/build/src/engine/execunix.c"
     "tools/build/src/engine/Jambase"
     "tools/build/src/engine/jambase.c")
     (("/bin/sh") (which "sh")))
     (setenv "SHELL" (which "sh"))
     (setenv "CONFIG_SHELL" (which "sh"))
     (invoke "./bootstrap.sh"
     (string-append "--prefix=" out)
     ;; Auto-detection looks for ICU only in traditional
     ;; install locations.
     (string-append "--with-icu=" icu)
     "--with-toolset=gcc"))))
     (replace 'build
     (lambda* (#:key make-flags #:allow-other-keys)
     (apply invoke "./b2"
     (format #f "-j~a" (parallel-job-count))
     make-flags)))
     (replace 'install
     (lambda* (#:key make-flags #:allow-other-keys)
     (apply invoke "./b2" "install" make-flags))))))
     (home-page "http://www.boost.org")
     (synopsis "Peer-reviewed portable C++ source libraries")
     (description
     "A collection of libraries intended to be widely useful, and usable
    across a broad spectrum of applications.")
     (license #f)))
    ;; (license (license:x11-style "http://www.boost.org/LICENSE_1_0.txt"
    ;; "Some components have other similar licences."))