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. How do I tell my cargo-build-system the list of package dependencies?
  5. How do I put my list of rust-crates into a separate scheme file?
  6. I’m seeing windows package dependencies during the build, should I get rid of those?
    1. If so, how?
  7. My build can’t find pkg-config. How do I get it to recognize it?

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))

(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)
    (inputs (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

My latest issue:

$ guix build -f package.scm
...
error: failed to run custom build command for `zstd-sys v2.0.16+zstd.1.5.7`

Caused by:
  process didn't exit successfully: `/tmp/guix-build-ant-node-0.14.3.drv-0/ant-node-0.14.3/target/release/build/zstd-sys-9370d6b83cde04de/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=ZSTD_SYS_USE_PKG_CONFIG
  cargo:rerun-if-env-changed=LIBZSTD_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr

  thread 'main' (42529) panicked at /tmp/guix-build-ant-node-0.14.3.drv-0/ant-node-0.14.3/guix-vendor/rust-zstd-sys-2.0.16+zstd.1.5.7.tar.gz/build.rs:60:10:
  Can't probe for zstd in pkg-config: Could not run `PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --static --libs --cflags libzstd`
  The pkg-config command could not be found.

  Most likely, you need to install a pkg-config package for your OS.
  Try `apt install pkg-config`, or `yum install pkg-config`, or `brew install pkgconf`
  or `pkg install pkg-config`, or `apk add pkgconfig` depending on your distribution.

  If you've already installed it, ensure the pkg-config command is one of the
  directories in the PATH environment variable.

  If you did not expect this build to link to a pre-installed system library,
  then check documentation of the zstd-sys crate for an option to
  build the library from source, or disable features or dependencies
  that require pkg-config.
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: in phase 'build': uncaught exception:
%exception #<&invoke-error program: "cargo" arguments: ("build" "--offline" "-j" "4" "--release") exit-status: 101 term-signal: #f stop-signal: #f> 
phase `build' failed after 277.1 seconds
command "cargo" "build" "--offline" "-j" "4" "--release" failed with status 101
build process 6 exited with status 256
builder for `/gnu/store/aqh86grqs5m9xpp9gzylssr24q3g1p9h-ant-node-0.14.3.drv' failed with exit code 1
build of /gnu/store/aqh86grqs5m9xpp9gzylssr24q3g1p9h-ant-node-0.14.3.drv failed
View build log at '/var/log/guix/drvs/aq/h86grqs5m9xpp9gzylssr24q3g1p9h-ant-node-0.14.3.drv.gz'.
guix build: error: build of `/gnu/store/aqh86grqs5m9xpp9gzylssr24q3g1p9h-ant-node-0.14.3.drv' failed

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 not only will it return the hash code I needed, but a full-blown template! That’s amazing.

$ guix import crate ant-node

answer #4

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)

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.