Skip to content

Commit c3a0431

Browse files
committed
Avoid recursive cargo calls when doing cargo clif instead of cargo-clif
Fixes #1383
1 parent c137418 commit c3a0431

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

scripts/cargo-clif.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,22 @@ fn main() {
4040
"cargo"
4141
};
4242

43-
let args: Vec<_> = match env::args().nth(1).as_deref() {
43+
let mut args = env::args().skip(1).collect::<Vec<_>>();
44+
if args.get(0).map(|arg| &**arg) == Some("clif") {
45+
// Avoid infinite recursion when invoking `cargo-clif` as cargo subcommand using
46+
// `cargo clif`.
47+
args.remove(0);
48+
}
49+
50+
let args: Vec<_> = match args.get(0).map(|arg| &**arg) {
4451
Some("jit") => {
4552
env::set_var(
4653
"RUSTFLAGS",
4754
env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic",
4855
);
56+
args.remove(0);
4957
IntoIterator::into_iter(["rustc".to_string()])
50-
.chain(env::args().skip(2))
58+
.chain(args)
5159
.chain([
5260
"--".to_string(),
5361
"-Zunstable-options".to_string(),
@@ -60,16 +68,17 @@ fn main() {
6068
"RUSTFLAGS",
6169
env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic",
6270
);
71+
args.remove(0);
6372
IntoIterator::into_iter(["rustc".to_string()])
64-
.chain(env::args().skip(2))
73+
.chain(args)
6574
.chain([
6675
"--".to_string(),
6776
"-Zunstable-options".to_string(),
6877
"-Cllvm-args=mode=jit-lazy".to_string(),
6978
])
7079
.collect()
7180
}
72-
_ => env::args().skip(1).collect(),
81+
_ => args,
7382
};
7483

7584
#[cfg(unix)]

0 commit comments

Comments
 (0)