Folaht’s first attempt to build a cargo package on Guix system - The one with windows dependencies

Note: This is actually my fourth attempt, but since this one is probably easiest, I’ll change it to my first.


Wahey!

I finally found a package that I want to add to the guix system, well, my channel really, because I’m not sure how many hoops I’ve got to cross to get it onto guix, so I’ll be building this for my channel first.

I first successfully build it locally, so I think the next step is to wrap it into a guix package,
which I’ve never done before.

The package is called ant-node, although the actual first package I wanted to package was fetchit, but since it relies on ANT applications, I decided to dig down until found the my current target, ant-protocol. Although this one is already complicated, at least it’s a good starting point.

For my first package I ran into these questions..

How do I turn this package definition into a package downloadable for others..

  1. Is there some command that builds the package from this package definition?
  2. Where can I see a list of guix licenses accepted by the guix license module?
  3. How do I know the sha256 base32 code?
  4. What is guix gexp?
  5. How do I tell my cargo-build-system the list of package dependencies?
  6. How do I put my list of rust-crates into a separate scheme file?
  7. I’m seeing windows package dependencies during the build, should I get rid of those?
    1. If so, how?
  8. My build can’t find pkg-config. How do I get it to recognize it?
  9. How do I add or avoid ‘testing CA certificates’ for building this package?
  10. I get the suggestion to symlink config to config.toml. How do I do that in a package build?

package.scm

;;; 2026 Yrop <folaht@protonmail.com>

