GNU bug report logs - #77093
[PATCH rust-team 00/18] New Rust packaging workflow based on lockfile importer.

Previous Next

Package: guix-patches;

Reported by: Hilton Chain <hako <at> ultrarare.space>

Date: Tue, 18 Mar 2025 07:18:02 UTC

Severity: normal

Tags: patch

Full log


Message #62 received at 77093 <at> debbugs.gnu.org (full text, mbox):

From: Efraim Flashner <efraim <at> flashner.co.il>
To: Hilton Chain <hako <at> ultrarare.space>
Cc: Steve George <steve <at> futurile.net>,
 Ludovic Courtès <ludo <at> gnu.org>,
 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>, 77093 <at> debbugs.gnu.org,
 Divya Ranjan Pattanaik <divya <at> subvertising.org>
Subject: Re: [bug#77093] [PATCH rust-team 03/18] build-system: cargo: Support
 packaging Cargo workspace.
Date: Tue, 18 Mar 2025 13:49:15 +0200
[Message part 1 (text/plain, inline)]
I've attached a diff that removes the need for RUSTC_BOOTSTRAP that
seems to work when I rebuilt rust-pubgrub.

Some links I followed:
https://doc.rust-lang.org/cargo/commands/cargo-publish.html#package-selection
https://github.com/rust-lang/cargo/issues/10948#issuecomment-1229236664
"One background knowledge: cargo publish is roughly `cargo package` +
call crates.io API."

Before and after:

(ins)efraim <at> 3900XT ~/workspace/guix-rust-team$ tree /gnu/store/zk1n23l2wdca8snz1wqllmjxv83hccl5-rust-pubgrub-0.3.0-0.b70cf70 | head
/gnu/store/zk1n23l2wdca8snz1wqllmjxv83hccl5-rust-pubgrub-0.3.0-0.b70cf70
└── share
    ├── cargo
    │   ├── registry
    │   │   ├── pubgrub-0.3.0.crate
    │   │   └── version-ranges-0.1.1.crate
    │   └── src
    │       ├── pubgrub-0.3.0
    │       │   ├── benches
    │       │   │   ├── backtracking.rs
(ins)efraim <at> 3900XT ~/workspace/guix-rust-team$ tree /gnu/store/9310sgn182cgqy4p1xkn2hi8x4wg0nn8-rust-pubgrub-0.3.0-0.b70cf70 | head
/gnu/store/9310sgn182cgqy4p1xkn2hi8x4wg0nn8-rust-pubgrub-0.3.0-0.b70cf70
└── share
    ├── cargo
    │   ├── registry
    │   │   ├── pubgrub-0.3.0.crate
    │   │   └── version-ranges-0.1.1.crate
    │   └── src
    │       ├── pubgrub-0.3.0
    │       │   ├── benches
    │       │   │   ├── backtracking.rs


On Tue, Mar 18, 2025 at 03:24:16PM +0800, Hilton Chain wrote:
> * guix/build-system/cargo.scm (cargo-build,cargo-cross-build)
> [#:cargo-package-crates]: New argument.
> * guix/build/cargo-build-system.scm (package): Use it.
> * doc/guix.texi (Build Systems)[cargo-build-system]: Document it.
> 
> Change-Id: I45ccd95e90827d47127015cb0bda2d41f792335b
> ---
>  doc/guix.texi                     |  7 +++++++
>  guix/build-system/cargo.scm       |  4 ++++
>  guix/build/cargo-build-system.scm | 28 ++++++++++++++++++++++++++--
>  3 files changed, 37 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/guix.texi b/doc/guix.texi
> index 0ca109a214..322512fd36 100644
> --- a/doc/guix.texi
> +++ b/doc/guix.texi
> @@ -9363,6 +9363,13 @@ Build Systems
>  the binaries defined by the crate.  Unless @code{install-source? #f} is
>  defined it will also install a source crate repository of itself and unpacked
>  sources, to ease in future hacking on rust packages.
> +
> +This build system supports cargo workspaces.  Parameter
> +@code{#:cargo-package-crates} (default: @code{''()}) allows specifying
> +names of library crates to package in @code{package} phase.  Specified
> +crates are packaged from left to right, in case there's dependency among
> +them.  For example, specifying @code{''("pcre2-sys" "pcre2")} will
> +package @code{"pcre2-sys"} first and then @code{"pcre2"}.
>  @end defvar
>  
>  @defvar chicken-build-system
> diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm
> index 452f7f78d0..4f6d46e70c 100644
> --- a/guix/build-system/cargo.scm
> +++ b/guix/build-system/cargo.scm
> @@ -94,6 +94,7 @@ (define* (cargo-build name inputs
>                        (vendor-dir "guix-vendor")
>                        (cargo-build-flags ''("--release"))
>                        (cargo-test-flags ''())
> +                      (cargo-package-crates ''())
>                        (cargo-package-flags ''("--no-metadata" "--no-verify"))
>                        (features ''())
>                        (skip-build? #f)
> @@ -122,6 +123,7 @@ (define* (cargo-build name inputs
>                         #:vendor-dir #$vendor-dir
>                         #:cargo-build-flags #$(sexp->gexp cargo-build-flags)
>                         #:cargo-test-flags #$(sexp->gexp cargo-test-flags)
> +                       #:cargo-package-crates #$(sexp->gexp cargo-package-crates)
>                         #:cargo-package-flags #$(sexp->gexp cargo-package-flags)
>                         #:cargo-target #$(cargo-triplet system)
>                         #:features #$(sexp->gexp features)
> @@ -154,6 +156,7 @@ (define* (cargo-cross-build name
>                              (vendor-dir "guix-vendor")
>                              (cargo-build-flags ''("--release"))
>                              (cargo-test-flags ''())
> +                            (cargo-package-crates ''())
>                              (cargo-package-flags ''("--no-metadata" "--no-verify"))
>                              (cargo-target (cargo-triplet (or target system)))
>                              (features ''())
> @@ -185,6 +188,7 @@ (define* (cargo-cross-build name
>                         #:vendor-dir #$vendor-dir
>                         #:cargo-build-flags #$(sexp->gexp cargo-build-flags)
>                         #:cargo-test-flags #$(sexp->gexp cargo-test-flags)
> +                       #:cargo-package-crates #$(sexp->gexp cargo-package-crates)
>                         #:cargo-package-flags #$(sexp->gexp cargo-package-flags)
>                         #:cargo-target #$(cargo-triplet (or target system))
>                         #:features #$(sexp->gexp features)
> diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm
> index 58238992b8..001e9c7adc 100644
> --- a/guix/build/cargo-build-system.scm
> +++ b/guix/build/cargo-build-system.scm
> @@ -300,11 +300,16 @@ (define* (package #:key
>                    source
>                    skip-build?
>                    install-source?
> +                  (cargo-package-crates '())
>                    (cargo-package-flags '("--no-metadata" "--no-verify"))
> +                  (vendor-dir "guix-vendor")
>                    #:allow-other-keys)
>    "Run 'cargo-package' for a given Cargo package."
>    (if install-source?
> -    (if skip-build?
> +    ;; NOTE: Cargo workspace packaging support:
> +    ;; #:install-source? #t + #:cargo-package-crates.
> +    (if (and (null? cargo-package-crates)
> +             skip-build?)
>        (begin
>          (install-file source "target/package")
>          (with-directory-excursion "target/package"
> @@ -322,7 +327,26 @@ (define* (package #:key
>          ;;error: invalid inclusion of reserved file name Cargo.toml.orig in package source
>          (when (file-exists? "Cargo.toml.orig")
>            (delete-file "Cargo.toml.orig"))
> -        (apply invoke `("cargo" "package" "--offline" ,@cargo-package-flags))
> +
> +        (if (null? cargo-package-crates)
> +            (apply invoke `("cargo" "package" "--offline" ,@cargo-package-flags))
> +            ;; Use unstable feature ‘--registry’.
> +            (begin
> +              (setenv "RUSTC_BOOTSTRAP" "1")
> +              (for-each
> +               (lambda (pkg)
> +                 (apply invoke "cargo" "package" "--offline" "--package" pkg
> +                        "--registry" "crates-io" "-Z" "package-workspace"
> +                        cargo-package-flags)
> +                 (for-each
> +                  (lambda (crate)
> +                    (invoke "tar" "xzf" crate "-C" vendor-dir))
> +                  (begin
> +                    (delete-file-recursively "target/package/tmp-registry")
> +                    (find-files "target/package" "\\.crate$")))
> +                 (patch-cargo-checksums #:vendor-dir vendor-dir))
> +               cargo-package-crates)
> +              (unsetenv "RUSTC_BOOTSTRAP")))
>  
>          ;; Then unpack the crate, reset the timestamp of all contained files, and
>          ;; repack them.  This is necessary to ensure that they are reproducible.
> -- 
> 2.48.1
> 
> 
> 

-- 
Efraim Flashner   <efraim <at> flashner.co.il>   אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
[0003-no-unstable-flags (text/plain, attachment)]
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 15 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.