Skip to content

Commit e06990b

Browse files
committed
extra-targets -> targets and add documentation
1 parent c9bffa8 commit e06990b

File tree

2 files changed

+42
-30
lines changed

2 files changed

+42
-30
lines changed

src/docbuilder/metadata.rs

+34-28
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use failure::err_msg;
1919
/// all-features = true
2020
/// no-default-features = true
2121
/// default-target = "x86_64-unknown-linux-gnu"
22-
/// extra-targets = [ "x86_64-apple-darwin", "x86_64-pc-windows-msvc" ]
22+
/// targets = [ "x86_64-apple-darwin", "x86_64-pc-windows-msvc" ]
2323
/// rustc-args = [ "--example-rustc-arg" ]
2424
/// rustdoc-args = [ "--example-rustdoc-arg" ]
2525
/// ```
@@ -39,16 +39,22 @@ pub struct Metadata {
3939
/// Set `no-default-fatures` to `false` if you want to build only certain features.
4040
pub no_default_features: bool,
4141

42-
/// Docs.rs is running on `x86_64-unknown-linux-gnu` target system and default documentation
43-
/// is always built on this target. You can change default target by setting this.
42+
/// docs.rs runs on `x86_64-unknown-linux-gnu`, which is the default target for documentation by default.
43+
///
44+
/// You can change the default target by setting this.
45+
///
46+
/// If `default_target` is unset and `targets` is non-empty,
47+
/// the first element of `targets` will be used as the `default_target`.
4448
pub default_target: Option<String>,
4549

4650
/// If you want a crate to build only for specific targets,
47-
/// set `extra-targets` to the list of targets to build, in addition to `default-target`.
51+
/// set `targets` to the list of targets to build, in addition to `default-target`.
4852
///
49-
/// If you do not set `extra_targets`, all of the tier 1 supported targets will be built.
50-
/// If you set `extra_targets` to an empty array, only the default target will be built.
51-
pub extra_targets: Option<Vec<String>>,
53+
/// If you do not set `targets`, all of the tier 1 supported targets will be built.
54+
/// If you set `targets` to an empty array, only the default target will be built.
55+
/// If you set `targets` to a non-empty array but do not set `default_target`,
56+
/// the first element will be treated as the default.
57+
pub targets: Option<Vec<String>>,
5258

5359
/// List of command line arguments for `rustc`.
5460
pub rustc_args: Option<Vec<String>>,
@@ -94,7 +100,7 @@ impl Metadata {
94100
default_target: None,
95101
rustc_args: None,
96102
rustdoc_args: None,
97-
extra_targets: None,
103+
targets: None,
98104
}
99105
}
100106

