diff options
author | Marius Bakke <mbakke@fastmail.com> | 2019-03-23 23:16:55 +0100 |
---|---|---|
committer | Marius Bakke <mbakke@fastmail.com> | 2019-03-23 23:16:55 +0100 |
commit | 8c14f7f8a7ab0722bf4c9f92fd28ae85514d564f (patch) | |
tree | adc5d29e9c2dcda5befa0ca81f1af8df23294947 /guix/build | |
parent | 2f33a7321e5e37d37f57c229c8079cb4ffd10834 (diff) | |
parent | 3374e9207f5244c20402a3c5513fe562140fef47 (diff) |
Merge branch 'staging' into core-updates
Diffstat (limited to 'guix/build')
-rw-r--r-- | guix/build/go-build-system.scm | 139 | ||||
-rw-r--r-- | guix/build/rakudo-build-system.scm | 145 |
2 files changed, 221 insertions, 63 deletions
diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm index 022d4fe16b..1a716cea77 100644 --- a/guix/build/go-build-system.scm +++ b/guix/build/go-build-system.scm @@ -1,6 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016 Petter <petter@mykolab.ch> -;;; Copyright © 2017 Leo Famulari <leo@famulari.name> +;;; Copyright © 2017, 2019 Leo Famulari <leo@famulari.name> ;;; ;;; This file is part of GNU Guix. ;;; @@ -19,6 +19,7 @@ (define-module (guix build go-build-system) #:use-module ((guix build gnu-build-system) #:prefix gnu:) + #:use-module (guix build union) #:use-module (guix build utils) #:use-module (ice-9 match) #:use-module (srfi srfi-1) @@ -38,24 +39,26 @@ ;; results. [0] ;; Go software is developed and built within a particular file system hierarchy -;; structure called a 'workspace' [1]. This workspace is found by Go -;; via the GOPATH environment variable. Typically, all Go source code -;; and compiled objects are kept in a single workspace, but it is -;; possible for GOPATH to contain a list of directories, and that is -;; what we do in this go-build-system. [2] +;; structure called a 'workspace' [1]. This workspace can be found by Go via +;; the GOPATH environment variable. Typically, all Go source code and compiled +;; objects are kept in a single workspace, but GOPATH may be a list of +;; directories [2]. In this go-build-system we create a filesystem union of +;; the Go-language dependencies. Previously, we made GOPATH a list of store +;; directories, but stopped because Go programs started keeping references to +;; these directories in Go 1.11: +;; <https://bugs.gnu.org/33620>. ;; -;; Go software, whether a package or a command, is uniquely named using -;; an 'import path'. The import path is based on the URL of the -;; software's source. Since most source code is provided over the -;; internet, the import path is typically a combination of the remote -;; URL and the source repository's file system structure. For example, -;; the Go port of the common `du` command is hosted on github.com, at -;; <https://github.com/calmh/du>. Thus, the import path is -;; <github.com/calmh/du>. [3] +;; Go software, whether a package or a command, is uniquely named using an +;; 'import path'. The import path is based on the URL of the software's source. +;; Because most source code is provided over the internet, the import path is +;; typically a combination of the remote URL and the source repository's file +;; system structure. For example, the Go port of the common `du` command is +;; hosted on github.com, at <https://github.com/calmh/du>. Thus, the import +;; path is <github.com/calmh/du>. [3] ;; -;; It may be possible to programatically guess a package's import path -;; based on the source URL, but we don't try that in this revision of -;; the go-build-system. +;; It may be possible to automatically guess a package's import path based on +;; the source URL, but we don't try that in this revision of the +;; go-build-system. ;; ;; Modules of modular Go libraries are named uniquely with their ;; file system paths. For example, the supplemental but "standardized" @@ -75,6 +78,17 @@ ;; file system union of the required modules of such libraries. I think ;; this could be improved in future revisions of the go-build-system. ;; +;; TODO: +;; * Avoid copying dependencies into the build environment and / or avoid using +;; a tmpdir when creating the inputs union. +;; * Use Go modules [4] +;; * Re-use compiled packages [5] +;; * Avoid the go-inputs hack +;; * Stop needing remove-go-references (-trimpath ? ) +;; * Remove module packages, only offering the full Git repos? This is +;; more idiomatic, I think, because Go downloads Git repos, not modules. +;; What are the trade-offs? +;; ;; [0] `go build`: ;; https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies ;; `go install`: @@ -107,18 +121,44 @@ ;; ;; [2] https://golang.org/doc/code.html#GOPATH ;; [3] https://golang.org/doc/code.html#ImportPaths +;; [4] https://golang.org/cmd/go/#hdr-Modules__module_versions__and_more +;; [5] https://bugs.gnu.org/32919 ;; ;; Code: +(define* (setup-go-environment #:key inputs outputs #:allow-other-keys) + "Prepare a Go build environment for INPUTS and OUTPUTS. Build a filesystem +union of INPUTS. Export GOPATH, which helps the compiler find the source code +of the package being built and its dependencies, and GOBIN, which determines +where executables (\"commands\") are installed to. This phase is sometimes used +by packages that use (guix build-system gnu) but have a handful of Go +dependencies, so it should be self-contained." + ;; Using the current working directory as GOPATH makes it easier for packagers + ;; who need to manipulate the unpacked source code. + (setenv "GOPATH" (getcwd)) + (setenv "GOBIN" (string-append (assoc-ref outputs "out") "/bin")) + (let ((tmpdir (tmpnam))) + (match (go-inputs inputs) + (((names . directories) ...) + (union-build tmpdir (filter directory-exists? directories) + #:create-all-directories? #t + #:log-port (%make-void-port "w")))) + ;; XXX A little dance because (guix build union) doesn't use mkdir-p. + (copy-recursively tmpdir + (string-append (getenv "GOPATH")) + #:keep-mtime? #t) + (delete-file-recursively tmpdir)) + #t) + (define* (unpack #:key source import-path unpack-path #:allow-other-keys) - "Unpack SOURCE in the UNPACK-PATH, or the IMPORT-PATH is the UNPACK-PATH is -unset. When SOURCE is a directory, copy it instead of unpacking." + "Relative to $GOPATH, unpack SOURCE in the UNPACK-PATH, or the IMPORT-PATH is +the UNPACK-PATH is unset. When SOURCE is a directory, copy it instead of +unpacking." (if (string-null? import-path) ((display "WARNING: The Go import path is unset.\n"))) (if (string-null? unpack-path) (set! unpack-path import-path)) - (mkdir "src") - (let ((dest (string-append "src/" unpack-path))) + (let ((dest (string-append (getenv "GOPATH") "/src/" unpack-path))) (mkdir-p dest) (if (file-is-directory? source) (begin @@ -128,15 +168,6 @@ unset. When SOURCE is a directory, copy it instead of unpacking." (invoke "unzip" "-d" dest source) (invoke "tar" "-C" dest "-xvf" source))))) -(define* (install-source #:key install-source? outputs #:allow-other-keys) - "Install the source code to the output directory." - (let* ((out (assoc-ref outputs "out")) - (source "src") - (dest (string-append out "/" source))) - (when install-source? - (copy-recursively source dest #:keep-mtime? #t)) - #t)) - (define (go-package? name) (string-prefix? "go-" name)) @@ -155,27 +186,6 @@ unset. When SOURCE is a directory, copy it instead of unpacking." (_ #f)) inputs)))) -(define* (setup-environment #:key inputs outputs #:allow-other-keys) - "Export the variables GOPATH and GOBIN, which are based on INPUTS and OUTPUTS, -respectively." - (let ((out (assoc-ref outputs "out"))) - ;; GOPATH is where Go looks for the source code of the build's dependencies. - (set-path-environment-variable "GOPATH" - ;; XXX Matching "." hints that we could do - ;; something simpler here... - (list ".") - (match (go-inputs inputs) - (((_ . dir) ...) - dir))) - - ;; Add the source code of the package being built to GOPATH. - (if (getenv "GOPATH") - (setenv "GOPATH" (string-append (getcwd) ":" (getenv "GOPATH"))) - (setenv "GOPATH" (getcwd))) - ;; Where to install compiled executable files ('commands' in Go parlance'). - (setenv "GOBIN" (string-append out "/bin")) - #t)) - (define* (build #:key import-path #:allow-other-keys) "Build the package named by IMPORT-PATH." (with-throw-handler @@ -193,22 +203,26 @@ respectively." "Here are the results of `go env`:\n")) (invoke "go" "env")))) +;; Can this also install commands??? (define* (check #:key tests? import-path #:allow-other-keys) "Run the tests for the package named by IMPORT-PATH." (when tests? (invoke "go" "test" import-path)) #t) -(define* (install #:key outputs #:allow-other-keys) - "Install the compiled libraries. `go install` installs these files to -$GOPATH/pkg, so we have to copy them into the output directory manually. -Compiled executable files should have already been installed to the store based -on $GOBIN in the build phase." - ;; TODO: From go-1.10 onward, the pkg folder should not be needed (see - ;; https://lists.gnu.org/archive/html/guix-devel/2018-11/msg00208.html). - ;; Remove it? - (when (file-exists? "pkg") - (copy-recursively "pkg" (string-append (assoc-ref outputs "out") "/pkg"))) +(define* (install #:key install-source? outputs import-path unpack-path #:allow-other-keys) + "Install the source code of IMPORT-PATH to the primary output directory. +Compiled executable files (Go \"commands\") should have already been installed +to the store based on $GOBIN in the build phase. +XXX We can't make us of compiled libraries (Go \"packages\")." + (when install-source? + (if (string-null? import-path) + ((display "WARNING: The Go import path is unset.\n"))) + (let* ((out (assoc-ref outputs "out")) + (source (string-append (getenv "GOPATH") "/src/" import-path)) + (dest (string-append out "/src/" import-path))) + (mkdir-p dest) + (copy-recursively source dest #:keep-mtime? #t))) #t) (define* (remove-store-reference file file-name @@ -269,9 +283,8 @@ files in OUTPUTS." (delete 'bootstrap) (delete 'configure) (delete 'patch-generated-file-shebangs) + (add-before 'unpack 'setup-go-environment setup-go-environment) (replace 'unpack unpack) - (add-after 'unpack 'install-source install-source) - (add-before 'build 'setup-environment setup-environment) (replace 'build build) (replace 'check check) (replace 'install install) diff --git a/guix/build/rakudo-build-system.scm b/guix/build/rakudo-build-system.scm new file mode 100644 index 0000000000..dbdeb1ccd2 --- /dev/null +++ b/guix/build/rakudo-build-system.scm @@ -0,0 +1,145 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il> +;;; +;;; 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 (guix build rakudo-build-system) + #:use-module ((guix build gnu-build-system) #:prefix gnu:) + #:use-module (guix build utils) + #:use-module (ice-9 ftw) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:export (%standard-phases + rakudo-build)) + +;; Commentary: +;; +;; Builder-side code of the standard Rakudo package build procedure. +;; +;; Code: + +(define* (check #:key tests? inputs with-prove6? #:allow-other-keys) + (if (and tests? (assoc-ref inputs "perl6-tap-harness")) + ;(if (and tests? with-prove6?) + (invoke "prove6" "-I=lib" "t/") + (format #t "test suite not run~%")) + #t) + +(define* (install #:key inputs outputs with-zef? #:allow-other-keys) + "Install a given Perl6 package." + (let* ((out (assoc-ref outputs "out")) + (perl6 (string-append out "/share/perl6"))) + (if (assoc-ref inputs "perl6-zef") + ;(if with-zef? + (begin + (let ((zef (string-append (assoc-ref inputs "perl6-zef") + "/bin/zef"))) + (setenv "HOME" (getcwd)) + (mkdir-p perl6) + (invoke zef "install" "--verbose" "." + ;; Don't install any of the following: + "--/depends" "--/build-depends" "--/test-depends" + (string-append "--install-to=" perl6)) + (delete-file (string-append perl6 "/repo.lock"))) + #t) + (begin + (let ((inst (string-append (assoc-ref inputs "rakudo") + "/share/perl6/tools/install-dist.p6"))) + (setenv "RAKUDO_RERESOLVE_DEPENDENCIES" "0") + (setenv "RAKUDO_MODULE_DEBUG" "1") ; be verbose while building + (invoke inst (string-append "--to=" perl6) "--for=site")))))) + +(define* (install-libs #:key outputs #:allow-other-keys) + (let ((out (assoc-ref outputs "out")) + (lock "lib/.precomp/.lock")) + (when (file-exists? lock) + (delete-file "lib/.precomp/.lock")) + (copy-recursively "lib" (string-append out "/share/perl6/lib")) + #t)) + +(define* (install-bins #:key outputs #:allow-other-keys) + (let ((out (assoc-ref outputs "out"))) + (when (file-exists? "bin") + (for-each (lambda (file) + (install-file file (string-append out "/bin")) + (chmod (string-append out "/" file) #o555)) + (find-files "bin" ".*"))) + (when (file-exists? "sbin") + (for-each (lambda (file) + (install-file file (string-append out "/sbin")) + (chmod (string-append out "/" file) #o555)) + (find-files "sbin" ".*"))) + #t)) + +(define* (install-resources #:key outputs #:allow-other-keys) + (let ((out (assoc-ref outputs "out"))) + (when (file-exists? "resources") + (copy-recursively "resources" + (string-append out "/share/perl6/resources"))) + #t)) + +(define* (wrap #:key inputs outputs #:allow-other-keys) + (define (list-of-files dir) + (map (cut string-append dir "/" <>) + (or (scandir dir (lambda (f) + (let ((s (stat (string-append dir "/" f)))) + (eq? 'regular (stat:type s))))) + '()))) + + (define bindirs + (append-map (match-lambda + ((_ . dir) + (list (string-append dir "/bin") + (string-append dir "/sbin")))) + outputs)) + + (let* ((out (assoc-ref outputs "out")) + (var `("PERL6LIB" "," prefix + ,(cons (string-append out "/share/perl6/lib," + out "/share/perl6/site/lib," + out "/share/perl6/vendor/lib") + (search-path-as-string->list + (or (getenv "PERL6LIB") "") #\,))))) + (for-each (lambda (dir) + (let ((files (list-of-files dir))) + (for-each (cut wrap-program <> var) + files))) + bindirs) + #t)) + +(define %standard-phases + ;; No need for 'bootstrap, 'configure or 'build. + (modify-phases gnu:%standard-phases + (delete 'bootstrap) + (delete 'configure) + (delete 'build) + (replace 'check check) + (replace 'install install) + (add-before 'install 'install-lib-dir install-libs) + (add-after 'install-lib-dir 'install-resources install-resources) + (add-after 'install-resources 'install-binaries install-bins) + ;; needs to be after 'install-binaries and all 'install phases + (add-after 'install 'wrap wrap))) + +(define* (rakudo-build #:key inputs (phases %standard-phases) + #:allow-other-keys #:rest args) + "Build the given Perl6 package, applying all of PHASES in order." + (apply gnu:gnu-build + #:inputs inputs #:phases phases + args)) + +;;; rakudo-build-system.scm ends here |