summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/rust/build-rust-crate/helpers.nix
blob: a72bb505a4014855fb0375586e8eb2043fc309d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{ stdenv, lib }:
{
  kernel = stdenv.hostPlatform.parsed.kernel.name;
  abi = stdenv.hostPlatform.parsed.abi.name;
  cpu = stdenv.hostPlatform.parsed.cpu.name;
  updateFeatures =
    f: up: functions:
    lib.deepSeq f (
      lib.foldl' (features: fun: fun features) (lib.attrsets.recursiveUpdate f up) functions
    );
  mapFeatures = features: map (fun: fun { features = features; });
  mkFeatures =
    feat:
    lib.foldl (
      features: featureName:
      if feat.${featureName} or false then [ featureName ] ++ features else features
    ) [ ] (lib.attrNames feat);
  include =
    includedFiles: src:
    builtins.filterSource (
      path: type:
      lib.any (
        f:
        let
          p = toString (src + ("/" + f));
        in
        p == path || (lib.strings.hasPrefix (p + "/") path)
      ) includedFiles
    ) src;
  exclude =
    excludedFiles: src:
    builtins.filterSource (
      path: type: lib.all (f: !lib.strings.hasPrefix (toString (src + ("/" + f))) path) excludedFiles
    ) src;
}