Skip to content

Commit 6f77eba

Browse files
committed
Add support for specifying the target to run
1 parent bc3bc63 commit 6f77eba

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

docs/bot-usage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ following flags:
153153
by the experiment mode, e.g. `+cargoflags=-Zavoid-dev-deps`
154154
* `+patch={crate_name}={git_repo_url}={branch}`: patches all crates built by
155155
this toolchain to resolve the given crate from the given git repository and branch.
156+
* `+target={target_name}`: installs the specified target and passes `--target {target-name}`
157+
to Cargo when building, e.g. `+target=i686-unknown-linux-musl`.
156158

157159
## Commands reference
158160

src/runner/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ pub fn run_ex<DB: WriteResults + Sync>(
9999
if ex.mode == Mode::Clippy {
100100
tc.add_component(workspace, "clippy")?;
101101
}
102+
if let Some(requested_target) = &tc.target {
103+
tc.add_target(workspace, requested_target)?;
104+
}
102105
}
103106

104107
info!("running tasks in {} threads...", threads_count);

src/runner/test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ fn run_cargo<DB: WriteResults>(
8989
let local_packages_id: HashSet<_> = local_packages.iter().map(|p| &p.id).collect();
9090

9191
let mut args = args.to_vec();
92+
if let Some(ref target) = ctx.toolchain.target {
93+
args.extend(["--target", target]);
94+
}
9295
if let Some(ref tc_cargoflags) = ctx.toolchain.cargoflags {
9396
args.extend(tc_cargoflags.split(' '));
9497
}

src/server/routes/webhooks/commands.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub fn run(
7171
{
7272
detected_start = Some(Toolchain {
7373
source: RustwideToolchain::ci(&build.base_sha, false),
74+
target: None,
7475
rustflags: None,
7576
rustdocflags: None,
7677
cargoflags: None,
@@ -79,6 +80,7 @@ pub fn run(
7980
});
8081
detected_end = Some(Toolchain {
8182
source: RustwideToolchain::ci(&build.merge_sha, false),
83+
target: None,
8284
rustflags: None,
8385
rustdocflags: None,
8486
cargoflags: None,

src/toolchain.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ lazy_static! {
99
/// This toolchain is used during internal tests, and must be different than TEST_TOOLCHAIN
1010
pub(crate) static ref MAIN_TOOLCHAIN: Toolchain = Toolchain {
1111
source: RustwideToolchain::dist("stable"),
12+
target: None,
1213
rustflags: None,
1314
rustdocflags: None,
1415
cargoflags: None,
@@ -19,6 +20,7 @@ lazy_static! {
1920
/// This toolchain is used during internal tests, and must be different than MAIN_TOOLCHAIN
2021
pub(crate) static ref TEST_TOOLCHAIN: Toolchain = Toolchain {
2122
source: RustwideToolchain::dist("beta"),
23+
target: None,
2224
rustflags: None,
2325
rustdocflags: None,
2426
cargoflags: None,
@@ -30,6 +32,7 @@ lazy_static! {
3032
#[derive(Serialize, Deserialize, PartialEq, Eq, Hash, Debug, Clone)]
3133
pub struct Toolchain {
3234
pub source: RustwideToolchain,
35+
pub target: Option<String>,
3336
pub rustflags: Option<String>,
3437
pub rustdocflags: Option<String>,
3538
pub cargoflags: Option<String>,
@@ -67,6 +70,10 @@ impl fmt::Display for Toolchain {
6770
panic!("unsupported rustwide toolchain");
6871
}
6972

73+
if let Some(ref target) = self.target {
74+
write!(f, "+target={}", target)?;
75+
}
76+
7077
if let Some(ref flag) = self.rustflags {
7178
write!(f, "+rustflags={}", flag)?;
7279
}
@@ -131,6 +138,7 @@ impl FromStr for Toolchain {
131138
let mut rustdocflags = None;
132139
let mut cargoflags = None;
133140
let mut patches: Vec<CratePatch> = vec![];
141+
let mut target = None;
134142
for part in parts {
135143
if let Some(equal_idx) = part.find('=') {
136144
let (flag, value_with_equal) = part.split_at(equal_idx);
@@ -145,6 +153,7 @@ impl FromStr for Toolchain {
145153
"rustdocflags" => rustdocflags = Some(value),
146154
"cargoflags" => cargoflags = Some(value),
147155
"patch" => patches.push(value.parse()?),
156+
"target" => target = Some(value),
148157
unknown => return Err(ToolchainParseError::InvalidFlag(unknown.to_string())),
149158
}
150159
} else {
@@ -154,6 +163,7 @@ impl FromStr for Toolchain {
154163

155164
Ok(Toolchain {
156165
source,
166+
target,
157167
rustflags,
158168
rustdocflags,
159169
cargoflags,
@@ -208,6 +218,18 @@ mod tests {
208218
// Test parsing without flags
209219
test_from_str!($str => Toolchain {
210220
source: $source,
221+
target: None,
222+
rustflags: None,
223+
rustdocflags: None,
224+
cargoflags: None,
225+
ci_try: $ci_try,
226+
patches: Vec::new(),
227+
});
228+
229+
// Test parsing with target
230+
test_from_str!(concat!($str, "+target=x86_64-unknown-linux-gnu") => Toolchain {
231+
source: $source,
232+
target: Some("x86_64-unknown-linux-gnu".to_string()),
211233
rustflags: None,
212234
rustdocflags: None,
213235
cargoflags: None,
@@ -218,6 +240,7 @@ mod tests {
218240
// Test parsing with rustflags
219241
test_from_str!(concat!($str, "+rustflags=foo bar") => Toolchain {
220242
source: $source,
243+
target: None,
221244
rustflags: Some("foo bar".to_string()),
222245
rustdocflags: None,
223246
cargoflags: None,
@@ -228,6 +251,7 @@ mod tests {
228251
// Test parsing with rustdocflags
229252
test_from_str!(concat!($str, "+rustdocflags=-Zunstable-options -wjson") => Toolchain {
230253
source: $source,
254+
target: None,
231255
rustflags: None,
232256
rustdocflags: Some("-Zunstable-options -wjson".to_string()),
233257
cargoflags: None,
@@ -238,6 +262,7 @@ mod tests {
238262
// Test parsing with cargoflags
239263
test_from_str!(concat!($str, "+cargoflags=foo bar") => Toolchain {
240264
source: $source,
265+
target: None,
241266
rustflags: None,
242267
rustdocflags: None,
243268
cargoflags: Some("foo bar".to_string()),
@@ -248,6 +273,7 @@ mod tests {
248273
// Test parsing with patches
249274
test_from_str!(concat!($str, "+patch=example=https://git.example.com/some/repo=master") => Toolchain {
250275
source: $source,
276+
target: None,
251277
rustflags: None,
252278
rustdocflags: None,
253279
cargoflags: None,
@@ -262,6 +288,7 @@ mod tests {
262288
// Test parsing with patches & rustflags
263289
test_from_str!(concat!($str, "+rustflags=foo bar+patch=example=https://git.example.com/some/repo=master") => Toolchain {
264290
source: $source,
291+
target: None,
265292
rustflags: Some("foo bar".to_string()),
266293
rustdocflags: None,
267294
cargoflags: None,
@@ -319,6 +346,7 @@ mod tests {
319346
assert!(Toolchain::from_str("stable+rustdocflags").is_err());
320347
assert!(Toolchain::from_str("stable+rustdocflags=").is_err());
321348
assert!(Toolchain::from_str("stable+donotusethisflag=ever").is_err());
322-
assert!(Toolchain::from_str("stable+patch=").is_err())
349+
assert!(Toolchain::from_str("stable+patch=").is_err());
350+
assert!(Toolchain::from_str("try#1234+target=").is_err());
323351
}
324352
}

0 commit comments

Comments
 (0)