Skip to content

Commit 250680b

Browse files
committed
Add cargoflags to toolchain configuration
1 parent 75c8513 commit 250680b

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

docs/bot-usage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ You can specify a toolchain using a rustup name or `branch#sha`, and use the
149149
following flags:
150150
* `+rustflags={flags}`: sets the `RUSTFLAGS` environment variable to `{flags}` when
151151
building with this toolchain, e.g. `+rustflags=-Zverbose`
152+
* `+cargoflags={flags}`: appends the given `{flags}` to the Cargo command specified
153+
by the experiment mode, e.g. `+cargoflags=-Zavoid-dev-deps`
152154
* `+patch={crate_name}={git_repo_url}={branch}`: patches all crates built by
153155
this toolchain to resolve the given crate from the given git repository and branch.
154156

src/runner/test.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ fn run_cargo<DB: WriteResults>(
8484
check_errors: bool,
8585
local_packages_id: &HashSet<PackageId>,
8686
) -> Fallible<()> {
87+
let mut args = args.to_vec();
88+
if let Some(ref tc_cargoflags) = ctx.toolchain.cargoflags {
89+
args.extend(tc_cargoflags.split(' '));
90+
}
91+
8792
let mut rustflags = format!("--cap-lints={}", ctx.experiment.cap_lints.to_str());
8893
if let Some(ref tc_rustflags) = ctx.toolchain.rustflags {
8994
rustflags.push(' ');
@@ -158,7 +163,7 @@ fn run_cargo<DB: WriteResults>(
158163

159164
let mut command = build_env
160165
.cargo()
161-
.args(args)
166+
.args(&args)
162167
.env("CARGO_INCREMENTAL", "0")
163168
.env("RUST_BACKTRACE", "full")
164169
.env(rustflags_env, rustflags);

src/server/routes/webhooks/commands.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ pub fn run(
7272
detected_start = Some(Toolchain {
7373
source: RustwideToolchain::ci(&build.base_sha, false),
7474
rustflags: None,
75+
cargoflags: None,
7576
ci_try: false,
7677
patches: Vec::new(),
7778
});
7879
detected_end = Some(Toolchain {
7980
source: RustwideToolchain::ci(&build.merge_sha, false),
8081
rustflags: None,
82+
cargoflags: None,
8183
ci_try: true,
8284
patches: Vec::new(),
8385
});

src/toolchain.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ lazy_static! {
1010
pub(crate) static ref MAIN_TOOLCHAIN: Toolchain = Toolchain {
1111
source: RustwideToolchain::dist("stable"),
1212
rustflags: None,
13+
cargoflags: None,
1314
ci_try: false,
1415
patches: Vec::new(),
1516
};
@@ -18,6 +19,7 @@ lazy_static! {
1819
pub(crate) static ref TEST_TOOLCHAIN: Toolchain = Toolchain {
1920
source: RustwideToolchain::dist("beta"),
2021
rustflags: None,
22+
cargoflags: None,
2123
ci_try: false,
2224
patches: Vec::new(),
2325
};
@@ -27,6 +29,7 @@ lazy_static! {
2729
pub struct Toolchain {
2830
pub source: RustwideToolchain,
2931
pub rustflags: Option<String>,
32+
pub cargoflags: Option<String>,
3033
pub ci_try: bool,
3134
pub patches: Vec<CratePatch>,
3235
}
@@ -65,6 +68,10 @@ impl fmt::Display for Toolchain {
6568
write!(f, "+rustflags={}", flag)?;
6669
}
6770

71+
if let Some(ref flag) = self.cargoflags {
72+
write!(f, "+cargoflags={}", flag)?;
73+
}
74+
6875
for patch in self.patches.iter() {
6976
write!(f, "+patch={}", patch)?;
7077
}
@@ -114,6 +121,7 @@ impl FromStr for Toolchain {
114121
};
115122

116123
let mut rustflags = None;
124+
let mut cargoflags = None;
117125
let mut patches: Vec<CratePatch> = vec![];
118126
for part in parts {
119127
if let Some(equal_idx) = part.find('=') {
@@ -126,6 +134,7 @@ impl FromStr for Toolchain {
126134

127135
match flag {
128136
"rustflags" => rustflags = Some(value),
137+
"cargoflags" => cargoflags = Some(value),
129138
"patch" => patches.push(value.parse()?),
130139
unknown => return Err(ToolchainParseError::InvalidFlag(unknown.to_string())),
131140
}
@@ -137,6 +146,7 @@ impl FromStr for Toolchain {
137146
Ok(Toolchain {
138147
source,
139148
rustflags,
149+
cargoflags,
140150
ci_try,
141151
patches,
142152
})
@@ -189,14 +199,25 @@ mod tests {
189199
test_from_str!($str => Toolchain {
190200
source: $source,
191201
rustflags: None,
202+
cargoflags: None,
192203
ci_try: $ci_try,
193204
patches: Vec::new(),
194205
});
195206

196-
// Test parsing with flags
207+
// Test parsing with rustflags
197208
test_from_str!(concat!($str, "+rustflags=foo bar") => Toolchain {
198209
source: $source,
199210
rustflags: Some("foo bar".to_string()),
211+
cargoflags: None,
212+
ci_try: $ci_try,
213+
patches: Vec::new(),
214+
});
215+
216+
// Test parsing with cargoflags
217+
test_from_str!(concat!($str, "+cargoflags=foo bar") => Toolchain {
218+
source: $source,
219+
rustflags: None,
220+
cargoflags: Some("foo bar".to_string()),
200221
ci_try: $ci_try,
201222
patches: Vec::new(),
202223
});
@@ -205,6 +226,7 @@ mod tests {
205226
test_from_str!(concat!($str, "+patch=example=https://git.example.com/some/repo=master") => Toolchain {
206227
source: $source,
207228
rustflags: None,
229+
cargoflags: None,
208230
ci_try: $ci_try,
209231
patches: vec![CratePatch {
210232
name: "example".to_string(),
@@ -217,6 +239,7 @@ mod tests {
217239
test_from_str!(concat!($str, "+rustflags=foo bar+patch=example=https://git.example.com/some/repo=master") => Toolchain {
218240
source: $source,
219241
rustflags: Some("foo bar".to_string()),
242+
cargoflags: None,
220243
ci_try: $ci_try,
221244
patches: vec![CratePatch {
222245
name: "example".to_string(),

0 commit comments

Comments
 (0)