Skip to content
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

Allow non-tier-one targets to be built #633

Merged
merged 5 commits into from
Mar 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ assignees: ''

**Requested RAM limit:**
**Requested timeout:**
**Requested number of targets:**

**Why your crate needs the resource increases:**
11 changes: 11 additions & 0 deletions src/db/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,17 @@ fn migrate_inner(version: Option<Version>, conn: &Connection, apply_mode: ApplyM
"ALTER TABLE releases ALTER COLUMN default_target DROP NOT NULL;
ALTER TABLE releases ALTER COLUMN default_target DROP DEFAULT",
),
migration!(
context,
// version
9,
// description
"Allow max number of targets to be overriden",
// upgrade query
"ALTER TABLE sandbox_overrides ADD COLUMN max_targets INT;",
// downgrade query
"ALTER TABLE sandbox_overrides DROP COLUMN max_targets;"
),
];

for migration in migrations {
Expand Down
10 changes: 10 additions & 0 deletions src/docbuilder/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::time::Duration;

pub(crate) struct Limits {
memory: usize,
targets: usize,
timeout: Duration,
networking: bool,
max_log_size: usize,
Expand All @@ -15,6 +16,7 @@ impl Default for Limits {
Self {
memory: 3 * 1024 * 1024 * 1024, // 3 GB
timeout: Duration::from_secs(15 * 60), // 15 minutes
targets: 10,
networking: false,
max_log_size: 100 * 1024, // 100 KB
}
Expand All @@ -37,6 +39,9 @@ impl Limits {
if let Some(timeout) = row.get::<_, Option<i32>>("timeout_seconds") {
limits.timeout = Duration::from_secs(timeout as u64);
}
if let Some(targets) = row.get::<_, Option<u32>>("max_targets") {
limits.targets = targets as usize;
}
}

Ok(limits)
Expand All @@ -58,6 +63,10 @@ impl Limits {
self.max_log_size
}

pub(crate) fn targets(&self) -> usize {
self.targets
}

pub(crate) fn for_website(&self) -> BTreeMap<String, String> {
let time_scale = |v| scale(v, 60, &["seconds", "minutes", "hours"]);
let size_scale = |v| scale(v, 1024, &["bytes", "KB", "MB", "GB"]);
Expand All @@ -74,6 +83,7 @@ impl Limits {
} else {
res.insert("Network access".into(), "blocked".into());
}
res.insert("Maximum number of build targets".into(), self.targets.to_string());
res
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ impl RustwideBuilder {
//
// Removing it beforehand works fine, and prevents rustup from blocking the update later in
// the method.
//
// Note that this means that non tier-one targets will be uninstalled on every update,
// and will not be reinstalled until explicitly requested by a crate.
for target in installed_targets {
if !targets_to_install.remove(&target) {
self.toolchain.remove_target(&self.workspace, &target)?;
Expand Down Expand Up @@ -351,7 +354,8 @@ impl RustwideBuilder {
successful_targets.push(res.target.clone());

// Then build the documentation for all the targets
for target in other_targets {
// Limit the number of targets so that no one can try to build all 200000 possible targets
for target in other_targets.into_iter().take(limits.targets()) {
debug!("building package {} {} for {}", name, version, target);
self.build_target(
target,
Expand Down Expand Up @@ -453,6 +457,11 @@ impl RustwideBuilder {
}
let mut cargo_args = vec!["doc".to_owned(), "--lib".to_owned(), "--no-deps".to_owned()];
if target != HOST_TARGET {
// If the explicit target is not a tier one target, we need to install it.
if !TARGETS.contains(&target) {
// This is a no-op if the target is already installed.
self.toolchain.add_target(&self.workspace, target)?;
}
cargo_args.push("--target".to_owned());
cargo_args.push(target.to_owned());
};
Expand Down
14 changes: 8 additions & 6 deletions templates/about.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,20 @@ no-default-features = true

# Target to test build on, used as the default landing page (default: "x86_64-unknown-linux-gnu")
#
# Available targets:
# Any target supported by rustup can be used.
default-target = "x86_64-unknown-linux-gnu"

# Targets to build (default: see below)
#
# Any target supported by rustup can be used.
#
# Default 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"

# Targets to build (default: all tier 1 targets)
#
# Same available targets as `default-target`.
# Set this to `[]` to only build the default target.
#
# If `default-target` is unset, the first element of `targets` is treated as the default target.
Expand Down