From patchwork Sun Mar 23 07:28:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hilton Chain X-Patchwork-Id: 40707 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 A468227BBEA; Sun, 23 Mar 2025 07:30: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=-5.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,FROM_SUSPICIOUS_NTLD,MAILING_LIST_MULTI, PDS_OTHER_BAD_TLD,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE,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 14EFC27BBE2 for ; Sun, 23 Mar 2025 07:30:38 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1twFml-0001NX-N2; Sun, 23 Mar 2025 03:30:19 -0400 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 1twFmj-0001Mp-QN for guix-patches@gnu.org; Sun, 23 Mar 2025 03:30:18 -0400 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 1twFmj-0008Ux-Em for guix-patches@gnu.org; Sun, 23 Mar 2025 03:30:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=h3Vgf4tjTqkYBWyagpTXL5ZNIhW4KaLaVkwkrFdGnws=; b=Zo3NispkFLOe2dzgr0kPTWd0+9m+EQSjO6RR9TpH4uDQkGQT6KAqLXH5PcyXQ3Ur8yqpvOoXBMojG3ZlWPMZQZQRf6EeN9qVVSgpmVTk1xjbDKW6E8a/9ba8LL7aabavIxERN9pDZX76mMzn7VVFkp4h/nhtcwIdUcgb8ayq0Xo1LbHqPIzWnBfaI45/Qimwtrwt/wo4ifimlU8UCVeLbVjHbtVJGZ6SDaI45tTrB4PJYDCm3ljv8VyWzAsxuY5XHpx7oWtx71LQh/FBB91O3DXxfBZnxQoM4V2QNKed1RTaJqR4T4R9TrBQ2Gmw90mpB+4SvD0FfWePfoZ0kpPurg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1twFmh-0004OG-WA; Sun, 23 Mar 2025 03:30:16 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77093] [PATCH rust-team v3 07/17] build/cargo: Support non-workspace directory source inputs. Resent-From: Hilton Chain Original-Sender: "Debbugs-submit" Resent-CC: divya@subvertising.org, efraim@flashner.co.il, steve@futurile.net, guix-patches@gnu.org Resent-Date: Sun, 23 Mar 2025 07:30:15 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77093 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77093@debbugs.gnu.org Cc: Hilton Chain , Divya Ranjan Pattanaik , Efraim Flashner , Steve George X-Debbugs-Original-Xcc: Divya Ranjan Pattanaik , Efraim Flashner , Steve George Received: via spool by 77093-submit@debbugs.gnu.org id=B77093.174271499816351 (code B ref 77093); Sun, 23 Mar 2025 07:30:15 +0000 Received: (at 77093) by debbugs.gnu.org; 23 Mar 2025 07:29:58 +0000 Received: from localhost ([127.0.0.1]:47341 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1twFmQ-0004FY-0k for submit@debbugs.gnu.org; Sun, 23 Mar 2025 03:29:58 -0400 Received: from mx.boiledscript.com ([88.99.243.112]:34824) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1twFlz-0004BF-7g for 77093@debbugs.gnu.org; Sun, 23 Mar 2025 03:29:32 -0400 From: Hilton Chain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ultrarare.space; s=mail; t=1742714970; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h3Vgf4tjTqkYBWyagpTXL5ZNIhW4KaLaVkwkrFdGnws=; b=CKmFZltJGcsXqX+jLqACViuNcMfaLg06AKlE2pV9nmG7cw1To/DDON4Dg/JoT44Jp0d0Cu MKbXW11B5iQyTp/H7KtJi3lx9qHkpkk5xH3d2Q60RUQ4fmgbooLubsyz2xYVqFKhX8Ls8g ew4d/5MGBodQinW/8Nv0nrgZ+wsTO9/WtRkIZiQcF4szBDUC2UwBdXDBIT5hpMqipJmEG/ yEugDt+FAhv4Eqc/RPhjfwSNBlZrb9E3Zjq204XEX/EgUKkeKF11UN4TEh932CjcgWVhhI fBLcd2pBpg5IxmTZsWlfND+hFZ/rEiNnsZx+VfU3CG2pPdpGPWaYrxbYz/jSCA== Date: Sun, 23 Mar 2025 15:28:29 +0800 Message-ID: <4c0ba403c7eac57f45425e2372cc7ba5e0c08af5.1742713356.git.hako@ultrarare.space> 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 * guix/build/cargo-build-system.scm (single-crate?): New procedure. (crate-src?): Support non-workspace directory source inputs. (configure): Likewise. Change-Id: If2bd318b44ed765baec69309f25d320edceee116 --- guix/build/cargo-build-system.scm | 60 ++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm index f2a7323748..1012d7f401 100644 --- a/guix/build/cargo-build-system.scm +++ b/guix/build/cargo-build-system.scm @@ -33,6 +33,7 @@ (define-module (guix build cargo-build-system) #:use-module (ice-9 ftw) #:use-module (ice-9 format) #:use-module (ice-9 match) + #:use-module (ice-9 textual-ports) #:use-module (ice-9 threads) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) @@ -60,22 +61,35 @@ (define (has-executable-target?) (bin-dep? (lambda (dep) (find bin? (get-kinds dep))))) (find bin-dep? (manifest-targets)))) +(define (single-crate? dir) + "Check if directory DIR contains 'Cargo.toml' and is not a workspace." + (let ((manifest-file (in-vicinity dir "Cargo.toml"))) + (and (file-exists? manifest-file) + (not (string-contains + (call-with-input-file manifest-file get-string-all) + "[workspace]"))))) + (define (crate-src? path) "Check if PATH refers to a crate source, namely a gzipped tarball with a Cargo.toml file present at its root." - (and (not (directory-exists? path)) ; not a tarball - (not (string-suffix? "py" path)) ; sanity-check.py - ;; First we print out all file names within the tarball to see if it - ;; looks like the source of a crate. However, the tarball will include - ;; an extra path component which we would like to ignore (since we're - ;; interested in checking if a Cargo.toml exists at the root of the - ;; archive, but not nested anywhere else). We do this by cutting up - ;; each output line and only looking at the second component. We then - ;; check if it matches Cargo.toml exactly and short circuit if it does. - (apply invoke (list "sh" "-c" - (string-append "tar -tf " path - " | cut -d/ -f2" - " | grep -q '^Cargo.toml$'"))))) + (if (directory-exists? path) + ;; The build system only handles sources containing single crate. + ;; Workspaces should be packaged into crates (via 'package phase) + ;; and used in inputs. + (single-crate? path) + (and (not (string-suffix? "py" path)) ;sanity-check.py + ;; First we print out all file names within the tarball to see + ;; if it looks like the source of a crate. However, the tarball + ;; will include an extra path component which we would like to + ;; ignore (since we're interested in checking if a Cargo.toml + ;; exists at the root of the archive, but not nested anywhere + ;; else). We do this by cutting up each output line and only + ;; looking at the second component. We then check if it matches + ;; Cargo.toml exactly and short circuit if it does. + (invoke "sh" "-c" + (string-append "tar -tf " path + " | cut -d/ -f2" + " | grep -q '^Cargo.toml$'"))))) (define* (unpack-rust-crates #:key inputs (vendor-dir "guix-vendor") #:allow-other-keys) @@ -159,14 +173,18 @@ (define* (configure #:key inputs (and (crate-src? path) ;; Gracefully handle duplicate inputs (not (file-exists? crate-dir)) - (mkdir-p crate-dir) - ;; Cargo crates are simply gzipped tarballs but with a .crate - ;; extension. We expand the source to a directory name we control - ;; so that we can generate any cargo checksums. - ;; The --strip-components argument is needed to prevent creating - ;; an extra directory within `crate-dir`. - (format #t "Unpacking ~a~%" name) - (invoke "tar" "xf" path "-C" crate-dir "--strip-components" "1"))))) + (if (directory-exists? path) + (copy-recursively path crate-dir) + (begin + (mkdir-p crate-dir) + ;; Cargo crates are simply gzipped tarballs but with a + ;; .crate extension. We expand the source to a directory + ;; name we control so that we can generate any cargo + ;; checksums. The --strip-components argument is needed to + ;; prevent creating an extra directory within `crate-dir`. + (format #t "Unpacking ~a~%" name) + (invoke "tar" "xf" path "-C" crate-dir + "--strip-components" "1"))))))) inputs) ;; For cross-building