split of cargo.toml handling
Some checks failed
CI / checks (push) Has been cancelled

This commit is contained in:
Robin Appelman 2024-12-12 00:38:52 +01:00
commit 77800944c2
3 changed files with 34 additions and 23 deletions

17
cargo-meta.nix Normal file
View file

@ -0,0 +1,17 @@
{ lib }:
let
inherit (builtins) isAttrs attrNames;
inherit (lib) assertMsg remove;
in
cargoToml: rec {
tomlPackage = cargoToml.package or cargoToml.workspace.package;
hasMsrv = tomlPackage ? rust-version;
hasWorkspace = tomlPackage ? workspace;
hasFeatures = cargoToml ? features && isAttrs cargoToml.features;
features = cargoToml.features or { };
defaultFeatures = features.default or [ ];
nonDefaultFeatures = remove "default" (attrNames features);
hasNonDefaultFeatures = hasFeatures && (defaultFeatures != nonDefaultFeatures);
hasDefaultFeatures = cargoToml ? features && cargoToml.features ? default;
msrv = assert assertMsg hasMsrv ''"rust-version" not set in Cargo.toml''; tomlPackage.rust-version;
}