Skip to content

Commit b184b8d

Browse files
authored
Merge pull request #633 from jyn514/dynamic-targets
Allow non-tier-one targets to be built
2 parents 0822ab5 + 8ac235f commit b184b8d

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

.github/ISSUE_TEMPLATE/sandbox-limits-increase-request.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ assignees: ''
1616

1717
**Requested RAM limit:**
1818
**Requested timeout:**
19+
**Requested number of targets:**
1920

2021
**Why your crate needs the resource increases:**

src/db/migrate.rs

+11
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,17 @@ fn migrate_inner(version: Option<Version>, conn: &Connection, apply_mode: ApplyM
296296
"ALTER TABLE releases ALTER COLUMN default_target DROP NOT NULL;
297297
ALTER TABLE releases ALTER COLUMN default_target DROP DEFAULT",
298298
),
299+
migration!(
300+
context,
301+
// version
302+
9,
303+
// description
304+
"Allow max number of targets to be overriden",
305+
// upgrade query
306+
"ALTER TABLE sandbox_overrides ADD COLUMN max_targets INT;",
307+
// downgrade query
308+
"ALTER TABLE sandbox_overrides DROP COLUMN max_targets;"
309+
),
299310
];
300311

301312
for migration in migrations {

src/docbuilder/limits.rs

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::time::Duration;
55

66
pub(crate) struct Limits {
77
memory: usize,
8+
targets: usize,
89
timeout: Duration,
910
networking: bool,
1011
max_log_size: usize,
@@ -15,6 +16,7 @@ impl Default for Limits {
1516
Self {
1617
memory: 3 * 1024 * 1024 * 1024, // 3 GB
1718
timeout: Duration::from_secs(15 * 60), // 15 minutes
19+
targets: 10,
1820
networking: false,
1921
max_log_size: 100 * 1024, // 100 KB
2022
}
@@ -37,6 +39,9 @@ impl Limits {
3739
if let Some(timeout) = row.get::<_, Option<i32>>("timeout_seconds") {
3840
limits.timeout = Duration::from_secs(timeout as u64);
3941
}
42+
if let Some(targets) = row.get::<_, Option<u32>>("max_targets") {
43+
limits.targets = targets as usize;
44+
}
4045
}
4146

4247
Ok(limits)
@@ -58,6 +63,10 @@ impl Limits {
5863
self.max_log_size
5964
}
6065

66+
pub(crate) fn targets(&self) -> usize {
67+
self.targets
68+
}
69+
6170
pub(crate) fn for_website(&self) -> BTreeMap<String, String> {
6271
let time_scale = |v| scale(v, 60, &["seconds", "minutes", "hours"]);
6372
let size_scale = |v| scale(v, 1024, &["bytes", "KB", "MB", "GB"]);
@@ -74,6 +83,7 @@ impl Limits {
7483
} else {
7584
res.insert("Network access".into(), "blocked".into());
7685
}
86+
res.insert("Maximum number of build targets".into(), self.targets.to_string());
7787
res
7888
}
7989
}

src/docbuilder/rustwide_builder.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ impl RustwideBuilder {
130130
//
131131
// Removing it beforehand works fine, and prevents rustup from blocking the update later in
132132
// the method.
133+
//
134+
// Note that this means that non tier-one targets will be uninstalled on every update,
135+
// and will not be reinstalled until explicitly requested by a crate.
133136
for target in installed_targets {
134137
if !targets_to_install.remove(&target) {
135138
self.toolchain.remove_target(&self.workspace, &target)?;
@@ -351,7 +354,8 @@ impl RustwideBuilder {
351354
successful_targets.push(res.target.clone());
352355

353356
// Then build the documentation for all the targets
354-
for target in other_targets {
357+
// Limit the number of targets so that no one can try to build all 200000 possible targets
358+
for target in other_targets.into_iter().take(limits.targets()) {
355359
debug!("building package {} {} for {}", name, version, target);
356360
self.build_target(
357361
target,
@@ -453,6 +457,11 @@ impl RustwideBuilder {
453457
}
454458
let mut cargo_args = vec!["doc".to_owned(), "--lib".to_owned(), "--no-deps".to_owned()];
455459
if target != HOST_TARGET {
460+
// If the explicit target is not a tier one target, we need to install it.
461+
if !TARGETS.contains(&target) {
462+
// This is a no-op if the target is already installed.
463+
self.toolchain.add_target(&self.workspace, target)?;
464+
}
456465
cargo_args.push("--target".to_owned());
457466
cargo_args.push(target.to_owned());
458467
};

templates/about.hbs

+8-6
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,20 @@ no-default-features = true
153153

154154
# Target to test build on, used as the default landing page (default: "x86_64-unknown-linux-gnu")
155155
#
156-
# Available targets:
156+
# Any target supported by rustup can be used.
157+
default-target = "x86_64-unknown-linux-gnu"
158+
159+
# Targets to build (default: see below)
160+
#
161+
# Any target supported by rustup can be used.
162+
#
163+
# Default targets:
157164
# - x86_64-unknown-linux-gnu
158165
# - x86_64-apple-darwin
159166
# - x86_64-pc-windows-msvc
160167
# - i686-unknown-linux-gnu
161-
# - i686-apple-darwin
162168
# - i686-pc-windows-msvc
163-
default-target = "x86_64-unknown-linux-gnu"
164-
165-
# Targets to build (default: all tier 1 targets)
166169
#
167-
# Same available targets as `default-target`.
168170
# Set this to `[]` to only build the default target.
169171
#
170172
# If `default-target` is unset, the first element of `targets` is treated as the default target.

0 commit comments

Comments
 (0)