From cddf7d95c9134075aec45e2f2e49073f92aadfcb Mon Sep 17 00:00:00 2001 From: Sarah Morgensen Date: Sun, 19 Sep 2021 22:20:50 -0700 Subject: [PATCH 3/4] build-system/go: Add pre-built standard library as implicit input. * gnu/packages/golang.scm (make-go-std): New procedure. * guix/build-system/go.scm (make-go-std): New procedure. (lower): Use it. Add pre-built standard library to inputs. Signed-off-by: Leo Famulari --- gnu/packages/golang.scm | 30 ++++++++++++++++++++++++++++++ guix/build-system/go.scm | 16 ++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/gnu/packages/golang.scm b/gnu/packages/golang.scm index c863388475..7989a3a138 100644 --- a/gnu/packages/golang.scm +++ b/gnu/packages/golang.scm @@ -806,6 +806,36 @@ (define-public go-1.17 (define-public go go-1.14) +(define-public (make-go-std go) + "Return a package which builds the standard library for Go compiler GO." + (package + (name (string-append (package-name go) "-std")) + (version (package-version go)) + (source #f) + (build-system go-build-system) + (arguments + `(#:import-path "std" + #:build-flags `("-pkgdir" "pkg") ; "Install" to build directory. + #:allow-go-reference? #t + #:substitutable? #f ; Faster to build than download. + #:tests? #f ; Already tested in the main Go build. + #:go ,go + #:phases + (modify-phases %standard-phases + (delete 'unpack) + (replace 'install + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (out-cache (string-append out "/var/cache/go/build"))) + (copy-recursively (getenv "GOCACHE") out-cache) + (delete-file (string-append out-cache "/trim.txt")) + (delete-file (string-append out-cache "/README"))))) + (delete 'install-license-files)))) + (home-page (package-home-page go)) + (synopsis "Cached standard library build for Go") + (description (package-description go)) + (license (package-license go)))) + (define-public go-0xacab-org-leap-shapeshifter (let ((commit "0aa6226582efb8e563540ec1d3c5cfcd19200474") (revision "12")) diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm index 0b2bf1c11b..09148f8730 100644 --- a/guix/build-system/go.scm +++ b/guix/build-system/go.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2020 Jakub Kądziołka ;;; Copyright © 2021 Ludovic Courtès ;;; Copyright © 2021 Efraim Flashner +;;; Copyright © 2021 Sarah Morgensen ;;; ;;; This file is part of GNU Guix. ;;; @@ -112,6 +113,9 @@ (define (default-go) (let ((go (resolve-interface '(gnu packages golang)))) (module-ref go 'go))) +(define (make-go-std) + (module-ref (resolve-interface '(gnu packages golang)) 'make-go-std)) + (define* (lower name #:key source inputs native-inputs outputs system target (go (default-go)) @@ -121,6 +125,14 @@ (define* (lower name (define private-keywords '(#:target #:go #:inputs #:native-inputs)) + (define inputs-with-cache + ;; XXX: Avoid a circular dependency. This should be rewritten with + ;; 'package-mapping' or similar. + (let ((go-std-name (string-append (package-name go) "-std"))) + (if (string-prefix? go-std-name name) + inputs + (cons `(,go-std-name ,((make-go-std) go)) inputs)))) + (bag (name name) (system system) @@ -130,7 +142,7 @@ (define private-keywords '()) ,@`(("go" ,go)) ,@native-inputs - ,@(if target '() inputs) + ,@(if target '() inputs-with-cache) ,@(if target ;; Use the standard cross inputs of ;; 'gnu-build-system'. @@ -138,7 +150,7 @@ (define private-keywords '()) ;; Keep the standard inputs of 'gnu-build-system'. ,@(standard-packages))) - (host-inputs (if target inputs '())) + (host-inputs (if target inputs-with-cache '())) ;; The cross-libc is really a target package, but for bootstrapping ;; reasons, we can't put it in 'host-inputs'. Namely, 'cross-gcc' is a -- 2.34.0