unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Marius Bakke <marius@gnu.org>
To: 50227@debbugs.gnu.org
Subject: [bug#50227] [PATCH] build-system/go: Trim store references using the native compiler option.
Date: Fri, 27 Aug 2021 21:38:40 +0200	[thread overview]
Message-ID: <87tujan0e7.fsf@gnu.org> (raw)
In-Reply-To: <87wno6n5ju.fsf@gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 864 bytes --]

Marius Bakke <marius@gnu.org> skriver:

> Marius Bakke <marius@gnu.org> skriver:
>
>> * guix/build/go-build-system.scm (build): Add '-trimpath' to the 'go install'
>> invocation.
>> (remove-store-references, remove-go-references): Remove procedures.
>> (%standard-phases): Don't include remove-go-references.
>> * gnu/packages/docker.scm (docker)[arguments]: Add the '-trimpath' option to
>> the build flags.  Remove phase remove-go-references.
>> * gnu/packages/uucp.scm (nncp)[arguments]: Likewise.

[...]

> Docker explodes from 764.4 MiB to 1215.5 MiB with this patch even though
> it does use the '-trimpath' option.  Perhaps -trimpath does not work as
> well with dynamically linked executables as it does for static?

The size difference comes from containerd, which has a custom build
system that does not add -trimpath.  After adding the following hunk:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: Type: text/x-patch, Size: 1032 bytes --]

diff --git a/gnu/packages/docker.scm b/gnu/packages/docker.scm
index 88dccc2ae2..e1ddfc6c38 100644
--- a/gnu/packages/docker.scm
+++ b/gnu/packages/docker.scm
@@ -221,6 +221,13 @@ Python without keeping their credentials in a Docker configuration file.")
                    (("exec\\.LookPath\\(\"unpigz\"\\)")
                     (string-append "\"" (assoc-ref inputs "pigz")
                                    "/bin/unpigz\", error(nil)"))))))
+           (add-before 'build 'trim-store-references
+             (lambda* (#:key import-path #:allow-other-keys)
+               (substitute* (string-append "src/" import-path "/Makefile")
+                 ;; Pass the '-trimpath' option down to 'go build' in order
+                 ;; to avoid spurious store references.
+                 (("^GO_BUILD_FLAGS=")
+                  "GO_BUILD_FLAGS=-trimpath"))))
            (replace 'build
              (lambda* (#:key import-path #:allow-other-keys)
                (with-directory-excursion (string-append "src/" import-path)

[-- Attachment #1.3: Type: text/plain, Size: 272 bytes --]


...the size of Docker becomes 763.7 MiB, or 0.7 less than before.

I realize we can set the flag globally in go-build-system, instead of
just for the build phase.  Then we don't need to patch Docker,
containerd, or anything else that does not use the stock build phase.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.4: Type: text/x-patch, Size: 1634 bytes --]

diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm
index fc5ee39c8d..a6b9397d35 100644
--- a/guix/build/go-build-system.scm
+++ b/guix/build/go-build-system.scm
@@ -137,6 +137,9 @@ 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" (string-append (getcwd) ":" (getenv "GOPATH")))
+  ;; Unconditionally set the -trimpath option to avoid spurious store references
+  ;; from having multiple GOPATH entries.  See <https://bugs.gnu.org/33620>.
+  (setenv "GOFLAGS" "-trimpath")
   ;; Go 1.13 uses go modules by default. The go build system does not
   ;; currently support modules, so turn modules off to continue using the old
   ;; GOPATH behavior.
@@ -188,8 +191,6 @@ unpacking."
       (apply invoke "go" "install"
               "-v" ; print the name of packages as they are compiled
               "-x" ; print each command as it is invoked
-              ;; Trim store references from the compiled binaries.
-              "-trimpath"
               ;; Respectively, strip the symbol table and debug
               ;; information, and the DWARF symbol table.
               "-ldflags=-s -w"
@@ -202,6 +203,9 @@ unpacking."
 ;; Can this also install commands???
 (define* (check #:key tests? import-path #:allow-other-keys)
   "Run the tests for the package named by IMPORT-PATH."
+  ;; Remove the global -trimpath option because it can break some test
+  ;; suites.
+  (unsetenv "GOFLAGS")
   (when tests?
     (invoke "go" "test" import-path))
   #t)

[-- Attachment #1.5: Type: text/plain, Size: 44 bytes --]


This may be a cleaner solution.  Thoughts?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 247 bytes --]

  reply	other threads:[~2021-08-27 19:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 15:10 [bug#50227] [PATCH 0/3] go-build-system and GOPATH improvements Marius Bakke
2021-08-27 15:13 ` [bug#50227] [PATCH 1/3] build-system/go: Use a native-search-path for GOPATH Marius Bakke
2021-08-27 15:13   ` [bug#50227] [PATCH 2/3] gnu: hyperledger-fabric: Do not assume GOPATH contains a single entry Marius Bakke
2021-08-27 15:13   ` [bug#50227] [PATCH 3/3] gnu: go-gotest-tools-assert: Provide internal inputs with the source Marius Bakke
2021-08-27 16:44 ` [bug#50227] [PATCH] build-system/go: Trim store references using the native compiler option Marius Bakke
2021-08-27 17:47   ` Marius Bakke
2021-08-27 19:38     ` Marius Bakke [this message]
2021-08-28  2:16 ` [bug#50227] [PATCH 0/3] go-build-system and GOPATH improvements Sarah Morgensen
2021-08-28 14:52   ` Marius Bakke
2022-01-14  3:13     ` Maxim Cournoyer
2021-08-29  6:17 ` [bug#50227] [PATCH 3/3] gnu: go-gotest-tools-assert: Provide internal inputs with the source Sarah Morgensen
2021-09-03 22:55 ` [bug#50227] [PATCH 0/3] go-build-system and GOPATH improvements Sarah Morgensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tujan0e7.fsf@gnu.org \
    --to=marius@gnu.org \
    --cc=50227@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).