summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/rust/hooks/default.nix
blob: d57f1b09c40a409d8b11fb2e342120c582048c51 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
{
  cargo-nextest,
  clang,
  diffutils,
  lib,
  makeSetupHook,
  rust,
  stdenv,
  pkgsHostTarget,
  pkgsTargetTarget,

  # This confusingly-named parameter indicates the *subdirectory of
  # `target/` from which to copy the build artifacts.  It is derived
  # from a stdenv platform (or a JSON file).
  target ? stdenv.targetPlatform.rust.cargoShortTarget,
  tests,
  pkgsCross,
}:
{
  cargoBuildHook = makeSetupHook {
    name = "cargo-build-hook.sh";
    substitutions = {
      inherit (stdenv.targetPlatform.rust) rustcTargetSpec;
      inherit (rust.envVars) setEnv;

    };
    passthru.tests = {
      test = tests.rust-hooks.cargoBuildHook;
      ${if stdenv.hostPlatform.isLinux then "testCross" else null} =
        pkgsCross.riscv64.tests.rust-hooks.cargoBuildHook;
    };
    meta.license = lib.licenses.mit;
  } ./cargo-build-hook.sh;

  cargoCheckHook = makeSetupHook {
    name = "cargo-check-hook.sh";
    substitutions = {
      inherit (stdenv.targetPlatform.rust) rustcTargetSpec;
      inherit (rust.envVars) setEnv;
    };
    passthru.tests = {
      test = tests.rust-hooks.cargoCheckHook;
      ${if stdenv.hostPlatform.isLinux then "testCross" else null} =
        pkgsCross.riscv64.tests.rust-hooks.cargoCheckHook;
    };
    meta.license = lib.licenses.mit;
  } ./cargo-check-hook.sh;

  cargoInstallHook = makeSetupHook {
    name = "cargo-install-hook.sh";
    substitutions = {
      targetSubdirectory = target;
    };
    passthru.tests = {
      test = tests.rust-hooks.cargoInstallHook;
      ${if stdenv.hostPlatform.isLinux then "testCross" else null} =
        pkgsCross.riscv64.tests.rust-hooks.cargoInstallHook;
    };
    meta.license = lib.licenses.mit;
  } ./cargo-install-hook.sh;

  cargoNextestHook = makeSetupHook {
    name = "cargo-nextest-hook.sh";
    propagatedBuildInputs = [ cargo-nextest ];
    substitutions = {
      inherit (stdenv.targetPlatform.rust) rustcTargetSpec;
    };
    passthru.tests = {
      test = tests.rust-hooks.cargoNextestHook;
      ${if stdenv.hostPlatform.isLinux then "testCross" else null} =
        pkgsCross.riscv64.tests.rust-hooks.cargoNextestHook;
    };
    meta.license = lib.licenses.mit;
  } ./cargo-nextest-hook.sh;

  cargoSetupHook = makeSetupHook {
    name = "cargo-setup-hook.sh";
    substitutions = {
      defaultConfig = ../fetchcargo-default-config.toml;

      # Specify the stdenv's `diff` by abspath to ensure that the user's build
      # inputs do not cause us to find the wrong `diff`.
      diff = "${lib.getBin diffutils}/bin/diff";

      cargoConfig =
        lib.optionalString (stdenv.hostPlatform.config != stdenv.targetPlatform.config) ''
          [target."${stdenv.targetPlatform.rust.rustcTarget}"]
          "linker" = "${pkgsTargetTarget.stdenv.cc}/bin/${pkgsTargetTarget.stdenv.cc.targetPrefix}cc"
          "rustflags" = [ ${
            lib.concatStringsSep ", " (
              [
                ''"-Ctarget-feature=${if stdenv.targetPlatform.isStatic then "+" else "-"}crt-static"''
              ]
              ++ lib.optional (!stdenv.targetPlatform.isx86_32) ''"-Cforce-frame-pointers=yes"''
            )
          } ]
        ''
        + ''
          [target."${stdenv.hostPlatform.rust.rustcTarget}"]
          "linker" = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"
          "rustflags" = [ ${
            lib.optionalString (!stdenv.hostPlatform.isx86_32) ''"-Cforce-frame-pointers=yes"''
          } ]
        '';
    };

    passthru.tests = {
      test = tests.rust-hooks.cargoSetupHook;
      ${if stdenv.hostPlatform.isLinux then "testCross" else null} =
        pkgsCross.riscv64.tests.rust-hooks.cargoSetupHook;
    };
    meta.license = lib.licenses.mit;
  } ./cargo-setup-hook.sh;

  maturinBuildHook = makeSetupHook {
    name = "maturin-build-hook.sh";
    propagatedBuildInputs = [
      pkgsHostTarget.maturin
      pkgsHostTarget.cargo
      pkgsHostTarget.rustc
    ];
    substitutions = {
      inherit (stdenv.targetPlatform.rust) rustcTargetSpec;
      inherit (rust.envVars) setEnv;

    };
    meta.license = lib.licenses.mit;
  } ./maturin-build-hook.sh;

  bindgenHook = makeSetupHook {
    name = "rust-bindgen-hook";
    substitutions = {
      libclang = (lib.getLib clang.cc);
      inherit clang;
    };
    meta.license = lib.licenses.mit;
  } ./rust-bindgen-hook.sh;
}