NixOS / NixOS/nixpkgs

Adding support for `cargo-c`-specific hooks

Open
#482,012 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

2.status: stale
Dominant language
Nix
Stars
26.2k
Forks
20.1k
PR merge metrics
PR metrics pending

Description

CC @cpu @matthiasbeyer

While creating my kconfq project I realised that nixpkgs does not have any hooks for the cargo-c cargo applet.

The applet allows one to generate a header, pkg-config file and a cdynlib with nothing but cargo (no need for extra build systems like Meson). The sequence of cargo-c commands is always the same:

cargo cbuild
cargo ctest
cargo cinstall

Currently, nixpkgs has 6 derivations that use cargo-c:

  1. hdr10plus (buildPhase)
  2. libdovi (buildPhase)
  3. libimagequant (does not have capi in the root-level crate, can't be built with the standard hook)
  4. rav1e (postBuild)
  5. rustls-ffi (buildPhase)
  6. yara-x (postBuild)
buildPhase vs postBuild

3 of the existing derivations call cargo-c commands inside the buildPhase, while other 2 do it inside the postBuild phase.

From what I observed with libdovi, replacing

buildPhase = ''
  runHook preBuild
  # `cargo cbuild` invocation
  runHook postBuild
'';

installPhase = ''
  runHook preInstall
  # `cargo cisntall` invocation
  runHook postInstall
'';

with

postBuild = ''
  # `cargo cbuild` invocation
'';

postInstall = ''
  # `cargo cisntall` invocation
'';

does not change the output of the derivation.

Proposal

Adding cargo-c as a nativeBuildInputs dependency should automatically enable cargocBuildHook, cargocCheckHook and cargocInstallHook hooks that will be added to the buildPhase, checkPhase and installPhase phases.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the cargo-c invocations in the package.nix files for hdr10plus, libdovi, rav1e, rustls-ffi, and yara-x, especially their build, check, and install phases. Then trace existing cargo hook conventions in nixpkgs; done should be automatic cargoc build, check, and install hooks that cover these repeated commands without changing derivation output.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.