diff mbox series

[bug#50227] build-system/go: Trim store references using the native compiler option.

Message ID 87tujan0e7.fsf@gnu.org
State New
Headers show
Series [bug#50227] build-system/go: Trim store references using the native compiler option. | expand

Checks

Context Check Description
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Marius Bakke Aug. 27, 2021, 7:38 p.m. UTC
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:
...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.
This may be a cleaner solution.  Thoughts?
diff mbox series

Patch

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)