@@ -119,7 +125,7 @@ impl Metadata {
119125
.and_then(|v| v.as_bool()).unwrap_or(metadata.all_features);
120126
metadata.default_target = table.get("default-target")
121127
.and_then(|v| v.as_str()).map(|v| v.to_owned());
122-
metadata.extra_targets = table.get("extra-targets").and_then(|f| f.as_array())
128+
metadata.targets = table.get("extra-targets").and_then(|f| f.as_array())
123129
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
124130
metadata.rustc_args = table.get("rustc-args").and_then(|f| f.as_array())
125131
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
@@ -136,7 +142,7 @@ impl Metadata {
136142
// Ideally this would use Iterator instead of Vec so I could collect to a `HashSet`,
137143
// but I had trouble with `chain()` ¯\_(ツ)_/¯
138144
let mut all_targets: Vec<_> = self.default_target.as_deref().into_iter().collect();
139-
match &self.extra_targets {
145+
match &self.targets {
140146
Some(targets) => all_targets.extend(targets.iter().map(|s| s.as_str())),
141147
None if all_targets.is_empty() => {
142148
// Make sure HOST_TARGET is first
@@ -146,7 +152,7 @@ impl Metadata {
146152
None => all_targets.extend(TARGETS.iter().copied()),
147153
};
148154

149-
// default_target unset and extra_targets set to `[]`
155+
// default_target unset and targets set to `[]`
150156
let landing_page = if all_targets.is_empty() {
151157
HOST_TARGET
152158
} else {
@@ -205,10 +211,10 @@ mod test {
205211

206212
assert_eq!(metadata.default_target.unwrap(), "x86_64-unknown-linux-gnu".to_owned());
207213

208-
let extra_targets = metadata.extra_targets.expect("should have explicit extra target");
209-
assert_eq!(extra_targets.len(), 2);
210-
assert_eq!(extra_targets[0], "x86_64-apple-darwin");
211-
assert_eq!(extra_targets[1], "x86_64-pc-windows-msvc");
214+
let targets = metadata.targets.expect("should have explicit extra target");
215+
assert_eq!(targets.len(), 2);
216+
assert_eq!(targets[0], "x86_64-apple-darwin");
217+
assert_eq!(targets[1], "x86_64-pc-windows-msvc");
212218

213219
let rustc_args = metadata.rustc_args.unwrap();
214220
assert_eq!(rustc_args.len(), 1);
@@ -220,8 +226,8 @@ mod test {
220226
}
221227

222228
#[test]
223-
fn test_no_extra_targets() {
224-
// metadata section but no extra_targets
229+
fn test_no_targets() {
230+
// metadata section but no targets
225231
let manifest = r#"
226232
[package]
227233
name = "test"
@@ -230,24 +236,24 @@ mod test {
230236
features = [ "feature1", "feature2" ]
231237
"#;
232238
let metadata = Metadata::from_str(manifest);
233-
assert!(metadata.extra_targets.is_none());
239+
assert!(metadata.targets.is_none());
234240

235241
// no package.metadata.docs.rs section
236242
let metadata = Metadata::from_str(r#"
237243
[package]
238244
name = "test"
239245
"#);
240-
assert!(metadata.extra_targets.is_none());
246+
assert!(metadata.targets.is_none());
241247

242248
// extra targets explicitly set to empty array
243249
let metadata = Metadata::from_str(r#"
244250
[package.metadata.docs.rs]
245251
extra-targets = []
246252
"#);
247-
assert!(metadata.extra_targets.unwrap().is_empty());
253+
assert!(metadata.targets.unwrap().is_empty());
248254
}
249255
#[test]
250-
fn test_select_extra_targets() {
256+
fn test_select_targets() {
251257
use crate::docbuilder::rustwide_builder::{HOST_TARGET, TARGETS};
252258

253259
let mut metadata = Metadata::default();
@@ -267,26 +273,26 @@ mod test {
267273
}
268274

269275
// unchanged default_target, extra targets specified to be empty
270-
metadata.extra_targets = Some(Vec::new());
276+
metadata.targets = Some(Vec::new());
271277
let (default, others) = metadata.targets();
272278
assert_eq!(default, HOST_TARGET);
273279
assert!(others.is_empty());
274280

275281
// unchanged default_target, extra targets non-empty
276-
metadata.extra_targets = Some(vec!["i686-pc-windows-msvc".into(), "i686-apple-darwin".into()]);
282+
metadata.targets = Some(vec!["i686-pc-windows-msvc".into(), "i686-apple-darwin".into()]);
277283
let (default, others) = metadata.targets();
278284
assert_eq!(default, "i686-pc-windows-msvc");
279285
assert_eq!(others.len(), 1);
280286
assert!(others.contains(&"i686-apple-darwin"));
281287

282288
// make sure that default_target is not built twice
283-
metadata.extra_targets = Some(vec![HOST_TARGET.into()]);
289+
metadata.targets = Some(vec![HOST_TARGET.into()]);
284290
let (default, others) = metadata.targets();
285291
assert_eq!(default, HOST_TARGET);
286292
assert!(others.is_empty());
287293

288294
// make sure that duplicates are removed
289-
metadata.extra_targets = Some(vec!["i686-pc-windows-msvc".into(), "i686-pc-windows-msvc".into()]);
295+
metadata.targets = Some(vec!["i686-pc-windows-msvc".into(), "i686-pc-windows-msvc".into()]);
290296
let (default, others) = metadata.targets();
291297
assert_eq!(default, "i686-pc-windows-msvc");
292298
assert!(others.is_empty());
@@ -299,13 +305,13 @@ mod test {
299305
assert!(others.contains(&"i686-pc-windows-msvc"));
300306

301307
// make sure that `default_target` takes priority over `HOST_TARGET`
302-
metadata.extra_targets = Some(vec![]);
308+
metadata.targets = Some(vec![]);
303309
let (default, others) = metadata.targets();
304310
assert_eq!(default, "i686-apple-darwin");
305311
assert!(others.is_empty());
306312

307-
// and if `extra_targets` is unset, it should still be set to `TARGETS`
308-
metadata.extra_targets = None;
313+
// and if `targets` is unset, it should still be set to `TARGETS`
314+
metadata.targets = None;
309315
let (default, others) = metadata.targets();
310316
assert_eq!(default, "i686-apple-darwin");
311317
let tier_one_targets_no_default: Vec<_> = TARGETS.iter().filter(|&&t| t != "i686-apple-darwin").copied().collect();

templates/about.hbs

+8-2
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,16 @@ no-default-features = true
162162
# - i686-pc-windows-msvc
163163
default-target = "x86_64-unknown-linux-gnu"
164164

165-
# Targets to build in addition to `default-target` (default: all tier 1 targets)
165+
# Targets to build (default: all tier 1 targets)
166+
#
166167
# Same available targets as `default-target`.
167168
# Set this to `[]` to only build the default target.
168-
extra-targets = [ "x86_64-apple-darwin", "x86_64-pc-windows-msvc" ]
169+
#
170+
# If `default-target` is unset, the first element of `targets` is treated as the default target.
171+
# Otherwise, these `targets` are built in addition to the default target.
172+
# If both `default-target` and `targets` are unset,
173+
# all tier-one targets will be built and `x86_64-unknown-linux-gnu` will be used as the default target.
174+
targets = [ "x86_64-apple-darwin", "x86_64-pc-windows-msvc" ]
169175

170176
# Additional `RUSTFLAGS` to set (default: none)
171177
rustc-args = [ "--example-rustc-arg" ]

0 commit comments

Comments
 (0)