Skip to content

Commit 29a92b3

Browse files
committed
feat(hooks): add additional cargo-options
1 parent 40e6053 commit 29a92b3

File tree

2 files changed

+587
-37
lines changed

2 files changed

+587
-37
lines changed

modules/cargo/common-settings.nix

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
{ lib, cargoManifestPath, ... }:
2+
let
3+
inherit (lib) types mkOption;
4+
nameType = types.strMatching "[][*?!0-9A-Za-z_-]+";
5+
featureNameType = types.strMatching "([0-9A-Za-z_-]+/)?[0-9A-Za-z_+-]+";
6+
profileNameType = types.strMatching "[0-9A-Za-z_-]+";
7+
tripleType = types.strMatching "^([0-9a-z_.]+)(-[0-9a-z_]+){1,3}$";
8+
in
9+
{
10+
# Package Selection:
11+
exclude = mkOption {
12+
type = types.listOf nameType;
13+
description = lib.mdDoc "Exclude packages from the check";
14+
default = [ ];
15+
};
16+
package = mkOption {
17+
type = types.listOf nameType;
18+
description = lib.mdDoc "Package(s) to check";
19+
default = [ ];
20+
};
21+
workspace = mkOption {
22+
type = types.bool;
23+
description = lib.mdDoc "Check all packages in the workspace";
24+
default = false;
25+
};
26+
27+
# Target Selection:
28+
all-targets = mkOption {
29+
type = types.bool;
30+
description = lib.mdDoc "Check all targets";
31+
default = false;
32+
};
33+
bench = mkOption {
34+
type = types.listOf nameType;
35+
description = lib.mdDoc "Check only the specified bench targets";
36+
default = [ ];
37+
};
38+
benches = mkOption {
39+
type = types.bool;
40+
description = lib.mdDoc "Check all bench targets";
41+
default = false;
42+
};
43+
bin = mkOption {
44+
type = types.listOf nameType;
45+
description = lib.mdDoc "Check only the specified binaries";
46+
default = [ ];
47+
};
48+
bins = mkOption {
49+
type = types.bool;
50+
description = lib.mdDoc "Check all binaries";
51+
default = false;
52+
};
53+
example = mkOption {
54+
type = types.listOf nameType;
55+
description = lib.mdDoc "Check only the specified examples";
56+
default = [ ];
57+
};
58+
examples = mkOption {
59+
type = types.bool;
60+
description = lib.mdDoc "Check all examples";
61+
default = false;
62+
};
63+
lib = mkOption {
64+
type = types.bool;
65+
description = lib.mdDoc "Check only this package's library";
66+
default = false;
67+
};
68+
test = mkOption {
69+
type = types.listOf nameType;
70+
description = lib.mdDoc "Check only the specified test targets";
71+
default = [ ];
72+
};
73+
tests = mkOption {
74+
type = types.bool;
75+
description = lib.mdDoc "Check all test targets";
76+
default = false;
77+
};
78+
79+
# Feature Selection:
80+
all-features = mkOption {
81+
type = types.bool;
82+
description = lib.mdDoc "Activate all available features";
83+
default = false;
84+
};
85+
features = mkOption {
86+
type = types.listOf featureNameType;
87+
description = lib.mdDoc "List of features to activate";
88+
default = [ ];
89+
apply = features: lib.optional (features != [ ]) (builtins.concatStringsSep "," features);
90+
};
91+
no-default-features = mkOption {
92+
type = types.bool;
93+
description = lib.mdDoc "Do not activate the `default` feature";
94+
default = false;
95+
};
96+
97+
# Compilation Options:
98+
ignore-rust-version = mkOption {
99+
type = types.bool;
100+
description = lib.mdDoc "Ignore `rust-version` specification in packages";
101+
default = false;
102+
};
103+
profile = mkOption {
104+
type = types.nullOr profileNameType;
105+
description = lib.mdDoc "Check artifacts with the specified profile";
106+
default = null;
107+
};
108+
release = mkOption {
109+
type = types.bool;
110+
description = lib.mdDoc "Check artifacts in release mode, with optimizations";
111+
default = false;
112+
};
113+
target = mkOption {
114+
type = types.listOf tripleType;
115+
description = lib.mdDoc "Check for the target triple(s)";
116+
default = [ ];
117+
};
118+
timings = mkOption {
119+
type = types.bool;
120+
description = lib.mdDoc "Output information how long each compilation takes";
121+
default = false;
122+
};
123+
124+
# Output Options:
125+
target-dir = mkOption {
126+
type = types.nullOr types.path;
127+
description = lib.mdDoc "Directory for all generated artifacts";
128+
default = null;
129+
};
130+
131+
# Display Options:
132+
color = mkOption {
133+
type = types.enum [ "auto" "always" "never" ];
134+
description = lib.mdDoc "Coloring the output";
135+
default = "always";
136+
};
137+
message-format = mkOption {
138+
type = types.nullOr (types.enum [ "human" "short" ]);
139+
description = lib.mdDoc "The output format of diagnostic messages";
140+
default = null;
141+
};
142+
verbose = mkOption {
143+
type = types.bool;
144+
description = lib.mdDoc "Use verbose output";
145+
default = false;
146+
};
147+
148+
# Manifest Options:
149+
frozen = mkOption {
150+
type = types.bool;
151+
description = lib.mdDoc "Require Cargo.lock and cache are up to date";
152+
default = false;
153+
};
154+
locked = mkOption {
155+
type = types.bool;
156+
description = lib.mdDoc "Require Cargo.lock is up to date";
157+
default = false;
158+
};
159+
manifest-path = mkOption {
160+
type = types.nullOr types.str;
161+
description = lib.mdDoc "Path to Cargo.toml";
162+
default = cargoManifestPath;
163+
};
164+
offline = mkOption {
165+
type = types.bool;
166+
description = lib.mdDoc "Run without accessing the network";
167+
default = false;
168+
};
169+
170+
# Common Options:
171+
config = mkOption {
172+
type = types.either types.str types.attrs;
173+
description = lib.mdDoc "Override configuration values";
174+
default = { };
175+
apply = config:
176+
if builtins.isAttrs config
177+
then
178+
lib.mapAttrsToList
179+
(key: value: "${key}=${toString value}")
180+
config
181+
else
182+
config;
183+
};
184+
Z = mkOption {
185+
type = types.listOf types.str;
186+
description = lib.mdDoc "Unstable (nightly-only) flags to Cargo";
187+
default = [ ];
188+
};
189+
190+
# Miscellaneous Options:
191+
future-incompat-report = mkOption {
192+
type = types.bool;
193+
description = lib.mdDoc "Outputs a future incompatibility report at the end of the build";
194+
default = false;
195+
};
196+
jobs = mkOption {
197+
type = types.nullOr types.ints.positive;
198+
description = lib.mdDoc "Number of parallel jobs, defaults to # of CPUs";
199+
default = null;
200+
};
201+
keep-going = mkOption {
202+
type = types.bool;
203+
description = lib.mdDoc "Do not abort the build as soon as there is an error";
204+
default = false;
205+
};
206+
}

0 commit comments

Comments
 (0)