Skip to content

only build crates for default target unless asked #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/docbuilder/chroot_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const TARGETS: [&'static str; 6] = [
"x86_64-unknown-linux-gnu"
];


const DEFAULT_TARGET: &'static str = "x86_64-unknown-linux-gnu";

#[derive(Debug)]
pub struct ChrootBuilderResult {
Expand Down Expand Up @@ -86,11 +86,21 @@ impl DocBuilder {
// copy sources and documentation
let file_list = try!(self.add_sources_into_database(&conn, &pkg));
let successfully_targets = if res.have_doc {
let default_target = metadata.default_target.as_ref().map(String::as_str);
let mut build_targets = metadata.extra_targets.clone().unwrap_or_default();
{
// FIXME: skip the second build for `default_target` by copying its documentation
// in twice
let default_target = default_target.unwrap_or(DEFAULT_TARGET);
if !build_targets.iter().any(|t| t == default_target) {
build_targets.push(default_target.to_owned());
}
}
try!(self.copy_documentation(&pkg,
&res.rustc_version,
metadata.default_target.as_ref().map(String::as_str),
default_target,
true));
let successfully_targets = self.build_package_for_all_targets(&pkg);
let successfully_targets = self.build_package_for_all_targets(&pkg, &build_targets);
for target in &successfully_targets {
try!(self.copy_documentation(&pkg, &res.rustc_version, Some(target), false));
}
Expand Down Expand Up @@ -151,11 +161,16 @@ impl DocBuilder {



/// Builds documentation of crate for every target and returns Vec of successfully targets
fn build_package_for_all_targets(&self, package: &Package) -> Vec<String> {
/// Builds documentation of the given crate for the given targets and returns a Vec of the ones
/// that were successful.
fn build_package_for_all_targets(&self, package: &Package, targets: &[String]) -> Vec<String> {
let mut successfuly_targets = Vec::new();

for target in TARGETS.iter() {
for target in targets.iter() {
if !TARGETS.contains(&&**target) {
// we only support building for win/mac/linux 32-/64-bit
continue;
}
debug!("Building {} for {}", canonical_name(&package), target);
let cmd = format!("cratesfyi doc {} ={} {}",
package.manifest().name(),
Expand Down
15 changes: 15 additions & 0 deletions src/docbuilder/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use failure::err_msg;
/// all-features = true
/// no-default-features = true
/// default-target = "x86_64-unknown-linux-gnu"
/// extra-targets = [ "x86_64-apple-darwin", "x86_64-pc-windows-msvc" ]
/// rustc-args = [ "--example-rustc-arg" ]
/// rustdoc-args = [ "--example-rustdoc-arg" ]
/// dependencies = [ "example-system-dependency" ]
Expand All @@ -45,6 +46,11 @@ pub struct Metadata {
/// is always built on this target. You can change default target by setting this.
pub default_target: Option<String>,

/// Docs.rs doesn't automatically build extra targets for crates. If you want a crate to build
/// for multiple targets, set `extra-targets` to the list of targets to build, in addition to
/// `default-target`.
pub extra_targets: Option<Vec<String>>,

/// List of command line arguments for `rustc`.
pub rustc_args: Option<Vec<String>>,

Expand Down Expand Up @@ -93,6 +99,7 @@ impl Metadata {
all_features: false,
no_default_features: false,
default_target: None,
extra_targets: None,
rustc_args: None,
rustdoc_args: None,
dependencies: None,
Expand Down Expand Up @@ -120,6 +127,8 @@ impl Metadata {
.and_then(|v| v.as_bool()).unwrap_or(metadata.all_features);
metadata.default_target = table.get("default-target")
.and_then(|v| v.as_str()).map(|v| v.to_owned());
metadata.extra_targets = table.get("extra-targets").and_then(|f| f.as_array())
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
metadata.rustc_args = table.get("rustc-args").and_then(|f| f.as_array())
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
metadata.rustdoc_args = table.get("rustdoc-args").and_then(|f| f.as_array())
Expand Down Expand Up @@ -151,6 +160,7 @@ mod test {
all-features = true
no-default-features = true
default-target = "x86_64-unknown-linux-gnu"
extra-targets = [ "x86_64-apple-darwin", "x86_64-pc-windows-msvc" ]
rustc-args = [ "--example-rustc-arg" ]
rustdoc-args = [ "--example-rustdoc-arg" ]
dependencies = [ "example-system-dependency" ]
Expand All @@ -171,6 +181,11 @@ mod test {

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

let extra_targets = metadata.extra_targets.unwrap();
assert_eq!(extra_targets.len(), 2);
assert_eq!(extra_targets[0], "x86_64-apple-darwin".to_owned());
assert_eq!(extra_targets[1], "x86_64-pc-windows-msvc".to_owned());

let rustc_args = metadata.rustc_args.unwrap();
assert_eq!(rustc_args.len(), 1);
assert_eq!(rustc_args[0], "--example-rustc-arg".to_owned());
Expand Down
27 changes: 25 additions & 2 deletions templates/about.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,44 @@
</tbody>
</table>

<h4>Metadata for custom builds</h4>
<h4 id="metadata"><a href="#metadata">Metadata for custom builds</a></h4>

<p>You can customize docs.rs builds by defining <code>[package.metadata.docs.rs]</code> table in your crates' `Cargo.toml`.</p>

<p>An example metadata:</p>
<p>The available configuration flags you can customize are:</p>

<pre><code>[package]
name = "test"

[package.metadata.docs.rs]

# Features to pass to Cargo (default: none)
features = [ "feature1", "feature2" ]

# Whether to pass `--all-features` to Cargo (default: false)
all-features = true

# Whether to pass `--no-default-features` to Cargo (default: false)
no-default-features = true

# Target to test build on, used as the default landing page (default: "x86_64-unknown-linux-gnu")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this now looks very clear to me. Very helpful.

#
# Available targets:
# - x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
# - x86_64-pc-windows-msvc
# - i686-unknown-linux-gnu
# - i686-apple-darwin
# - i686-pc-windows-msvc
default-target = "x86_64-unknown-linux-gnu"

# Extra targets to build, same available targets as `default-target` (default: none)
extra-targets = [ "x86_64-apple-darwin", "x86_64-pc-windows-msvc" ]

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

# Additional `RUSTDOCFLAGS` to set (default: none)
rustdoc-args = [ "--example-rustdoc-arg" ]</pre></code>

<h4>Version</h4>
Expand Down