build/cargo: Pass ‘--offline’ to cargo.

This will make error messages more helpful.

* guix/build/cargo-build-system.scm (build, check, package, install): Pass
‘--offline’ to cargo.

Change-Id: Ic95f603b793319f99c9c1fbce43f773bfc8126c0
This commit is contained in:
Hilton Chain 2025-02-27 21:45:51 +08:00
parent bb01612462
commit 0ee848e2ee
No known key found for this signature in database
GPG key ID: ACC66D09CA528292

View file

@ -246,7 +246,7 @@ directory = '" vendor-dir "'") port)
"Build a given Cargo package." "Build a given Cargo package."
(or skip-build? (or skip-build?
(apply invoke (apply invoke
`("cargo" "build" `("cargo" "build" "--offline"
,@(if parallel-build? ,@(if parallel-build?
(list "-j" (number->string (parallel-job-count))) (list "-j" (number->string (parallel-job-count)))
(list "-j" "1")) (list "-j" "1"))
@ -264,7 +264,7 @@ directory = '" vendor-dir "'") port)
"Run tests for a given Cargo package." "Run tests for a given Cargo package."
(when tests? (when tests?
(apply invoke (apply invoke
`("cargo" "test" `("cargo" "test" "--offline"
,@(if parallel-build? ,@(if parallel-build?
(list "-j" (number->string (parallel-job-count))) (list "-j" (number->string (parallel-job-count)))
(list "-j" "1")) (list "-j" "1"))
@ -303,7 +303,7 @@ directory = '" vendor-dir "'") port)
;;error: invalid inclusion of reserved file name Cargo.toml.orig in package source ;;error: invalid inclusion of reserved file name Cargo.toml.orig in package source
(when (file-exists? "Cargo.toml.orig") (when (file-exists? "Cargo.toml.orig")
(delete-file "Cargo.toml.orig")) (delete-file "Cargo.toml.orig"))
(apply invoke `("cargo" "package" ,@cargo-package-flags)) (apply invoke `("cargo" "package" "--offline" ,@cargo-package-flags))
;; Then unpack the crate, reset the timestamp of all contained files, and ;; Then unpack the crate, reset the timestamp of all contained files, and
;; repack them. This is necessary to ensure that they are reproducible. ;; repack them. This is necessary to ensure that they are reproducible.
@ -356,7 +356,8 @@ directory = '" vendor-dir "'") port)
;; otherwise cargo will raise an error. ;; otherwise cargo will raise an error.
(or skip-build? (or skip-build?
(not (has-executable-target?)) (not (has-executable-target?))
(invoke "cargo" "install" "--no-track" "--path" "." "--root" out (invoke "cargo" "install" "--offline" "--no-track"
"--path" "." "--root" out
"--features" (string-join features))) "--features" (string-join features)))
(when install-source? (when install-source?