(define-module (yrop packages ant node)
  #:use-module (guix build-system cargo)
  #:use-module (guix download)
  #:use-module (guix gexp)
  #:use-module ((guix licenses)
                #:prefix license:)
  #:use-module (guix packages)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages pkg-config))

(define rust-addr2line-0.25.1
  (crate-source "addr2line" "0.25.1"
                "0jwb96gv17vdr29hbzi0ha5q6jkpgjyn7rjlg5nis65k41rk0p8v"))
...

(define-public ant-node
  (package
    (name "ant-node")
    (version "0.14.3")
    (source
     (origin
       (method url-fetch)
       (uri (crate-uri "ant-node" version))
       (file-name (string-append name "-" version ".tar.gz"))
       (sha256
        (base32 "109wvkjlvv1s6kxy8x5jwl78lx7waq9vakn3vdjyhz1sd3lmszrz"))))
    (build-system cargo-build-system)
    (arguments 
      (list #:cargo-test-flags
        ''("--"
           "--skip=node::tests::test_build_upgrade_monitor_staged_rollout_disabled"
        ...)))
    (native-inputs (list pkg-config))
    (inputs 
      (cons* mimalloc 
        `(,zstd "lib")      
            (list
            rust-addr2line-0.25.1
            ...))
  (home-page "https://github.com/WithAutonomi/ant-node")
  (synopsis
   "Pure quantum-proof network node for the Autonomi decentralized network")
  (description
   "This package provides Pure quantum-proof network node for the Autonomi decentralized network.")
  (license (list license:expat license:asl2.0))))

ant-node

Problem #7

I see this during my build…

$ guix build -r
...
./guix-vendor/rust-windows-x86-64-msvc-0.48.5.tar.gz/lib/windows.0.48.5.lib
error: Possible pre-generated file found: ./guix-vendor/rust-windows-x86-64-msvc-0.48.5.tar.gz/lib/windows.0.48.5.lib
./guix-vendor/rust-windows-x86-64-msvc-0.52.6.tar.gz/lib/windows.0.52.0.lib
error: Possible pre-generated file found: ./guix-vendor/rust-windows-x86-64-msvc-0.52.6.tar.gz/lib/windows.0.52.0.lib
./guix-vendor/rust-wit-bindgen-0.57.1.tar.gz/src/rt/libwit_bindgen_cabi.a
error: Possible pre-generated file found: ./guix-vendor/rust-wit-bindgen-0.57.1.tar.gz/src/rt/libwit_bindgen_cabi.a
...

This app doesn’t need windows support if it’s installed for guix.
Is there way to skip these parts?

Problem #10

This is what I see during the build..

$ guix build -r
...
starting phase `install'
warning: `/tmp/guix-build-ant-node-0.14.3.drv-0/source/.cargo/config` is deprecated in favor of `config.toml`
  |
  = help: if you need to support cargo 1.38 or earlier, you can symlink `config` to `config.toml`
...

Is there a way to symlink these files in my package definition?

Perhaps keep these in one single thread :wink:

I feel like that would be too big a thread.

And I expect to run into more complex issues with each new package.

answer #1

$ guix build -f ant-node.scm
/home/folaht/Nwaȥ/Êsaj/Giks/yrop/yrop/packages/ant-node:29:13: error: license:apache2.0: unbound variable

answer #2

In the guix source code

answer #3

For crates, I can just just guix import crate and guix download --recursive --git. guix import crate not only will it return the hash code I needed, but a full-blown template! That’s amazing. I chose guix download --recursive --git for the hash however, because it’s on github where it’s being developed.

answer #4

It’s for scheme comments, I think.

answer #5

To get a crates list of a project, in this case ant-protocol, start a guix rust environment, download the crate, create a rust-crates file, do some cargo commands and then generate the rust-crates list from the project’s Cargo.lock file.

$ guix shell rust rust:cargo cargo-audit cargo-license
> curl -fsSL https://static.crates.io/crates/ant-node/ant-node-0.14.3.crate | tar -xz
> cd ant-node-1.14.3
> install -D -m 644 /dev/null yrop/packages/ant/node/rust-crates.scm
> cargo generate-lockfile
> cargo audit
> cargo license
> guix import -i yrop/packages/ant/node/rust-crates.scm crate -f Cargo.lock ant-node

Then fit that into a rust-crates template. (Credits to @hako)

answer #8

Since the error referred to a missing build dependency, pkg-config was added in native-inputs. Since library package zstd as part of pkg-config was also needed, module gnu packages compression was added.

(define-module yrop packages ant node)
...
#:use-module (gnu packages compression)
#:use-module (gnu packages pkg-config)...)

...

(define-public ant-node
  (package
    ...
    (native-inputs (list pkg-config (list zstd "lib")))
...))

answer #9

Add test arguments that skip these tests.

(arguments
        (list #:cargo-test-flags
            ''("--"
               "--skip=node::tests::test_build_upgrade_monitor_staged_rollout_disabled"
               "--skip=node::tests::test_build_upgrade_monitor_staged_rollout_enabled"
               "--skip=upgrade::apply::tests::test_auto_apply_upgrader_creation"
 ...)))

In case it’s not obvious, here’s documentation. I think everything is documented but understanding all of it may require some packaging experience.

They are linked together if you read from the beginning to the end, but here I just add all the links:

Also the blog post if it’s useful: A New Rust Packaging Model.

It was not obvious to me since I only relied on the first link and just got confused.

With the third link, I’m stuck at using rust-crates.scm.
Do I have to create that file manually?

$ guix import -i gnu/packages/rust-crates.scm crate -f Cargo.lock cargo-audit
guix import: error: file 'gnu/packages/rust-crates.scm' does not exist

Do I have to download it from https://codeberg.org/guix/guix/raw/tag/v1.5.0/gnu/packages/rust-crates.scm and save it at ./gnu/packages?

[edit]

Create an empty file does the trick

$ install -D -m 644 /dev/null gnu/packages/rust-crates.scm

[/edit]

cargo-inputs is documented in the packaging guidelines and it specifies the file:

module must export a public interface lookup-cargo-inputs, a template is available in the etc/teams/rust directory of Guix source tree.

It should be defined as a module so you’ll need to change the module name accordingly and adjust your cargo-inputs usage (it accepts an optional module argument).

Thanks @hako,

I adjusted my rust-crates file accordingly.
Still the same error though.