Skip to content

Commit 2723f3b

Browse files
committed
fix: strip --target and --target-dir from forwarded args
User CLI args like --target aarch64-unknown-none were passed through to the final cargo build command, overriding the resolved CARGO_BUILD_TARGET env var set by populate_from_args. Filter these out since the resolved hyperlight target is set via environment variable. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 308b3ad commit 2723f3b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/command.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,25 @@ impl Command {
529529

530530
fn command(&self) -> StdCommand {
531531
let mut command = self.cargo.command();
532-
command.args(self.get_args());
532+
// Filter out --target and --target-dir from forwarded args since
533+
// populate_from_args sets them via env vars with the resolved values
534+
let args: Vec<_> = self.get_args().map(|a| a.to_owned()).collect();
535+
let mut skip_next = false;
536+
for (i, arg) in args.iter().enumerate() {
537+
if skip_next {
538+
skip_next = false;
539+
continue;
540+
}
541+
let arg_str = arg.to_string_lossy();
542+
if arg_str == "--target" || arg_str == "--target-dir" {
543+
skip_next = true; // skip the next arg (the value)
544+
continue;
545+
}
546+
if arg_str.starts_with("--target=") || arg_str.starts_with("--target-dir=") {
547+
continue;
548+
}
549+
command.arg(arg);
550+
}
533551
if let Some(cwd) = &self.current_dir {
534552
command.current_dir(cwd);
535553
}

0 commit comments

Comments
 (0)