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

Add cargoflags to toolchain configuration #626

Merged
merged 1 commit into from
Apr 24, 2022
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
2 changes: 2 additions & 0 deletions docs/bot-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ You can specify a toolchain using a rustup name or `branch#sha`, and use the
following flags:
* `+rustflags={flags}`: sets the `RUSTFLAGS` environment variable to `{flags}` when
building with this toolchain, e.g. `+rustflags=-Zverbose`
* `+cargoflags={flags}`: appends the given `{flags}` to the Cargo command specified
by the experiment mode, e.g. `+cargoflags=-Zavoid-dev-deps`
* `+patch={crate_name}={git_repo_url}={branch}`: patches all crates built by
this toolchain to resolve the given crate from the given git repository and branch.

Expand Down
7 changes: 6 additions & 1 deletion src/runner/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ fn run_cargo<DB: WriteResults>(
check_errors: bool,
local_packages_id: &HashSet<PackageId>,
) -> Fallible<()> {
let mut args = args.to_vec();
if let Some(ref tc_cargoflags) = ctx.toolchain.cargoflags {
args.extend(tc_cargoflags.split(' '));
}

let mut rustflags = format!("--cap-lints={}", ctx.experiment.cap_lints.to_str());
if let Some(ref tc_rustflags) = ctx.toolchain.rustflags {
rustflags.push(' ');
Expand Down Expand Up @@ -158,7 +163,7 @@ fn run_cargo<DB: WriteResults>(

let mut command = build_env
.cargo()
.args(args)
.args(&args)
.env("CARGO_INCREMENTAL", "0")
.env("RUST_BACKTRACE", "full")
.env(rustflags_env, rustflags);
Expand Down
2 changes: 2 additions & 0 deletions src/server/routes/webhooks/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ pub fn run(
detected_start = Some(Toolchain {
source: RustwideToolchain::ci(&build.base_sha, false),
rustflags: None,
cargoflags: None,
ci_try: false,
patches: Vec::new(),
});
detected_end = Some(Toolchain {
source: RustwideToolchain::ci(&build.merge_sha, false),
rustflags: None,
cargoflags: None,
ci_try: true,
patches: Vec::new(),
});
Expand Down
25 changes: 24 additions & 1 deletion src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ lazy_static! {
pub(crate) static ref MAIN_TOOLCHAIN: Toolchain = Toolchain {
source: RustwideToolchain::dist("stable"),
rustflags: None,
cargoflags: None,
ci_try: false,
patches: Vec::new(),
};
Expand All @@ -18,6 +19,7 @@ lazy_static! {
pub(crate) static ref TEST_TOOLCHAIN: Toolchain = Toolchain {
source: RustwideToolchain::dist("beta"),
rustflags: None,
cargoflags: None,
ci_try: false,
patches: Vec::new(),
};
Expand All @@ -27,6 +29,7 @@ lazy_static! {
pub struct Toolchain {
pub source: RustwideToolchain,
pub rustflags: Option<String>,
pub cargoflags: Option<String>,
pub ci_try: bool,
pub patches: Vec<CratePatch>,
}
Expand Down Expand Up @@ -65,6 +68,10 @@ impl fmt::Display for Toolchain {
write!(f, "+rustflags={}", flag)?;
}

if let Some(ref flag) = self.cargoflags {
write!(f, "+cargoflags={}", flag)?;
}

for patch in self.patches.iter() {
write!(f, "+patch={}", patch)?;
}
Expand Down Expand Up @@ -114,6 +121,7 @@ impl FromStr for Toolchain {
};

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

match flag {
"rustflags" => rustflags = Some(value),
"cargoflags" => cargoflags = Some(value),
"patch" => patches.push(value.parse()?),
unknown => return Err(ToolchainParseError::InvalidFlag(unknown.to_string())),
}
Expand All @@ -137,6 +146,7 @@ impl FromStr for Toolchain {
Ok(Toolchain {
source,
rustflags,
cargoflags,
ci_try,
patches,
})
Expand Down Expand Up @@ -189,14 +199,25 @@ mod tests {
test_from_str!($str => Toolchain {
source: $source,
rustflags: None,
cargoflags: None,
ci_try: $ci_try,
patches: Vec::new(),
});

// Test parsing with flags
// Test parsing with rustflags
test_from_str!(concat!($str, "+rustflags=foo bar") => Toolchain {
source: $source,
rustflags: Some("foo bar".to_string()),
cargoflags: None,
ci_try: $ci_try,
patches: Vec::new(),
});

// Test parsing with cargoflags
test_from_str!(concat!($str, "+cargoflags=foo bar") => Toolchain {
source: $source,
rustflags: None,
cargoflags: Some("foo bar".to_string()),
ci_try: $ci_try,
patches: Vec::new(),
});
Expand All @@ -205,6 +226,7 @@ mod tests {
test_from_str!(concat!($str, "+patch=example=https://git.example.com/some/repo=master") => Toolchain {
source: $source,
rustflags: None,
cargoflags: None,
ci_try: $ci_try,
patches: vec![CratePatch {
name: "example".to_string(),
Expand All @@ -217,6 +239,7 @@ mod tests {
test_from_str!(concat!($str, "+rustflags=foo bar+patch=example=https://git.example.com/some/repo=master") => Toolchain {
source: $source,
rustflags: Some("foo bar".to_string()),
cargoflags: None,
ci_try: $ci_try,
patches: vec![CratePatch {
name: "example".to_string(),
Expand Down