On Wed, 26 Feb 2025 23:30:59 +0800,
Efraim Flashner wrote:
>
> [1  <text/plain; utf-8 (quoted-printable)>]
> On Wed, Feb 26, 2025 at 02:43:33PM +0800, Hilton Chain wrote:
> > On Tue, 25 Feb 2025 06:26:57 +0800,
> > Hilton Chain wrote:
> > >
> > > I'm working on the generator in:
> > > https://git.boiledscript.com/hako/guix/commits/branch/origin-crates
> > >
> > > Next step is to integrate cargo2guix, I expect to have a working demo 
> > > within
> > > this week.
> >
> > Time to try in your own channel!!!
>
> Probably need to change the headers in cargo2guix to not say it's not a
> part of Guix :)

Will do this, it's not in the final form at the moment. :)

> > --8<---------------cut here---------------start------------->8---
> > guix time-machine --no-channel-files 
> > --url=https://git.boiledscript.com/hako/guix.git --branch=origin-crates 
> > --disable-authentication \
> >         import --insert <MODULE FILE> crate --lockfile=<LOCKFILE> <NAME>
> > --8<---------------cut here---------------end--------------->8---
> >
> > A mirror is available at https://codeberg.org/hako/guix-mirror.git in case
> > cloning from my server is slow for you.
> >
> >
> > Module boilerplate:
> > --8<---------------cut here---------------start------------->8---
> > (define-module (<...>)
> >   #:use-module (guix gexp)
> >   #:use-module (guix packages)
> >   #:use-module (guix download)
> >   #:use-module (guix git-download)
> >   #:use-module (guix build-system cargo))
> >
> > ;;;
> > ;;; *-cargo-inputs and crates definitions
> > ;;;
> > ;;; This file is managed by ‘guix import’.  DO NOT add definitions manually.
> > ;;;
> > --8<---------------cut here---------------end--------------->8---
> >
> > NAME-cargo-inputs will be defined as a list in MODULE, and can be used with
> > ‘(force NAME-cargo-inputs)’ and modify it with append, cons etc., e.g.
> > --8<---------------cut here---------------start------------->8---
> > (use-modules MODULE)
> > (package
> >   ...
> >   (inputs (force NAME-cargo-inputs)))
> > --8<---------------cut here---------------end--------------->8---
> >
> >
> > Examples:
> > * Module creation:
> > https://git.boiledscript.com/hako/guix/commit/76ee706140045b16b74d68723b3b959b6e768720
> >
> > * Update zoxide:
> > https://git.boiledscript.com/hako/guix/commit/76ee706140045b16b74d68723b3b959b6e768720
> >
> > * Remove #:cargo-inputs for librsvg:
> > https://git.boiledscript.com/hako/guix/commit/003708b472448b2abd64227ff8947cc9abf143e2
> >
> >
> > TODO:
> > * Support directory and Cargo workspace input in cargo-build-system
>
> I was looking closely at cargo2guix earlier this week, and I hacked up
> that if a [[package]] had a source but no checksum it was a git
> reference, and if it had no source and no checksum then it must be
> inside the workspace.
>
> > I have modified cargo2guix to support git checkouts but commented it out 
> > due to
> > lack of cargo-build-system support.
>
> Looking at guix/build/cargo-build-system, the "easiest" option would be
> to take the git-checkout and then turn it into a .tar.gz.  Otherwise
> crate-src? and 'configure would need to be adjusted to handle git
> checkouts.

Will do, I actually looked at this but stopped after knowing cargo-build-system
doesn't support Cargo workspaces.

Just found out that Cargo workspaces can be packaged with:
--8<---------------cut here---------------start------------->8---
RUSTC_BOOTSTRAP=1 cargo package --workspace --registry crates-io -Z 
package-workspace
--8<---------------cut here---------------end--------------->8---

I'll look into Cargo workspaces support too.

> > * Deletion of unused variables
> >
> > I have deletion logic in mind but don't know how to implement it at the 
> > moment:
> > --8<---------------cut here---------------start------------->8---
> > While reading file MODULE, find definitions
> > If the definition is ‘(delay (list ...))’, add content of the list to 
> > REFERENCES.
> > Otherwise add the definition name to VARIABLES
> >
> > UNUSED_VARIABLES = VARIABLES - REFERENCES
> >
> > Delete UNUSED_VARIABLES from MODULES in one go.
> > --8<---------------cut here---------------end--------------->8---
>
> Would it be easier to have 1 package per module, as in just the cargo
> inputs for zoxide in gnu/packages/rust-crates/zoxide.scm, and then you
> wouldn't need to worry about removing variables that aren't used by
> zoxide anymore but are used by another package?

Here's a working implementation using bash, grep, cut and sed.  The logic is a 
bit
different since it's not fully in Guile. :)
--8<---------------cut here---------------start------------->8---
FILE=gnu/packages/rust-crates.scm
PATTERN='^(define-public rust-'

for crate in $(grep "$PATTERN" $FILE | cut -d' ' -f2)
do
    if [ "$(grep -wc "$crate" $FILE)" -eq 1 ]; then
        echo "(begin
                (use-modules ((srfi srfi-11))
                              (guix utils))
                (let-values
                    (((source-properties term-exists)
                      (find-definition-insertion-location \"$FILE\" '$crate)))
                  (when term-exists
                    (delete-expression source-properties))))" |
            guix repl -t machine
    fi
    # Delete extra newlines.
    sed --in-place ':a;N;$!ba;s/\n\n\+/\n\n/g' $FILE
done
--8<---------------cut here---------------end--------------->8---

> > * Package cargo-audio[1] and cargo-license[2] or similiar software, and 
> > write a
> >   step-by-step packaging workflow.
> >
> > [1] https://github.com/rustsec/rustsec/tree/main/cargo-audit
> > [2] https://github.com/onur/cargo-license
>
> What's the reasoning behind delay and force for the
> <package>-cargo-inputs?
>
> I think the source-only cargo inputs shouldn't be public variables, only
> the <package>-cargo-inputs variable.

These issues are related to ‘--insert’:
1. ‘find-definition-insertion-location’ searches ‘define-public’.
2. *-cargo-inputs may be insert before its dependencies.

I'll see how I can solve them.

Reply via email to