diff --git a/doc/guix.texi b/doc/guix.texi index 789e153189..8f65387e92 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -132,6 +132,8 @@ Copyright @copyright{} 2024 Denis 'GNUtoo' Carikli@* Copyright @copyright{} 2024 Fabio Natali@* Copyright @copyright{} 2024 Arnaud Daby-Seesaram@* Copyright @copyright{} 2024 Nigko Yerden@* +Copyright @copyright{} 2024 Troy Figiel@* +Copyright @copyright{} 2024 Sharlatan Hellseher@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -9588,6 +9590,11 @@ the test binary. Build, test and test binary flags can be provided as @code{#:test-flags} parameter, default is @code{'()}. See @code{go help test} and @code{go help testflag} for more details. +The key @code{#:embed-files}, default is @code{'()}, provides a list of +future embedded files or regexps matching files. They will be copied to +build directory after @code{unpack} phase. See +@url{https://pkg.go.dev/embed} for more details. + @end defvar @defvar glib-or-gtk-build-system diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm index e6e8b84e48..97581a14c6 100644 --- a/guix/build-system/go.scm +++ b/guix/build-system/go.scm @@ -6,6 +6,8 @@ ;;; Copyright © 2021, 2023 Efraim Flashner ;;; Copyright © 2021 Sarah Morgensen ;;; Copyright © 2024 Christina O'Donnell +;;; Copyright © 2024 Troy Figiel +;;; Copyright © 2024 Sharlatan Hellseher ;;; ;;; This file is part of GNU Guix. ;;; @@ -197,6 +199,7 @@ commit hash and its date rather than a proper release tag." (outputs '("out")) (search-paths '()) (install-source? #t) + (embed-files ''()) (import-path "") (unpack-path "") (build-flags ''()) @@ -226,6 +229,7 @@ commit hash and its date rather than a proper release tag." #:substitutable? #$substitutable? #:goarch #$goarch #:goos #$goos + #:embed-files #$embed-files #:search-paths '#$(sexp->gexp (map search-path-specification->sexp search-paths)) @@ -264,6 +268,7 @@ commit hash and its date rather than a proper release tag." (system (%current-system)) (goarch (first (go-target target))) (goos (last (go-target target))) + (embed-files ''()) (guile #f) (imported-modules %go-build-system-modules) (modules '((guix build go-build-system) @@ -297,6 +302,7 @@ commit hash and its date rather than a proper release tag." #:target #$target #:goarch #$goarch #:goos #$goos + #:embed-files #$embed-files #:inputs %build-target-inputs #:native-inputs %build-host-inputs #:search-paths '#$(map search-path-specification->sexp diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm index 3f0f5700a1..14cb5ae687 100644 --- a/guix/build/go-build-system.scm +++ b/guix/build/go-build-system.scm @@ -4,10 +4,12 @@ ;;; Copyright © 2019 Maxim Cournoyer ;;; Copyright © 2020 Jack Hill ;;; Copyright © 2020 Jakub Kądziołka -;;; Copyright © 2020, 2021, 2023 Efraim Flashner +;;; Copyright © 2020, 2021, 2023, 2024 Efraim Flashner ;;; Copyright © 2021 Sarah Morgensen ;;; Copyright © 2024 Ekaitz Zarraga ;;; Copyright © 2024 Picnoir +;;; Copyright © 2024 Troy Figiel +;;; Copyright © 2024 Sharlatan Hellseher ;;; ;;; This file is part of GNU Guix. ;;; @@ -28,8 +30,9 @@ #: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 (ice-9 format) #:use-module (ice-9 ftw) + #:use-module (ice-9 match) #:use-module (srfi srfi-1) #:use-module (rnrs io ports) #:use-module (rnrs bytevectors) @@ -201,6 +204,28 @@ dependencies, so it should be self-contained." (delete-file-recursively tmpdir)) #t) +(define* (fix-embed-files #:key embed-files #:allow-other-keys) + "Golang can't determine the valid directory of the module of embed file +which is symlinked during setup environment phase, but easy resolved after +coping file from the store to the build directory of the current package. Take +a list of files or regexps matching files from EMBED-FILES paramter, failover +to 'editions_defaults.binpb' which is a part of ." + ;; see details in Golang source: + ;; + ;; - URL: + ;; - commit: 82c14346d89ec0eeca114f9ca0e88516b2cda454 + ;; - file: src/cmd/go/internal/load/pkg.go#L2059 + (let ((embed-files (format #f "^(~{~a|~}~a)$" + embed-files + "editions_defaults.binpb"))) + (for-each (lambda (file) + (when (eq? (stat:type (lstat file)) + 'symlink) + (let ((file-store-path (readlink file))) + (delete-file file) + (copy-recursively file-store-path file)))) + (find-files "src" embed-files)))) + (define* (unpack #:key source import-path unpack-path #:allow-other-keys) "Relative to $GOPATH, unpack SOURCE in UNPACK-PATH, or IMPORT-PATH when UNPACK-PATH is unset. If the SOURCE archive has a single top level directory, @@ -321,6 +346,7 @@ the standard install-license-files phase to first enter the correct directory." (delete 'patch-generated-file-shebangs) (add-before 'unpack 'setup-go-environment setup-go-environment) (replace 'unpack unpack) + (add-after 'unpack 'fix-embed-files fix-embed-files) (replace 'build build) (replace 'check check) (replace 'install install)