From patchwork Thu Feb 22 16:10:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 60890 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 6E60227BBEA; Thu, 22 Feb 2024 16:17:38 +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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,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 C765127BBE9 for ; Thu, 22 Feb 2024 16:17:36 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdBl4-0003u0-CV; Thu, 22 Feb 2024 11:17: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 1rdBkZ-0003PK-CD for guix-patches@gnu.org; Thu, 22 Feb 2024 11:16:44 -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 1rdBkY-0004ae-VZ for guix-patches@gnu.org; Thu, 22 Feb 2024 11:16:42 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rdBkv-0003U9-SM for guix-patches@gnu.org; Thu, 22 Feb 2024 11:17:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68813] [core-updates PATCH 07/20] gnu: pkgconf: Add support for cross-compilation. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 22 Feb 2024 16:17:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68813 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68813@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 68813-submit@debbugs.gnu.org id=B68813.170861858413134 (code B ref 68813); Thu, 22 Feb 2024 16:17:05 +0000 Received: (at 68813) by debbugs.gnu.org; 22 Feb 2024 16:16:24 +0000 Received: from localhost ([127.0.0.1]:38589 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdBkF-0003Pc-BI for submit@debbugs.gnu.org; Thu, 22 Feb 2024 11:16:24 -0500 Received: from mail-qk1-f178.google.com ([209.85.222.178]:48452) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rdBk4-0003Ns-UV for 68813@debbugs.gnu.org; Thu, 22 Feb 2024 11:16:13 -0500 Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78776c82564so206403285a.1 for <68813@debbugs.gnu.org>; Thu, 22 Feb 2024 08:15:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708618484; x=1709223284; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oHxl0m05rWVekFol++fgctAtmU2NKuMd8A9Mn4sQn7Y=; b=Jmq3VrIS4ZPhWg226+t7BlkcS/vFOK9sJu0QmnF5NiSewfLiyusUnCTD7wlNjQw8UP zp6yVB5/jONnO1YQUHykSIW0qGtvmi9rUjP1NqvH8oPY8VQPGdtKWI3MFfJt3J8ldK1D CGjvWuFjWbOHyMihvMSWOwowhZHgP1ZJYQH0gRB5TDOWdKKJK+6IbMlOSbm+r05W1BFY v4fqGhADAlOd2u+O8mqtnLxpnjwn7F3JK86JaO4qioQXu0ho6+ajS20S8S7JLzFykyYP q9bZMAiqdMlXMiro676xtQn0lOlFjO2E0c0ItUxCCoiZtU8aP74cpvv+6sM+CDSg+adu R19g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708618484; x=1709223284; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oHxl0m05rWVekFol++fgctAtmU2NKuMd8A9Mn4sQn7Y=; b=i9vuiOXWe6+L5NaX+zKWc++l3/m61mrU0tkRR7o3QoOfwFQDm6oEN8mmyu+D4M0Bz+ QuVOHJkERg9wETGZWdbsnIcLjLMAtmCYxeCAv3yn+7O+3IenMb2ctJfLO2S+EvHyJrjk Jrr90Ahxml4u45w3Od2y85MMnBGqr6I6zhsi28Z4heN0uo4KZ1ds4BWAXhB3qymFocdo HsCX4V2GOO2k/Ii6D28waJlfsdeNoyPaq9X+PkbG2LhT1rs2dAnnpmBTOfLPs2SeYIFV IyhaH9vKcws3Natp334zMaoOChsO+2Efq0v++Pzwyv8u6P1jKHN+1HAKZ7Ds9QKM7SF3 Gvjw== X-Gm-Message-State: AOJu0YwBrQ+a/RWTcShfQPKH5w9b7+ELwIWMKcstsRdu+A8ol8mrnzFj GhAe22Togvo+mZ6XuFdrSj85axHMt0SPbz308ClbqPSB3Bn2DOWiuUyTyufK X-Google-Smtp-Source: AGHT+IE1Ed29J2mBilFa+lBFGx8iY6sLBSW82xIwvaqXTgNn6z6Q0bjsG5kMJqdJ0J6hRoBjASxigA== X-Received: by 2002:a0c:f28f:0:b0:68f:6bce:8505 with SMTP id k15-20020a0cf28f000000b0068f6bce8505mr12217127qvl.41.1708618483818; Thu, 22 Feb 2024 08:14:43 -0800 (PST) Received: from localhost.localdomain (dsl-155-144.b2b2c.ca. [66.158.155.144]) by smtp.gmail.com with ESMTPSA id od5-20020a0562142f0500b0068fa74cfa79sm2078437qvb.117.2024.02.22.08.14.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 08:14:43 -0800 (PST) From: Maxim Cournoyer Date: Thu, 22 Feb 2024 11:10:06 -0500 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 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 * gnu/packages/pkg-config.scm: Reorganize module into sections. (cross-pkg-config): Refactor to accept a TARGET argument. (pkg-config-for-target): Likewise. (pkg-config): Apply pkg-config-for-target to the %pkg-config argument. (pkgconf): New variable, computed via pkg-config-for-target. (pkgconf-as-pkg-config): Likewise. (make-pkg-config-for-build): New procedure. (pkg-config-for-build): Express in terms of the above. (pkgconf-as-pkg-config-for-build): New variable. (%pkgconf): New variable, renamed from previous pkgconf. (%pkgconf-as-pkg-config): New variable, renamed from pkgconf-as-pkg-config. Change-Id: I932e924949c5129bdc328c279cdd214b383d043d --- gnu/packages/pkg-config.scm | 238 +++++++++++++++++++++--------------- 1 file changed, 142 insertions(+), 96 deletions(-) diff --git a/gnu/packages/pkg-config.scm b/gnu/packages/pkg-config.scm index 64a36b2126..e8d63be3d7 100644 --- a/gnu/packages/pkg-config.scm +++ b/gnu/packages/pkg-config.scm @@ -31,11 +31,18 @@ (define-module (gnu packages pkg-config) #:use-module (gnu packages bash) #:use-module (gnu packages check) #:use-module (guix memoization) - #:export (pkg-config)) + #:export (pkg-config + pkgconf + pkgconf-as-pkg-config)) -;; This is the "primitive" pkg-config package. People should use `pkg-config' -;; (see below) rather than `%pkg-config', but we export `%pkg-config' so that -;; `fold-packages' finds it. + +;;; +;;; "Primitive" pkg-config packages. +;;; + +;; The %-less variants defined below should be used instead; the %-prefixed +;; "primitive" packages are exported so that `fold-packages' can find them, +;; making them available for use via the Guix CLI. (define-public %pkg-config (package (name "pkg-config") @@ -82,95 +89,7 @@ (define-public %pkg-config it can be used for defining the location of documentation tools, for instance."))) -(define cross-pkg-config - (mlambda (target) - "Return a pkg-config for TARGET, essentially just a wrapper called -`TARGET-pkg-config', as `configure' scripts like it." - ;; See - ;; for details. - (package - (inherit %pkg-config) - (name (string-append (package-name %pkg-config) "-" target)) - (build-system trivial-build-system) - (arguments - `(#:modules ((guix build utils)) - #:builder (begin - (use-modules (guix build utils)) - - (let* ((in (assoc-ref %build-inputs "pkg-config")) - (out (assoc-ref %outputs "out")) - (bin (string-append out "/bin")) - (prog (string-append ,target "-pkg-config")) - (native (string-append in "/bin/pkg-config"))) - - (mkdir-p bin) - - ;; Create a `TARGET-pkg-config' -> `pkg-config' symlink. - ;; This satisfies the pkg.m4 macros, which use - ;; AC_PROG_TOOL to determine the `pkg-config' program - ;; name. - (symlink native (string-append bin "/" prog)) - - ;; Also make 'pkg.m4' available, some packages might - ;; expect it. - (mkdir-p (string-append out "/share")) - (symlink (string-append in "/share/aclocal") - (string-append out "/share/aclocal")) - #t)))) - (native-inputs `(("pkg-config" ,%pkg-config))) - - ;; Ignore native inputs, and set `PKG_CONFIG_PATH' for target inputs. - (native-search-paths '()) - (search-paths (package-native-search-paths %pkg-config))))) - -(define (pkg-config-for-target target) - "Return a pkg-config package for TARGET, which may be either #f for a native -build, or a GNU triplet." - (if target - (cross-pkg-config target) - %pkg-config)) - -;; This hack allows us to automatically choose the native or the cross -;; `pkg-config' depending on whether it's being used in a cross-build -;; environment or not. -(define-syntax pkg-config - (identifier-syntax (pkg-config-for-target (%current-target-system)))) - -;; This hack allows for using both "pkg-config" and "TARGET-pkg-config" -;; at the same time. Simply using '%pkg-config' and 'pkg-config' won't -;; work because they both use the "PKG_CONFIG_PATH" environment variable. -(define-public pkg-config-for-build - (package - (inherit (hidden-package %pkg-config)) - (name "pkg-config-for-build") - (version "0") - (source #f) - (build-system trivial-build-system) - (inputs - (list bash-minimal %pkg-config)) - (arguments - `(#:modules ((guix build utils)) - #:builder - ,#~(begin - (use-modules (guix build utils)) - (define where (string-append #$output "/bin/pkg-config")) - (mkdir-p (dirname where)) - (call-with-output-file where - (lambda (port) - (format port "#!~a -export PKG_CONFIG_PATH=\"$PKG_CONFIG_PATH_FOR_BUILD\" -exec ~a \"$@\"" - (search-input-file %build-inputs "bin/bash") - (search-input-file %build-inputs "bin/pkg-config")))) - (chmod where #o500)))) - (native-search-paths - (map (lambda (original) - (search-path-specification - (inherit original) - (variable "PKG_CONFIG_PATH_FOR_BUILD"))) - (package-native-search-paths %pkg-config))))) - -(define-public pkgconf +(define-public %pkgconf (package (name "pkgconf") (version "2.1.0") @@ -200,8 +119,8 @@ (define-public pkgconf pkgconf.") (license isc))) -(define-public pkgconf-as-pkg-config - (package/inherit pkgconf +(define-public %pkgconf-as-pkg-config + (package/inherit %pkgconf (name "pkgconf-as-pkg-config") (build-system gnu-build-system) (arguments @@ -225,5 +144,132 @@ (define-public pkgconf-as-pkg-config "/share/aclocal") (string-append #$output "/share/aclocal")))))))) (native-inputs '()) - (inputs (list pkgconf)) + (inputs (list %pkgconf)) (propagated-inputs '()))) + + +;;; +;;; Tooling for generating pkg-config wrappers for cross-compiling. +;;; + +(define (make-cross-pkg-config pkg-config) + (mlambda (target) + "Return a procedure that evaluates to a PKG-CONFIG package for TARGET, +essentially just a wrapper called `TARGET-pkg-config', as `configure' scripts +like it." + ;; See + ;; for details. + (package + (inherit pkg-config) + (name (string-append (package-name pkg-config) "-" target)) + (build-system trivial-build-system) + (arguments + (list + #:builder (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + + (let* ((in #+pkg-config) + (out #$output) + (bin (string-append out "/bin")) + (prog (string-append #$target "-pkg-config")) + (native (string-append in "/bin/pkg-config"))) + + (mkdir-p bin) + + ;; Create a `TARGET-pkg-config' -> `pkg-config' symlink. + ;; This satisfies the pkg.m4 macros, which use + ;; AC_PROG_TOOL to determine the `pkg-config' program + ;; name. + (symlink native (string-append bin "/" prog)) + + ;; Also make 'pkg.m4' available, some packages might + ;; expect it. + (mkdir-p (string-append out "/share")) + (symlink (string-append in "/share/aclocal") + (string-append out "/share/aclocal"))))))) + + ;; Ignore native inputs, and set `PKG_CONFIG_PATH' for target inputs. + (native-search-paths '()) + (search-paths (package-native-search-paths pkg-config))))) + +(define (make-pkg-config-for-target pkg-config) + "Return a procedure that evaluates to a `pkg-config' package for TARGET +built from PKG-CONFIG. The target may be either #f for a native build, or a +GNU triplet." + (let ((cross-pkg-config (make-cross-pkg-config pkg-config))) + (lambda (target) + (if target + (cross-pkg-config target) + pkg-config)))) + +(define pkg-config-for-target + (make-pkg-config-for-target %pkg-config)) + +(define pkgconf-for-target + (make-pkg-config-for-target %pkgconf)) + +(define pkgconf-as-pkg-config-for-target + (make-pkg-config-for-target %pkgconf-as-pkg-config)) + + +;;; +;;; The final pkg-config package variables to use. +;;; + +;; These are a hacks for automatically choosing the native or the cross +;; `pkg-config' depending on whether it's being used in a cross-build +;; environment or not. +(define-syntax pkg-config + (identifier-syntax (pkg-config-for-target (%current-target-system)))) + +(define-syntax pkgconf + (identifier-syntax (pkgconf-for-target (%current-target-system)))) + +(define-syntax pkgconf-as-pkg-config + (identifier-syntax (pkgconf-as-pkg-config-for-target + (%current-target-system)))) + + +;;; +;;; pkg-config packages for native use (build-time only). +;;; +(define (make-pkg-config-for-build pkg-config) + "Return a `pkg-config' package from PKG-CONFIG for use by the builder when +cross-compiling, that honors a PKG_CONFIG_PATH_FOR_BUILD search path instead +of PKG_CONFIG_PATH, to avoid conflicting with the target `pkg-config'." + (package + (inherit (hidden-package pkg-config)) + (name "pkg-config-for-build") + (version "0") + (source #f) + (build-system trivial-build-system) + (inputs (list bash-minimal pkg-config)) + (arguments + (list + #:modules '((guix build utils)) + #:builder + #~(begin + (use-modules (guix build utils)) + (define where (string-append #$output "/bin/pkg-config")) + (mkdir-p (dirname where)) + (call-with-output-file where + (lambda (port) + (format port "#!~a +export PKG_CONFIG_PATH=\"$PKG_CONFIG_PATH_FOR_BUILD\" +exec ~a \"$@\"" + (search-input-file %build-inputs "bin/bash") + (search-input-file %build-inputs "bin/pkg-config")))) + (chmod where #o500)))) + (native-search-paths + (map (lambda (original) + (search-path-specification + (inherit original) + (variable "PKG_CONFIG_PATH_FOR_BUILD"))) + (package-native-search-paths pkg-config))))) + +(define-public pkg-config-for-build + (make-pkg-config-for-build %pkg-config)) + +(define-public pkgconf-as-pkg-config-for-build + (make-pkg-config-for-build %pkgconf-as-pkg-config))