On Thu, 27 Feb 2025 22:26:59 +0800,
Hilton Chain wrote:
>
> Cargo workspace support!
>
> https://git.boiledscript.com/hako/guix/commits/branch/cargo
I have continued to experiment on this branch (now based on rust-team), with
following changes:
- Removed git checkout support for the importer, instead a warning of missing
dependency is printed.
These dependencies are really rare. They are likely to be Cargo workspaces
and should be packaged separately.
Since these dependencies will be packaged, directory support for the build
system is removed too.
- For crates with a "src" "sys" suffix, importer adds TODO comments to their
definitions.
- Phase 'check-for-pregenerated-files moved after 'configure, since most
dependencies are origins and unpacked in configure phase.
Additionally the following command is invoked to print out all non-empty
binary files under current directory:
--8<---------------cut here---------------start------------->8---
find . -type f ! -size 0 -exec grep -IL . {} ;
--8<---------------cut here---------------end--------------->8---
This command is pretty helpful, but doesn't perform well :(
Quite a few seconds are added to the build time.
Now I think to move forward on this path we can replace all existing rust
packages to following definitions:
1. sources
Origin definitions in (gnu packages rust-crates), addition and deletion are
managed by importer and cleanup script.
+ crates published on crates.io that can be unbundled without extra dependency
2. source packages
Packaged in (gnu packages crates-*) with #:skip-build? set to #t.
+ git repository (single crate)
+ git repository (workspace)
When not all workspace members are packaged, or there's dependency among
workspace members, #:cargo-package-crates (default: ‘''()’) should be set.
Crates specefied in #:cargo-package-crates will be packaged in order. For
example rust-pipewire has such dependency among its workspace members:
--8<---------------cut here---------------start------------->8---
- pipewire-sys <-
/ \
libspa-sys <- libspa <----- pipewire
\ /
----------------
--8<---------------cut here---------------end--------------->8---
As a result, #:cargo-package-crates for rust-pipewire should be set to
''("libspa-sys" "libspa" "pipewire-sys" "pipewire")
+ published on crates.io but require extra dependency to unbundle
These crates will also have definitions imported to (gnu packages
rust-crates). These definitions should be replaced by symbol placeholders
with references commented out. For example:
--8<---------------cut here---------------start------------->8---
(define rust-ring-0.17.11 'crates-crypto-rust-ring-0.17)
...
(define-public cargo-audit-cargo-inputs
(list ...
;; rust-ring-0.17.11
...))
--8<---------------cut here---------------end--------------->8---
--8<---------------cut here---------------start------------->8---
(define rust-openssl-src-300.4.2+3.4.1 'do-not-package-rust-openssl-src)
...
(define-public rust-cargo-c-cargo-inputs
(list ...
;; rust-openssl-src-300.4.2+3.4.1
...))
--8<---------------cut here---------------end--------------->8---
The comment is used to preserve reference for cleanup script (currently
implemented in ‘grep -wc’).
By preserving these definitons with placeholders, we can avoid checking
known packages and help other packagers (the symbol placeholder appears in
error message when the definition is used as input).
3. regular packages
Packaged anywhere, install executables.
#:install-source? may be set to #f.
+ workspace support
When #:install-source? is #t (default value), 'package phase will be
executed and #:cargo-package-crates will be honored.
#:cargo-install-paths (default value ‘''(".")’) selects paths of workspace
members to be installed. For example atuin source contains following
members (in path):
--8<---------------cut here---------------start------------->8---
crates/atuin
crates/atuin-client
crates/atuin-common
crates/atuin-daemon
crates/atuin-dotfiles
...
--8<---------------cut here---------------end--------------->8---
What we wan't is the "atuin" one, so we'll set #:cargo-install-paths to
''("crates/atuin")
This argument uses path instead of crate name because ‘cargo install
<crate>’
requires <crate> to be packaged first, which is not the case when
#:install-source? is set to #f.