Skip to content

Commit fc94038

Browse files
committed
Fixed #7217, added support for no spaces between flags and values in rustc-flags
1 parent 60b7bf0 commit fc94038

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -514,29 +514,38 @@ impl BuildOutput {
514514
.split(|c: char| c.is_whitespace())
515515
.filter(|w| w.chars().any(|c| !c.is_whitespace()));
516516
let (mut library_paths, mut library_links) = (Vec::new(), Vec::new());
517+
517518
while let Some(flag) = flags_iter.next() {
518-
if flag != "-l" && flag != "-L" {
519+
if flag.starts_with("-l") || flag.starts_with("-L") {
520+
// Check if this flag has no space before the value as is
521+
// common with tools like pkg-config
522+
// e.g. -L/some/dir/local/lib or -licui18n
523+
let (flag, mut value) = flag.split_at(2);
524+
if value.len() == 0 {
525+
value = match flags_iter.next() {
526+
Some(v) => v,
527+
None => failure::bail! {
528+
"Flag in rustc-flags has no value in {}: {}",
529+
whence,
530+
value
531+
}
532+
}
533+
}
534+
535+
match flag {
536+
"-l" => library_links.push(value.to_string()),
537+
"-L" => library_paths.push(PathBuf::from(value)),
538+
539+
// This was already checked above
540+
_ => unreachable!(),
541+
};
542+
} else {
519543
failure::bail!(
520544
"Only `-l` and `-L` flags are allowed in {}: `{}`",
521545
whence,
522546
value
523547
)
524548
}
525-
let value = match flags_iter.next() {
526-
Some(v) => v,
527-
None => failure::bail!(
528-
"Flag in rustc-flags has no value in {}: `{}`",
529-
whence,
530-
value
531-
),
532-
};
533-
match flag {
534-
"-l" => library_links.push(value.to_string()),
535-
"-L" => library_paths.push(PathBuf::from(value)),
536-
537-
// was already checked above
538-
_ => failure::bail!("only -l and -L flags are allowed"),
539-
};
540549
}
541550
Ok((library_paths, library_links))
542551
}

0 commit comments

Comments
 (0)