From patchwork Sat Jan 13 11:46:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ekaitz Zarraga X-Patchwork-Id: 58837 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 121A627BBEA; Sat, 13 Jan 2024 11:48:33 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D627427BBE2 for ; Sat, 13 Jan 2024 11:48:31 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rOcUp-0000k1-21; Sat, 13 Jan 2024 06:48:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rOcUe-0000jg-2E for guix-patches@gnu.org; Sat, 13 Jan 2024 06:48:04 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rOcUd-0004ZW-Ox for guix-patches@gnu.org; Sat, 13 Jan 2024 06:48:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rOcUc-0002SI-5I; Sat, 13 Jan 2024 06:48:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68423] [PATCH] guix: go-build-system: use trimpath go flag Resent-From: Ekaitz Zarraga Original-Sender: "Debbugs-submit" Resent-CC: cox.katherine.e+guix@gmail.com, sharlatanus@gmail.com, guix-patches@gnu.org Resent-Date: Sat, 13 Jan 2024 11:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68423 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68423@debbugs.gnu.org Cc: Picnoir , Ekaitz Zarraga , Katherine Cox-Buday , Sharlatan Hellseher X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Katherine Cox-Buday , Sharlatan Hellseher Received: via spool by submit@debbugs.gnu.org id=B.17051464469243 (code B ref -1); Sat, 13 Jan 2024 11:48:01 +0000 Received: (at submit) by debbugs.gnu.org; 13 Jan 2024 11:47:26 +0000 Received: from localhost ([127.0.0.1]:38627 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rOcU1-0002P0-QB for submit@debbugs.gnu.org; Sat, 13 Jan 2024 06:47:26 -0500 Received: from lists.gnu.org ([2001:470:142::17]:43402) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rOcTy-0002Ok-6J for submit@debbugs.gnu.org; Sat, 13 Jan 2024 06:47:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rOcTs-0000h1-Ir for guix-patches@gnu.org; Sat, 13 Jan 2024 06:47:17 -0500 Received: from dane.soverin.net ([2a10:de80:1:4091:b9e9:2218:0:1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rOcTo-0004Bn-JY for guix-patches@gnu.org; Sat, 13 Jan 2024 06:47:16 -0500 Received: from smtp.soverin.net (unknown [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dane.soverin.net (Postfix) with ESMTPS id 4TBxTQ2rykzyRc; Sat, 13 Jan 2024 11:47:06 +0000 (UTC) Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.100]) by soverin.net (Postfix) with ESMTPSA id 4TBxTP3R0WzF1; Sat, 13 Jan 2024 11:47:05 +0000 (UTC) Authentication-Results: smtp.soverin.net; dkim=pass (2048-bit key; unprotected) header.d=elenq.tech header.i=@elenq.tech header.a=rsa-sha256 header.s=soverin1 header.b=n9wUX3Vw; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=elenq.tech; s=soverin1; t=1705146425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=tt7HZDrRxfiyAGQDqr74yxqzqHIxcVF3/3ermHAf8Wc=; b=n9wUX3Vwfwp7OGNYyibpdgHuuWACX65qBEgYZFXSgSVdQEwmCx+deUeDeYq2AjkAHbbW4a xA0YE7TtJNXmaQ4gDakTIDysJTdBWlejMdrEqjCnnQe6g+ROvmy4NEcjgX7Qmz/ZMWub7B hd+RiLmTssX+lrga+PJu5E9jQIAa9wIqicXwZXKyXCq2rUzB7MI2C+KpP8X5ZWeUcPibeW d7cJt/HuM/j5MtYesHiIk4oD6VuUqFHZh8rCAh/lTMBZ3okM+AD8pGmef0YvdlmYmrdsR9 uP8jPDu901y7CPOe9e15GZkq30W2vsa0I27qpCAW6O81limayW2lpAzCAosSIw== From: Ekaitz Zarraga Date: Sat, 13 Jan 2024 12:46:15 +0100 Message-ID: MIME-Version: 1.0 Received-SPF: pass client-ip=2a10:de80:1:4091:b9e9:2218:0:1; envelope-from=ekaitz@elenq.tech; helo=dane.soverin.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Go 1.13 introduced[1] a new "trimpath" flag in charge of removing the references to the go toolchain in the produced ELFs. We used to remove these references using the "remove-go-reference" function. This function was executed after go install. By using this new trimpath flag, we don't have to remove any store path from the ELFs produced by go install. We're not using any go older than 1.13 anymore, it's safe to remove these functions. [1] https://go.dev/doc/go1.13 -trimpath remove all file system paths from the resulting executable. Instead of absolute file system paths, the recorded file names will begin either a module path@version (when using modules), or a plain import path (when using the standard library, or GOPATH). * guix/build/go-build-system.scm (build): Add -trimpath (%standard-phases): Remove remove-go-references. (remove-go-references): Remove. Change-Id: Idcae366d226da5ce095693f81fd33133fd1d70d6 Co-authored-by: Picnoir --- guix/build/go-build-system.scm | 59 +++------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) base-commit: c0b303aaa3d6154acbe054120d11467eb98e6d33 diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm index 7f25e05d0d..70ddcd07cd 100644 --- a/guix/build/go-build-system.scm +++ b/guix/build/go-build-system.scm @@ -6,6 +6,8 @@ ;;; Copyright © 2020 Jakub Kądziołka ;;; Copyright © 2020, 2021 Efraim Flashner ;;; Copyright © 2021 Sarah Morgensen +;;; Copyright © 2024 Ekaitz Zarraga +;;; Copyright © 2024 Picnoir ;;; ;;; This file is part of GNU Guix. ;;; @@ -90,7 +92,6 @@ (define-module (guix build go-build-system) ;; * Use Go modules [4] ;; * Re-use compiled packages [5] ;; * Avoid the go-inputs hack -;; * Stop needing remove-go-references (-trimpath ? ) ;; * Remove module packages, only offering the full Git repos? This is ;; more idiomatic, I think, because Go downloads Git repos, not modules. ;; What are the trade-offs? @@ -265,6 +266,7 @@ (define* (build #:key import-path build-flags #:allow-other-keys) ;; Respectively, strip the symbol table and debug ;; information, and the DWARF symbol table. "-ldflags=-s -w" + "-trimpath" `(,@build-flags ,import-path))) (lambda (key . args) (display (string-append "Building '" import-path "' failed.\n" @@ -304,58 +306,6 @@ (define* (install-license-files #:key unpack-path unpack-path)) (apply (assoc-ref gnu:%standard-phases 'install-license-files) args))) -(define* (remove-store-reference file file-name - #:optional (store (%store-directory))) - "Remove from FILE occurrences of FILE-NAME in STORE; return #t when FILE-NAME -is encountered in FILE, #f otherwise. This implementation reads FILE one byte at -a time, which is slow. Instead, we should use the Boyer-Moore string search -algorithm; there is an example in (guix build grafts)." - (define pattern - (string-take file-name - (+ 34 (string-length (%store-directory))))) - - (with-fluids ((%default-port-encoding #f)) - (with-atomic-file-replacement file - (lambda (in out) - ;; We cannot use `regexp-exec' here because it cannot deal with - ;; strings containing NUL characters. - (format #t "removing references to `~a' from `~a'...~%" file-name file) - (setvbuf in 'block 65536) - (setvbuf out 'block 65536) - (fold-port-matches (lambda (match result) - (put-bytevector out (string->utf8 store)) - (put-u8 out (char->integer #\/)) - (put-bytevector out - (string->utf8 - "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-")) - #t) - #f - pattern - in - (lambda (char result) - (put-u8 out (char->integer char)) - result)))))) - -(define* (remove-go-references #:key allow-go-reference? - inputs outputs #:allow-other-keys) - "Remove any references to the Go compiler from the compiled Go executable -files in OUTPUTS." -;; We remove this spurious reference to save bandwidth when installing Go -;; executables. It would be better to not embed the reference in the first -;; place, but I'm not sure how to do that. The subject was discussed at: -;; - (if allow-go-reference? - #t - (let ((go (assoc-ref inputs "go")) - (bin "/bin")) - (for-each (lambda (output) - (when (file-exists? (string-append (cdr output) - bin)) - (for-each (lambda (file) - (remove-store-reference file go)) - (find-files (string-append (cdr output) bin))))) - outputs) - #t))) (define %standard-phases (modify-phases gnu:%standard-phases @@ -367,8 +317,7 @@ (define %standard-phases (replace 'build build) (replace 'check check) (replace 'install install) - (replace 'install-license-files install-license-files) - (add-after 'install 'remove-go-references remove-go-references))) + (replace 'install-license-files install-license-files))) (define* (go-build #:key inputs (phases %standard-phases) #:allow-other-keys #:rest args)