From patchwork Fri Jun 19 13:36:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Edouard Klein X-Patchwork-Id: 22780 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 22F7127BBE3; Fri, 19 Jun 2020 14:37:12 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 5065527BBE1 for ; Fri, 19 Jun 2020 14:37:11 +0100 (BST) Received: from localhost ([::1]:48154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmHCg-0001X3-SF for patchwork@mira.cbaines.net; Fri, 19 Jun 2020 09:37:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmHCY-0001VW-G0 for guix-patches@gnu.org; Fri, 19 Jun 2020 09:37:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:43907) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jmHCY-0006cY-68 for guix-patches@gnu.org; Fri, 19 Jun 2020 09:37:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jmHCY-0000I9-3t for guix-patches@gnu.org; Fri, 19 Jun 2020 09:37:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41949] [PATCH 3/5] guix: Add gerbil-build-system References: <875zbn2o5i.fsf@alice.lan> In-Reply-To: <875zbn2o5i.fsf@alice.lan> Resent-From: Edouard Klein Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 19 Jun 2020 13:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41949 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 41949@debbugs.gnu.org Received: via spool by 41949-submit@debbugs.gnu.org id=B41949.15925737941067 (code B ref 41949); Fri, 19 Jun 2020 13:37:02 +0000 Received: (at 41949) by debbugs.gnu.org; 19 Jun 2020 13:36:34 +0000 Received: from localhost ([127.0.0.1]:55449 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jmHC5-0000H8-EM for submit@debbugs.gnu.org; Fri, 19 Jun 2020 09:36:33 -0400 Received: from sender4-op-o11.zoho.com ([136.143.188.11]:17131) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jmHC3-0000Gz-Bl for 41949@debbugs.gnu.org; Fri, 19 Jun 2020 09:36:32 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1592573788; cv=none; d=zohomail.com; s=zohoarc; b=X+MmEuesCb4kqUYgpNcQ8rcpEgsNs2D8MtoTyA2iuT2p3uEFmL2dMRXfeIgFpR4wQqgu/gB90s37whLxIyOYfwPaO4LnZjwIroCP6kUVGosvmdoVYRiwbHD+tvKU3lnYgckA67hC6xzcX8H07AoCjW3SeHg1tYKRsL2IBg0p970= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592573788; h=Content-Type:Content-Transfer-Encoding:Date:From:MIME-Version:Message-ID:Subject:To; bh=aVrQLLbpbnJ8eLff7y9O4br9VFcO+gyWDm8PjHZAqZ4=; b=JIaC5lREPW/yM5dcOIICJNcHhItgzrZt08ScuI9L1pT9AgWL24BNlRP1AwJIGGHz2dMeSrc7HxZa71JMRUZ8/nzoAhH/Ewr3YSV7Te29nDwzJAyLvbMjmiI9tUsEZ/ckBkLEEkj2LPfgPtxDl2G+RvVbb7EDWXHzomra9f9rn/Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=beaver-labs.com; spf=pass smtp.mailfrom=edk@beaver-labs.com; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1592573788; s=zoho; d=beaver-labs.com; i=edk@beaver-labs.com; h=From:To:Subject:Message-ID:Date:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=aVrQLLbpbnJ8eLff7y9O4br9VFcO+gyWDm8PjHZAqZ4=; b=bXpinrr97B6570eNzd4h+9nVB0KFYfDKUqa9HHSoPSr8/9sqWawps8MNHMPvpxI8 kJhUl7U8b0lCb03+EV/LweCooa6oYHckEgak7ukJGr62+FTcSMdCAGPa2Lb4MKSV93h XMT7CHjnDAOmLjOZn0pXqhUBv0fC2j6XDaWrmk/Q= Received: from alice.lan (lfbn-idf1-1-1299-119.w90-79.abo.wanadoo.fr [90.79.23.119]) by mx.zohomail.com with SMTPS id 1592573787941652.1032957369371; Fri, 19 Jun 2020 06:36:27 -0700 (PDT) User-agent: mu4e 1.4.6; emacs 26.3 From: Edouard Klein Message-ID: <87wo4318kn.fsf@alice.lan> Date: Fri, 19 Jun 2020 15:36:24 +0200 MIME-Version: 1.0 X-ZohoMailClient: External X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/build-system/gerbil.scm: New file. (%gerbil-build-system-modules): New variable. (gerbil-build): New variable (gerbil-build-system): New variable * guix/build/gerbil-build-system.scm: New file. (%standard-phases): New variable. (gerbil-build): New variable. --- guix/build-system/gerbil.scm | 119 +++++++++++++++++++++++++++++ guix/build/gerbil-build-system.scm | 102 +++++++++++++++++++++++++ 2 files changed, 221 insertions(+) create mode 100644 guix/build-system/gerbil.scm create mode 100644 guix/build/gerbil-build-system.scm diff --git a/guix/build-system/gerbil.scm b/guix/build-system/gerbil.scm new file mode 100644 index 0000000000..eea0261b2a --- /dev/null +++ b/guix/build-system/gerbil.scm @@ -0,0 +1,119 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2020 Edouard Klein +;;; +;;; 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 (guix build-system gerbil) + #:use-module (guix store) + #:use-module (guix utils) + #:use-module (guix derivations) + #:use-module (guix search-paths) + #:use-module (guix build-system) + #:use-module (guix build-system gnu) + #:use-module (guix packages) + #:use-module (ice-9 match) + #:export (%gerbil-build-system-modules + gerbil-build + gerbil-build-system)) + +(define %gerbil-build-system-modules + ;; Build-side modules imported by default. + `((guix build gerbil-build-system) + ,@%gnu-build-system-modules)) + +(define (default-gerbil) + "Return the default Gerbil package." + ;; Do not use `@' to avoid introducing circular dependencies. + (let ((module (resolve-interface '(gnu packages scheme)))) + (module-ref module 'gerbil))) + +(define* (lower name + #:key source inputs native-inputs outputs system target + (gerbil (default-gerbil)) + #:allow-other-keys + #:rest arguments) + "Return a bag for NAME." + (define private-keywords + '(#:source #:target #:inputs #:native-inputs)) + (bag + (name name) + (system system) + (target target) + (host-inputs `(,@(if source + `(("source" ,source)) + '()) + ,@inputs + ;; Keep the standard inputs of 'gnu-build-system'. + ,@(standard-packages))) + (build-inputs `(("gerbil" ,gerbil) + ,@native-inputs)) + (outputs outputs) + (build gerbil-build) + (arguments (strip-keyword-arguments private-keywords arguments)))) + +(define* (gerbil-build store name inputs + #:key + (phases '(@ (guix build gerbil-build-system) + %standard-phases)) + (outputs '("out")) + (search-paths '()) + (system (%current-system)) + (guile #f) + (imported-modules %gerbil-build-system-modules) + (modules '((guix build gerbil-build-system) + (guix build utils)))) + "Build SOURCE using GERBIL and with INPUTS." + (define builder + `(begin + (use-modules ,@modules) + (gerbil-build #:name ,name + #:source ,(match (assoc-ref inputs "source") + (((? derivation? source)) + (derivation->output-path source)) + ((source) + source) + (source + source)) + #:system ,system + #:phases ,phases + #:outputs %outputs + #:search-paths ',(map search-path-specification->sexp + search-paths) + #:inputs %build-inputs))) + + (define guile-for-build + (match guile + ((? package?) + (package-derivation store guile system #:graft? #f)) + (#f ; the default + (let* ((distro (resolve-interface '(gnu packages commencement))) + (guile (module-ref distro 'guile-final))) + (package-derivation store guile system #:graft? #f))))) + + (build-expression->derivation store name builder + #:inputs inputs + #:system system + #:modules imported-modules + #:outputs outputs + #:guile-for-build guile-for-build)) + +(define gerbil-build-system + (build-system + (name 'gerbil) + (description "The standard Gerbil build system") + (lower lower))) + +;;; gerbil.scm ends here diff --git a/guix/build/gerbil-build-system.scm b/guix/build/gerbil-build-system.scm new file mode 100644 index 0000000000..e6763b841a --- /dev/null +++ b/guix/build/gerbil-build-system.scm @@ -0,0 +1,102 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2020 Edouard Klein +;;; +;;; 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 (guix build gerbil-build-system) + #:use-module ((guix build gnu-build-system) #:prefix gnu:) + #:use-module (guix build utils) + #:use-module (ice-9 match) + #:use-module (ice-9 ftw) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:export (%standard-phases + gerbil-build)) + +;; Gerbil's build system and package management is documented at +;; https://cons.io/guide/package-manager.html +;; https://cons.io/guide/build.html +;; https://cons.io/guide/env-vars.html +;; +;; The compiler is writing its output in the directory +;; pointed to by GERBIL_PATH (or ~/.gerbil by default). +;; +;; Every package is supposed to have a build.ss script +;; whose default action (when called with no argument) +;; is to compile the package. +;; +;; The GERBIL_LOADPATH env variable tells gerbil's runtime +;; where it can find its loadable code. +;; +;; GERBIL_HOME tells gerbil where to find its runtime +;; and standard library +;; +;; This build system therefore just +;; - makes GERBIL_PATH point to the output directory in the store, +;; - makes GERBIL_LOADPATH point to the lib subdir +;; of all the gerbil inputs, +;; - calls ./build.ss, +;; - wrap any executable with GERBIL_LOADPATH set the the lib +;; subdir of all the gerbil inputs plus the lib subdir +;; of the current package's output, and with GERBIL_HOME +;; set to the lib directory of the 'gerbil' input + +(define (loadpath inputs) + (string-join (map (match-lambda + ((_ . path) + (string-append path "/lib"))) + ;; Restrict to inputs beginning with "gerbil-". + (filter (match-lambda + ((name . _) + (string-prefix? "gerbil-" name))) + inputs)) + ":")) + +(define (gerbil-home inputs) + (assoc-ref inputs "gerbil")) + +(define* (install #:key inputs outputs #:allow-other-keys) + "Install a given Gerbil package." + (let ((out (assoc-ref outputs "out")) + (in (loadpath inputs))) + (setenv "GERBIL_PATH" out) + (setenv "GERBIL_LOADPATH" in) + (invoke "./build.ss")) + #t) + +(define* (wrap #:key inputs outputs #:allow-other-keys) + "Wrap any executable with a proper GERBIL_LOADPATH and GERBIL_HOME" + (let* ((out (assoc-ref outputs "out")) + (in (loadpath inputs)) + (gerbil-loadpath (string-append out "/lib:" in))) + (for-each (cut wrap-program <> + `("GERBIL_LOADPATH" = (,gerbil-loadpath)) + `("GERBIL_HOME" = (,(gerbil-home inputs)))) + (find-files (string-append out "/bin"))))) + +(define %standard-phases + (modify-phases gnu:%standard-phases + (delete 'bootstrap) + (delete 'configure) ;not needed + (delete 'build) ;build.ss does both build and install + (delete 'check) ;no standard way of testing + (replace 'install install) + (add-after 'install 'wrap wrap))) + +(define* (gerbil-build #:key inputs (phases %standard-phases) + #:allow-other-keys #:rest args) + "Build the given Gerbil package, applying all of PHASES in order." + (apply gnu:gnu-build #:inputs inputs #:phases phases args))