@@ -2169,7 +2169,7 @@ pub struct CargoBuildConfig {
2169
2169
pub dep_info_basedir : Option < ConfigRelativePath > ,
2170
2170
pub target_dir : Option < ConfigRelativePath > ,
2171
2171
pub incremental : Option < bool > ,
2172
- pub target : Option < ConfigRelativePath > ,
2172
+ pub target : Option < BuildTargetConfig > ,
2173
2173
pub jobs : Option < u32 > ,
2174
2174
pub rustflags : Option < StringList > ,
2175
2175
pub rustdocflags : Option < StringList > ,
@@ -2180,6 +2180,56 @@ pub struct CargoBuildConfig {
2180
2180
pub out_dir : Option < ConfigRelativePath > ,
2181
2181
}
2182
2182
2183
+ /// Configuration for `build.target`.
2184
+ ///
2185
+ /// Accepts in the following forms:
2186
+ ///
2187
+ /// ```toml
2188
+ /// target = "a"
2189
+ /// target = ["a"]
2190
+ /// target = ["a", "b"]
2191
+ /// ```
2192
+ #[ derive( Debug , Deserialize ) ]
2193
+ #[ serde( transparent) ]
2194
+ pub struct BuildTargetConfig {
2195
+ inner : Value < BuildTargetConfigInner > ,
2196
+ }
2197
+
2198
+ #[ derive( Debug , Deserialize ) ]
2199
+ #[ serde( untagged) ]
2200
+ enum BuildTargetConfigInner {
2201
+ One ( String ) ,
2202
+ Many ( Vec < String > ) ,
2203
+ }
2204
+
2205
+ impl BuildTargetConfig {
2206
+ /// Gets values of `build.target` as a list of [`BuildTargetConfigValue`].
2207
+ pub fn values ( & self , config : & Config ) -> Vec < BuildTargetConfigValue < ' _ > > {
2208
+ let def_root = self . inner . definition . root ( config) ;
2209
+ fn map < ' a > ( s : & ' a str , root : & Path ) -> BuildTargetConfigValue < ' a > {
2210
+ if s. ends_with ( ".json" ) {
2211
+ // To absolute path.
2212
+ BuildTargetConfigValue :: Path ( root. join ( s) )
2213
+ } else {
2214
+ BuildTargetConfigValue :: Simple ( s)
2215
+ }
2216
+ }
2217
+ match & self . inner . val {
2218
+ BuildTargetConfigInner :: One ( s) => vec ! [ map( s, def_root) ] ,
2219
+ BuildTargetConfigInner :: Many ( v) => v. iter ( ) . map ( |s| map ( s, def_root) ) . collect ( ) ,
2220
+ }
2221
+ }
2222
+ }
2223
+
2224
+ /// Represents a value of `build.target`.
2225
+ pub enum BuildTargetConfigValue < ' a > {
2226
+ /// Path to a target specification file (in JSON).
2227
+ /// <https://doc.rust-lang.org/rustc/targets/custom.html>
2228
+ Path ( PathBuf ) ,
2229
+ /// A string. Probably a target triple.
2230
+ Simple ( & ' a str ) ,
2231
+ }
2232
+
2183
2233
#[ derive( Deserialize , Default ) ]
2184
2234
struct TermConfig {
2185
2235
verbose : Option < bool > ,
0 commit comments