From af4fa7c00cae47552486c28d5559c53e058b597f Mon Sep 17 00:00:00 2001 From: Xinglu Chen Date: Tue, 31 Aug 2021 20:17:52 +0200 Subject: import: elpa: Support NonGNU ELPA. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/import/elpa.scm (elpa-url): Add NonGNU ELPA URL. * doc/guix.texi (Invoking guix import): Document it. Signed-off-by: Ludovic Courtès --- doc/guix.texi | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'doc') diff --git a/doc/guix.texi b/doc/guix.texi index 36a0c7f5ec..679f6b4369 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -11605,6 +11605,10 @@ contained in the GnuPG keyring at @code{emacs} package (@pxref{Package Installation, ELPA package signatures,, emacs, The GNU Emacs Manual}). +@item +@uref{https://elpa.nongnu.org/nongnu/, NonGNU}, selected by the +@code{nongnu} identifier. + @item @uref{https://stable.melpa.org/packages, MELPA-Stable}, selected by the @code{melpa-stable} identifier. -- cgit v1.2.3 From f8f94cc5446753b37ab3ddd23e21919efd006769 Mon Sep 17 00:00:00 2001 From: pukkamustard Date: Tue, 7 Sep 2021 13:41:12 +0200 Subject: guix: dune-build-system: Put dune into a reproducible release mode. * guix/build/dune-build-system.scm (build,check): Replace the profile parameter with the appropriate release flags. * guix/build-system/dune.scm: Remove the profile parameter. * doc/guix.texi: Remove paragraph on profile parameter. Signed-off-by: Julien Lepiller --- doc/guix.texi | 5 ----- guix/build-system/dune.scm | 19 ++++++++++++++++--- guix/build/dune-build-system.scm | 15 +++++++++------ 3 files changed, 25 insertions(+), 14 deletions(-) (limited to 'doc') diff --git a/doc/guix.texi b/doc/guix.texi index 679f6b4369..29246ad4e5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -7735,11 +7735,6 @@ is useful when a package contains multiple packages and you want to build only one of them. This is equivalent to passing the @code{-p} argument to @code{dune}. -The @code{#:profile} parameter can be passed to specify the -@uref{https://dune.readthedocs.io/en/stable/dune-files.html#profile, -dune build profile}. This is equivalent to passing the @code{--profile} -argument to @code{dune}. Its default value is @code{"release"}. - @end defvr @defvr {Scheme Variable} go-build-system diff --git a/guix/build-system/dune.scm b/guix/build-system/dune.scm index 1a64cf9b75..5b33ef6841 100644 --- a/guix/build-system/dune.scm +++ b/guix/build-system/dune.scm @@ -60,6 +60,17 @@ #:allow-other-keys #:rest arguments) "Return a bag for NAME." + + ;; Flags that put dune into reproducible build mode. + (define dune-release-flags + (if (version>=? (package-version dune) "2.5.0") + ;; For dune >= 2.5.0 this is just --release. + ''("--release") + ;; --release does not exist before 2.5.0. Replace with flags compatible + ;; with our old ocaml4.07-dune (1.11.3) + ''("--root" "." "--ignore-promoted-rules" "--no-config" + "--profile" "release"))) + (define private-keywords '(#:source #:target #:dune #:findlib #:ocaml #:inputs #:native-inputs)) @@ -79,7 +90,9 @@ (build-inputs `(("dune" ,dune) ,@(bag-build-inputs base))) (build dune-build) - (arguments (strip-keyword-arguments private-keywords arguments)))))) + (arguments (append + `(#:dune-release-flags ,dune-release-flags) + (strip-keyword-arguments private-keywords arguments))))))) (define* (dune-build store name inputs #:key (guile #f) @@ -89,7 +102,7 @@ (out-of-source? #t) (jbuild? #f) (package #f) - (profile "release") + (dune-release-flags ''()) (tests? #t) (test-flags ''()) (test-target "test") @@ -129,7 +142,7 @@ provides a 'setup.ml' file as its build system." #:out-of-source? ,out-of-source? #:jbuild? ,jbuild? #:package ,package - #:profile ,profile + #:dune-release-flags ,dune-release-flags #:tests? ,tests? #:test-target ,test-target #:install-target ,install-target diff --git a/guix/build/dune-build-system.scm b/guix/build/dune-build-system.scm index 6a0c2593ac..e9ccc71057 100644 --- a/guix/build/dune-build-system.scm +++ b/guix/build/dune-build-system.scm @@ -32,23 +32,26 @@ ;; Code: (define* (build #:key (build-flags '()) (jbuild? #f) - (use-make? #f) (package #f) - (profile "release") #:allow-other-keys) + (use-make? #f) (package #f) (dune-release-flags '()) + #:allow-other-keys) "Build the given package." (let ((program (if jbuild? "jbuilder" "dune"))) (apply invoke program "build" "@install" - (append (if package (list "-p" package) '()) - `("--profile" ,profile) + (append (if package (list "-p" package) + dune-release-flags) build-flags))) #t) (define* (check #:key (test-flags '()) (test-target "test") tests? - (jbuild? #f) (package #f) #:allow-other-keys) + (jbuild? #f) (package #f) (dune-release-flags '()) + #:allow-other-keys) "Test the given package." (when tests? (let ((program (if jbuild? "jbuilder" "dune"))) (apply invoke program "runtest" test-target - (append (if package (list "-p" package) '()) test-flags)))) + (append (if package (list "-p" package) + dune-release-flags) + test-flags)))) #t) (define* (install #:key outputs (install-target "install") (jbuild? #f) -- cgit v1.2.3 From 1dc3825e9940de44c1f170add7bd26d61830ce34 Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Mon, 6 Sep 2021 00:21:51 +0200 Subject: git: 'resolve-reference' handles 'git describe'-style commit IDs. * guix/git.scm (resolve-reference): Rewrite tag-or-commit case to recognize 'git describe' style identifiers and resolve them as commits. * doc/guix.texi (origin Reference): Mention it. --- doc/guix.texi | 9 +++++---- guix/git.scm | 33 ++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) (limited to 'doc') diff --git a/doc/guix.texi b/doc/guix.texi index 29246ad4e5..f88967b593 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -47,7 +47,7 @@ Copyright @copyright{} 2017, 2018 Carlo Zancanaro@* Copyright @copyright{} 2017 Thomas Danckaert@* Copyright @copyright{} 2017 humanitiesNerd@* Copyright @copyright{} 2017, 2021 Christine Lemmer-Webber@* -Copyright @copyright{} 2017, 2018, 2019, 2020 Marius Bakke@* +Copyright @copyright{} 2017, 2018, 2019, 2020, 2021 Marius Bakke@* Copyright @copyright{} 2017, 2019, 2020 Hartmut Goebel@* Copyright @copyright{} 2017, 2019, 2020, 2021 Maxim Cournoyer@* Copyright @copyright{} 2017, 2018, 2019, 2020, 2021 Tobias Geerinckx-Rice@* @@ -7010,9 +7010,10 @@ retrieve. The URL of the Git repository to clone. @item @code{commit} -This string denotes either the commit to fetch (a hexadecimal string, -either the full SHA1 commit or a ``short'' commit string; the latter is -not recommended) or the tag to fetch. +This string denotes either the commit to fetch (a hexadecimal string), +or the tag to fetch. You can also use a ``short'' commit ID or a +@command{git describe} style identifier such as +@code{v1.0.1-10-g58d7909c97}. @item @code{recursive?} (default: @code{#f}) This Boolean indicates whether to recursively fetch Git sub-modules. diff --git a/guix/git.scm b/guix/git.scm index 9c6f326c36..621de0e925 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2017, 2020 Mathieu Othacehe ;;; Copyright © 2018, 2019, 2020, 2021 Ludovic Courtès ;;; Copyright © 2021 Kyle Meyer +;;; Copyright © 2021 Marius Bakke ;;; ;;; This file is part of GNU Guix. ;;; @@ -223,15 +224,29 @@ corresponding Git object." (object-lookup-prefix repository (string->oid commit) len) (object-lookup repository (string->oid commit))))) (('tag-or-commit . str) - (if (or (> (string-length str) 40) - (not (string-every char-set:hex-digit str))) - (resolve `(tag . ,str)) ;definitely a tag - (catch 'git-error - (lambda () - (resolve `(tag . ,str))) - (lambda _ - ;; There's no such tag, so it must be a commit ID. - (resolve `(commit . ,str)))))) + (cond ((and (string-contains str "-g") + (match (string-split str #\-) + ((version ... revision g+commit) + (if (and (> (string-length g+commit) 4) + (string-every char-set:digit revision) + (string-every char-set:hex-digit + (string-drop g+commit 1))) + (string-drop g+commit 1) + #f)) + (_ #f))) + ;; Looks like a 'git describe' style ID, like + ;; v1.3.0-7-gaa34d4d28d. + => (lambda (commit) (resolve `(commit . ,commit)))) + ((or (> (string-length str) 40) + (not (string-every char-set:hex-digit str))) + (resolve `(tag . ,str))) ;definitely a tag + (else + (catch 'git-error + (lambda () + (resolve `(tag . ,str))) + (lambda _ + ;; There's no such tag, so it must be a commit ID. + (resolve `(commit . ,str))))))) (('tag . tag) (let ((oid (reference-name->oid repository (string-append "refs/tags/" tag)))) -- cgit v1.2.3 From 16ef7b4938b14e68f8ca7504c9614f84530572ed Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Sat, 4 Sep 2021 19:07:52 +0200 Subject: transformations: Git tags and 'git describe' style IDs are used as version. * guix/transformations.scm (commit->version-string): New procedure. Use git tags and 'git describe' style identifiers directly. (transform-package-source-commit): Adjust accordingly. * tests/transformations.scm ("options->transformation, with-commit, version transformation"): New test. * doc/guix.texi (Package Transformation Options): Mention the 'git describe' style. --- doc/guix.texi | 3 ++- guix/git.scm | 4 ++-- guix/transformations.scm | 30 +++++++++++++++++++++--------- tests/transformations.scm | 21 +++++++++++++++++++++ 4 files changed, 46 insertions(+), 12 deletions(-) (limited to 'doc') diff --git a/doc/guix.texi b/doc/guix.texi index f88967b593..220499503d 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -10652,7 +10652,8 @@ guix build --with-branch=guile-sqlite3=master cuirass @item --with-commit=@var{package}=@var{commit} This is similar to @option{--with-branch}, except that it builds from @var{commit} rather than the tip of a branch. @var{commit} must be a valid -Git commit SHA1 identifier or a tag. +Git commit SHA1 identifier, a tag, or a @command{git describe} style +identifier such as @code{1.0-3-gabc123}. @item --with-patch=@var{package}=@var{file} Add @var{file} to the list of patches applied to @var{package}, where diff --git a/guix/git.scm b/guix/git.scm index 621de0e925..acc48fd12f 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -231,11 +231,11 @@ corresponding Git object." (string-every char-set:digit revision) (string-every char-set:hex-digit (string-drop g+commit 1))) + ;; Looks like a 'git describe' style ID, like + ;; v1.3.0-7-gaa34d4d28d. (string-drop g+commit 1) #f)) (_ #f))) - ;; Looks like a 'git describe' style ID, like - ;; v1.3.0-7-gaa34d4d28d. => (lambda (commit) (resolve `(commit . ,commit)))) ((or (> (string-length str) 40) (not (string-every char-set:hex-digit str))) diff --git a/guix/transformations.scm b/guix/transformations.scm index 5122baa403..5ae1977cb2 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2021 Marius Bakke ;;; ;;; This file is part of GNU Guix. ;;; @@ -270,6 +271,25 @@ strings like \"guile-next=stable-3.0\" meaning that packages are built using (rewrite obj) obj)))) +(define (commit->version-string commit) + "Return a string suitable for use in the 'version' field of a package based +on the given COMMIT." + (cond ((and (> (string-length commit) 1) + (string-prefix? "v" commit) + (char-set-contains? char-set:digit + (string-ref commit 1))) + ;; Probably a tag like "v1.0" or a 'git describe' identifier. + (string-drop commit 1)) + ((not (string-every char-set:hex-digit commit)) + ;; Pass through tags and 'git describe' style IDs directly. + commit) + (else + (string-append "git." + (if (< (string-length commit) 7) + commit + (string-take commit 7)))))) + + (define (transform-package-source-commit replacement-specs) "Return a procedure that, when passed a package, replaces its direct dependencies according to REPLACEMENT-SPECS. REPLACEMENT-SPECS is a list of @@ -278,15 +298,7 @@ strings like \"guile-next=cabba9e\" meaning that packages are built using (define (replace old url commit) (package (inherit old) - (version (if (and (> (string-length commit) 1) - (string-prefix? "v" commit) - (char-set-contains? char-set:digit - (string-ref commit 1))) - (string-drop commit 1) ;looks like a tag like "v1.0" - (string-append "git." - (if (< (string-length commit) 7) - commit - (string-take commit 7))))) + (version (commit->version-string commit)) (source (git-checkout (url url) (commit commit) (recursive? #t))))) diff --git a/tests/transformations.scm b/tests/transformations.scm index 3417c994ec..09839dc1c5 100644 --- a/tests/transformations.scm +++ b/tests/transformations.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016, 2017, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2021 Marius Bakke ;;; ;;; This file is part of GNU Guix. ;;; @@ -235,6 +236,26 @@ (string=? (package-name dep2) "chbouib") (package-source dep2)))))))) +(test-equal "options->transformation, with-commit, version transformation" + '("1.0" "1.0-rc1-2-gabc123" "git.abc123") + (map (lambda (commit) + (let* ((p (dummy-package "guix.scm" + (inputs `(("foo" ,(dummy-package "chbouib" + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://example.org") + (commit "cabba9e"))) + (sha256 #f))))))))) + (t (options->transformation + `((with-commit . ,(string-append "chbouib=" commit)))))) + (let ((new (t p))) + (and (not (eq? new p)) + (match (package-inputs new) + ((("foo" dep1)) + (package-version dep1))))))) + '("v1.0" "1.0-rc1-2-gabc123" "abc123"))) + (test-equal "options->transformation, with-git-url" (let ((source (git-checkout (url "https://example.org") (recursive? #t)))) -- cgit v1.2.3 From de15397006c271b5506561b45fa41e110f93dec4 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Mon, 23 Aug 2021 22:47:05 -0500 Subject: doc: add clarifications to Linode cookbook recipe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * doc/guix-cookbook.texi: clarify Linode recipe Reword paragraph about adding the Guix device disk to Debian config. Improve example commands for sftp-ing files to the server. Minor wording fixes Signed-off-by: Ludovic Courtès --- doc/guix-cookbook.texi | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'doc') diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi index 7f7dd98e06..fda5093825 100644 --- a/doc/guix-cookbook.texi +++ b/doc/guix-cookbook.texi @@ -2050,10 +2050,12 @@ Copy into it the output of: cat ~/.ssh/_rsa.pub @end example -Power the Linode down. In the Linode's Disks/Configurations tab, resize -the Debian disk to be smaller. 30 GB is recommended. +Power the Linode down. + +In the Linode's Storage tab, resize the Debian disk to be smaller. +30 GB free space is recommended. Then click "Add a disk", and fill +out the form with the following: -In the Linode settings, "Add a disk", with the following: @itemize @bullet @item Label: "Guix" @@ -2065,9 +2067,9 @@ Filesystem: ext4 Set it to the remaining size @end itemize -On the "configuration" field that comes with the default image, press -"..." and select "Edit", then on that menu add to @file{/dev/sdc} the "Guix" -label. +In the Configurations tab, press "Edit" on the default Debian profile. +Under "Block Device Assignment" click "Add a Device". It should be +@file{/dev/sdc} and you can select the "Guix" disk. Save Changes. Now "Add a Configuration", with the following: @itemize @bullet @@ -2093,8 +2095,8 @@ Root device: @file{/dev/sda} Turn off all the filesystem/boot helpers @end itemize -Now power it back up, picking the Debian configuration. Once it's -booted up, ssh in your server via @code{ssh +Now power it back up, booting with the Debian configuration. Once it's +running, ssh to your server via @code{ssh root@@@var{}}. (You can find your server IP address in your Linode Summary section.) Now you can run the "install guix from @pxref{Binary Installation,,, guix, GNU Guix}" steps: @@ -2183,19 +2185,20 @@ Replace the following fields in the above configuration: @end lisp The last line in the above example lets you log into the server as root -and set the initial root password. After you have done this, you may +and set the initial root password (see the note at the end of this +recipe about root login). After you have done this, you may delete that line from your configuration and reconfigure to prevent root login. -Save your ssh public key (eg: @file{~/.ssh/id_rsa.pub}) as -@file{@var{}_rsa.pub} and your +Copy your ssh public key (eg: @file{~/.ssh/id_rsa.pub}) as +@file{@var{}_rsa.pub} and put @file{guix-config.scm} in the same directory. In a new terminal run these commands. @example sftp root@@ -put /home//ssh/id_rsa.pub . -put /path/to/linode/guix-config.scm . +put /path/to/files/_rsa.pub . +put /path/to/files/guix-config.scm . @end example In your first terminal, mount the guix drive: @@ -2205,9 +2208,9 @@ mkdir /mnt/guix mount /dev/sdc /mnt/guix @end example -Due to the way we set things up above, we do not install GRUB -completely. Instead we install only our grub configuration file. So we -need to copy over some of the other GRUB stuff that is already there: +Due to the way we set up the bootloader section of the guix-config.scm, +only the grub configuration file will be installed. So, we need to copy +over some of the other GRUB stuff already installed on the Debian system: @example mkdir -p /mnt/guix/boot/grub @@ -2260,7 +2263,7 @@ still need to set your root and user password initially by clicking on the ``Launch Console'' option in your linode. Choose the ``Glish'' instead of ``Weblish''. Now you should be able to ssh into the machine. -Horray! At this point you can shut down the server, delete the +Hooray! At this point you can shut down the server, delete the Debian disk, and resize the Guix to the rest of the size. Congratulations! -- cgit v1.2.3 From de4f5df95db6c2e7071bf5e44c0d7ae928da1025 Mon Sep 17 00:00:00 2001 From: Efraim Flashner Date: Mon, 26 Apr 2021 21:13:06 +0300 Subject: build/go: Support cross compiling. * guix/build-system/go.scm (go-target): New procedure. (go-build): Add goarch, goos keywords. Adjust bag depending if doing a native or cross compile. (go-cross-build): New procedure. * guix/build/go-build-system.scm (setup-go-environment): Accept goarch, goos keywords. Set go environment variables based on target architecture. * doc/guix.texi (Build Systems): Mention new go-build-system keywords. --- doc/guix.texi | 7 ++ guix/build-system/go.scm | 163 +++++++++++++++++++++++++++++++++++++---- guix/build/go-build-system.scm | 20 ++++- 3 files changed, 172 insertions(+), 18 deletions(-) (limited to 'doc') diff --git a/doc/guix.texi b/doc/guix.texi index 220499503d..2fc9687910 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -7759,6 +7759,13 @@ Packages that provide Go libraries should install their source code into the built output. The key @code{#:install-source?}, which defaults to @code{#t}, controls whether or not the source code is installed. It can be set to @code{#f} for packages that only provide executable files. + +Packages can be cross-built, and if a specific architecture or operating +system is desired then the keywords @code{#:goarch} and @code{#:goos} +can be used to force the package to be built for that architecture and +operating system. The combinations known to Go can be found +@url{"https://golang.org/doc/install/source#environment", in their +documentation}. @end defvr @defvr {Scheme Variable} glib-or-gtk-build-system diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm index 8f55796e86..4c1a732107 100644 --- a/guix/build-system/go.scm +++ b/guix/build-system/go.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2016 Petter ;;; Copyright © 2017 Leo Famulari ;;; Copyright © 2020 Jakub Kądziołka +;;; Copyright © 2021 Efraim Flashner ;;; ;;; This file is part of GNU Guix. ;;; @@ -27,6 +28,7 @@ #:use-module (guix packages) #:use-module (ice-9 match) #:use-module (ice-9 regex) + #:use-module (srfi srfi-1) #:export (%go-build-system-modules go-build go-build-system @@ -78,6 +80,24 @@ present) if a pseudo-version pattern is not recognized." commit hash and its date rather than a proper release tag." (regexp-exec %go-pseudo-version-rx version)) +(define (go-target target) + ;; Parse the nix-system equivalent of the target and set the + ;; target for compilation accordingly. + (match (string-split (gnu-triplet->nix-system target) #\-) + ((arch os) + (list (match arch + ("aarch64" "arm64") + ("armhf" "arm") + ("powerpc64le" "ppc64le") + ("powerpc64" "ppc64") + ("i686" "386") + ("x86_64" "amd64") + ("mips64el" "mips64le") + (_ arch)) + (match os + ((or "mingw32" "cygwin") "windows") + (_ os)))))) + (define %go-build-system-modules ;; Build-side modules imported and used by default. `((guix build go-build-system) @@ -98,22 +118,37 @@ commit hash and its date rather than a proper release tag." (define private-keywords '(#:source #:target #:go #:inputs #:native-inputs)) - (and (not target) ;XXX: no cross-compilation - (bag - (name name) - (system system) - (host-inputs `(,@(if source - `(("source" ,source)) - '()) - ,@inputs - - ;; Keep the standard inputs of 'gnu-build-system'. - ,@(standard-packages))) - (build-inputs `(("go" ,go) - ,@native-inputs)) - (outputs outputs) - (build go-build) - (arguments (strip-keyword-arguments private-keywords arguments))))) + (bag + (name name) + (system system) + (target target) + (build-inputs `(,@(if source + `(("source" ,source)) + '()) + ,@`(("go" ,go)) + ,@native-inputs + ,@(if target '() inputs) + ,@(if target + ;; Use the standard cross inputs of + ;; 'gnu-build-system'. + (standard-cross-packages target 'host) + '()) + ;; Keep the standard inputs of 'gnu-build-system'. + ,@(standard-packages))) + (host-inputs (if target inputs '())) + + ;; 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 + ;; native package, so it would end up using a "native" variant of + ;; 'cross-libc' (built with 'gnu-build'), whereas all the other packages + ;; would use a target variant (built with 'gnu-cross-build'.) + (target-inputs (if target + (standard-cross-packages target 'target) + '())) + + (outputs outputs) + (build (if target go-cross-build go-build)) + (arguments (strip-keyword-arguments private-keywords arguments)))) (define* (go-build store name inputs #:key @@ -128,6 +163,8 @@ commit hash and its date rather than a proper release tag." (tests? #t) (allow-go-reference? #f) (system (%current-system)) + (goarch (first (go-target (%current-system)))) + (goos (last (go-target (%current-system)))) (guile #f) (imported-modules %go-build-system-modules) (modules '((guix build go-build-system) @@ -147,6 +184,8 @@ commit hash and its date rather than a proper release tag." #:system ,system #:phases ,phases #:outputs %outputs + #:goarch ,goarch + #:goos ,goos #:search-paths ',(map search-path-specification->sexp search-paths) #:install-source? ,install-source? @@ -174,6 +213,98 @@ commit hash and its date rather than a proper release tag." #:outputs outputs #:guile-for-build guile-for-build)) +(define* (go-cross-build store name + #:key + target native-drvs target-drvs + (phases '(@ (guix build go-build-system) + %standard-phases)) + (outputs '("out")) + (search-paths '()) + (native-search-paths '()) + (install-source? #t) + (import-path "") + (unpack-path "") + (build-flags ''()) + (tests? #f) ; nothing can be done + (allow-go-reference? #f) + (system (%current-system)) + (goarch (first (go-target target))) + (goos (last (go-target target))) + (guile #f) + (imported-modules %go-build-system-modules) + (modules '((guix build go-build-system) + (guix build union) + (guix build utils)))) + "Cross-build NAME using GO, where TARGET is a GNU triplet and with INPUTS." + (define builder + `(begin + (use-modules ,@modules) + (let () + (define %build-host-inputs + ',(map (match-lambda + ((name (? derivation? drv) sub ...) + `(,name . ,(apply derivation->output-path drv sub))) + ((name path) + `(,name . ,path))) + native-drvs)) + + (define %build-target-inputs + ',(map (match-lambda + ((name (? derivation? drv) sub ...) + `(,name . ,(apply derivation->output-path drv sub))) + ((name (? package? pkg) sub ...) + (let ((drv (package-cross-derivation store pkg + target system))) + `(,name . ,(apply derivation->output-path drv sub)))) + ((name path) + `(,name . ,path))) + target-drvs)) + + (go-build #:name ,name + #:source ,(match (assoc-ref native-drvs "source") + (((? derivation? source)) + (derivation->output-path source)) + ((source) + source) + (source + source)) + #:system ,system + #:phases ,phases + #:outputs %outputs + #:target ,target + #:goarch ,goarch + #:goos ,goos + #:inputs %build-target-inputs + #:native-inputs %build-host-inputs + #:search-paths ',(map search-path-specification->sexp + search-paths) + #:native-search-paths ',(map + search-path-specification->sexp + native-search-paths) + #:install-source? ,install-source? + #:import-path ,import-path + #:unpack-path ,unpack-path + #:build-flags ,build-flags + #:tests? ,tests? + #:allow-go-reference? ,allow-go-reference? + #: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 + #:system system + #:inputs (append native-drvs target-drvs) + #:outputs outputs + #:modules imported-modules + #:guile-for-build guile-for-build)) + (define go-build-system (build-system (name 'go) diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm index 227df820db..645d2fe680 100644 --- a/guix/build/go-build-system.scm +++ b/guix/build/go-build-system.scm @@ -4,7 +4,7 @@ ;;; Copyright © 2019 Maxim Cournoyer ;;; Copyright © 2020 Jack Hill ;;; Copyright © 2020 Jakub Kądziołka -;;; Copyright © 2020 Efraim Flashner +;;; Copyright © 2020, 2021 Efraim Flashner ;;; ;;; This file is part of GNU Guix. ;;; @@ -131,7 +131,7 @@ ;; ;; Code: -(define* (setup-go-environment #:key inputs outputs #:allow-other-keys) +(define* (setup-go-environment #:key inputs outputs goos goarch #:allow-other-keys) "Prepare a Go build environment for INPUTS and OUTPUTS. Build a file system 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 @@ -149,6 +149,22 @@ dependencies, so it should be self-contained." ;; GOPATH behavior. (setenv "GO111MODULE" "off") (setenv "GOBIN" (string-append (assoc-ref outputs "out") "/bin")) + + ;; Make sure we're building for the correct architecture and OS targets + ;; that Guix targets. + (setenv "GOARCH" goarch) + (setenv "GOOS" goos) + (match goarch + ("arm" + (setenv "GOARM" "7")) + ((or "mips" "mipsel") + (setenv "GOMIPS" "hardfloat")) + ((or "mips64" "mips64le") + (setenv "GOMIPS64" "hardfloat")) + ((or "ppc64" "ppc64le") + (setenv "GOPPC64" "power8")) + (_ #t)) + (let ((tmpdir (tmpnam))) (match (go-inputs inputs) (((names . directories) ...) -- cgit v1.2.3