Skip to content

Add a way to not build tier one targets by default #1145

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

Merged
merged 1 commit into from
Nov 22, 2020
Merged
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
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ DOCSRS_LOG=docs_rs,rustwide=info
AWS_ACCESS_KEY_ID=cratesfyi
AWS_SECRET_ACCESS_KEY=secret_key
S3_ENDPOINT=http://localhost:9000
DOCSRS_INCLUDE_DEFAULT_TARGETS=false
46 changes: 32 additions & 14 deletions crates/metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//! let metadata = Metadata::from_crate_root(&source_root)?;
//!
//! // Next, learn what arguments we need to pass to `cargo`.
//! let targets = metadata.targets();
//! let targets = metadata.targets(/* include_default_targets: */ true);
//! let mut cargo_args = metadata.cargo_args(&[], &[]);
//! cargo_args.push(targets.default_target.into());
//!
Expand Down Expand Up @@ -190,7 +190,10 @@ impl Metadata {
/// Return the targets that should be built.
///
/// The `default_target` will never be one of the `other_targets`.
pub fn targets(&self) -> BuildTargets<'_> {
/// If `include_default_targets` is `true` and `targets` is unset, this also includes
/// [`DEFAULT_TARGETS`]. Otherwise, if `include_default_targets` is `false` and `targets`
/// is unset, `other_targets` will be empty.
pub fn targets(&self, include_default_targets: bool) -> BuildTargets<'_> {
let default_target = self
.default_target
.as_deref()
Expand All @@ -202,12 +205,16 @@ impl Metadata {
})
.unwrap_or(HOST_TARGET);

// Let people opt-in to only having specific targets
let mut targets: HashSet<_> = self
let crate_targets = self
.targets
.as_ref()
.map(|targets| targets.iter().map(String::as_str).collect())
.unwrap_or_else(|| DEFAULT_TARGETS.iter().copied().collect());
.map(|targets| targets.iter().map(String::as_str).collect());
// Let people opt-in to only having specific targets
let mut targets: HashSet<_> = if include_default_targets {
crate_targets.unwrap_or_else(|| DEFAULT_TARGETS.iter().copied().collect())
} else {
crate_targets.unwrap_or_default()
};

targets.remove(&default_target);
BuildTargets {
Expand Down Expand Up @@ -411,7 +418,7 @@ mod test_targets {
let BuildTargets {
default_target: default,
other_targets: tier_one,
} = metadata.targets();
} = metadata.targets(true);
assert_eq!(default, HOST_TARGET);

// should be equal to TARGETS \ {HOST_TARGET}
Expand All @@ -433,7 +440,7 @@ mod test_targets {
let BuildTargets {
default_target: default,
other_targets: others,
} = metadata.targets();
} = metadata.targets(true);

assert_eq!(default, HOST_TARGET);
assert!(others.is_empty());
Expand All @@ -447,7 +454,7 @@ mod test_targets {
let BuildTargets {
default_target: default,
other_targets: others,
} = metadata.targets();
} = metadata.targets(true);

assert_eq!(default, "i686-pc-windows-msvc");
assert_eq!(others.len(), 1);
Expand All @@ -458,7 +465,7 @@ mod test_targets {
let BuildTargets {
default_target: default,
other_targets: others,
} = metadata.targets();
} = metadata.targets(true);

assert_eq!(default, HOST_TARGET);
assert!(others.is_empty());
Expand All @@ -472,7 +479,7 @@ mod test_targets {
let BuildTargets {
default_target: default,
other_targets: others,
} = metadata.targets();
} = metadata.targets(true);

assert_eq!(default, "i686-pc-windows-msvc");
assert!(others.is_empty());
Expand All @@ -482,7 +489,7 @@ mod test_targets {
let BuildTargets {
default_target: default,
other_targets: others,
} = metadata.targets();
} = metadata.targets(true);

assert_eq!(default, "i686-apple-darwin");
assert_eq!(others.len(), 1);
Expand All @@ -493,7 +500,7 @@ mod test_targets {
let BuildTargets {
default_target: default,
other_targets: others,
} = metadata.targets();
} = metadata.targets(true);

assert_eq!(default, "i686-apple-darwin");
assert!(others.is_empty());
Expand All @@ -503,7 +510,7 @@ mod test_targets {
let BuildTargets {
default_target: default,
other_targets: others,
} = metadata.targets();
} = metadata.targets(true);

assert_eq!(default, "i686-apple-darwin");
let tier_one_targets_no_default = DEFAULT_TARGETS
Expand All @@ -514,6 +521,17 @@ mod test_targets {

assert_eq!(others, tier_one_targets_no_default);
}

#[test]
fn no_default_targets() {
// if `targets` is unset, `other_targets` should be empty
let metadata = Metadata::default();
let BuildTargets {
other_targets: others,
..
} = metadata.targets(false);
assert!(others.is_empty(), "{:?}", others);
}
}

#[cfg(test)]
Expand Down
7 changes: 4 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ use std::str::FromStr;

#[derive(Debug)]
pub struct Config {
// Build params
pub(crate) build_attempts: u16,

pub prefix: PathBuf,
pub registry_index_path: PathBuf,
pub registry_url: Option<String>,
Expand Down Expand Up @@ -41,11 +38,14 @@ pub struct Config {
// Time between 'git gc --auto' calls in seconds
pub(crate) registry_gc_interval: u64,

// Build params
pub(crate) build_attempts: u16,
pub(crate) rustwide_workspace: PathBuf,
pub(crate) inside_docker: bool,
pub(crate) local_docker_image: Option<String>,
pub(crate) toolchain: String,
pub(crate) build_cpu_limit: Option<u32>,
pub(crate) include_default_targets: bool,
}

impl Config {
Expand Down Expand Up @@ -89,6 +89,7 @@ impl Config {
local_docker_image: maybe_env("DOCS_RS_LOCAL_DOCKER_IMAGE")?,
toolchain: env("CRATESFYI_TOOLCHAIN", "nightly".to_string())?,
build_cpu_limit: maybe_env("DOCS_RS_BUILD_CPU_LIMIT")?,
include_default_targets: env("DOCSRS_INCLUDE_DEFAULT_TARGETS", true)?,
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl RustwideBuilder {
let BuildTargets {
default_target,
other_targets,
} = metadata.targets();
} = metadata.targets(self.config.include_default_targets);

// Perform an initial build
let res = self.execute_build(default_target, true, &build, &limits, &metadata)?;
Expand Down