@@ -21,6 +21,38 @@ class CargoLibraryArtifact(LibraryArtifact):
21
21
pass
22
22
23
23
24
+ class CargoCrateFeatures :
25
+ """Specify which crate features to build"""
26
+
27
+ #: When set to a list of features, only the specified features are built.
28
+ features : list [str ] = list ()
29
+
30
+ #: When set to False, default features are disabled.
31
+ default : bool = True
32
+
33
+ #: When set to True, all features are enabled.
34
+ all : bool = False
35
+
36
+ def __init__ (self , features : list [str ] = list (), default : bool = True , all : bool = False ):
37
+ self .features = features
38
+ self .default = default
39
+
40
+ def flags (self ) -> list [str ]:
41
+ flags = []
42
+
43
+ if self .all :
44
+ flags .append ("--all-features" )
45
+ else :
46
+ if not self .default :
47
+ flags .append ("--no-default-features" )
48
+
49
+ if self .features :
50
+ features = "," .join (self .features )
51
+ flags .append (f"--features { features } " )
52
+
53
+ return flags
54
+
55
+
24
56
class CargoBuildTask (Task ):
25
57
"""This task runs `cargo build` using the specified parameters. It will respect the authentication
26
58
credentials configured in :attr:`CargoProjectSettings.auth`."""
@@ -29,6 +61,9 @@ class CargoBuildTask(Task):
29
61
#: to an empty list instead of parsed from the Cargo manifest.
30
62
target : Property [str ]
31
63
64
+ #: Features to enable for this build.
65
+ features : Property [CargoCrateFeatures ] = Property .default (CargoCrateFeatures ())
66
+
32
67
#: Additional arguments to pass to the Cargo command-line.
33
68
additional_args : Property [list [str ]] = Property .default_factory (list )
34
69
@@ -58,11 +93,14 @@ def get_description(self) -> str | None:
58
93
def get_cargo_command_additional_flags (self ) -> list [str ]:
59
94
return shlex .split (os .environ .get ("KRAKEN_CARGO_BUILD_FLAGS" , "" ))
60
95
61
- def get_cargo_command (self , env : dict [str , str ]) -> list [str ]:
96
+ def get_cargo_subcommand (self , env : dict [str , str ], subcommand : str ) -> list [str ]:
62
97
incremental = self .incremental .get ()
63
98
if incremental is not None :
64
99
env ["CARGO_INCREMENTAL" ] = "1" if incremental else "0"
65
- return ["cargo" , "build" ] + self .additional_args .get ()
100
+ return ["cargo" , subcommand ] + self .additional_args .get () + self .features .get ().flags ()
101
+
102
+ def get_cargo_command (self , env : dict [str , str ]) -> list [str ]:
103
+ return self .get_cargo_subcommand (env , "build" )
66
104
67
105
def make_safe (self , args : list [str ], env : dict [str , str ]) -> None :
68
106
pass
0 commit comments