Skip to content

Commit 9d276ae

Browse files
authored
Merge pull request #115 from rust-lang/isystem
Add support for -isystem, -iquote, -idirafter include flags
2 parents 7a442be + 948f45f commit 9d276ae

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

src/lib.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,17 @@ impl Library {
518518
}
519519
};
520520

521+
let mut dirs = Vec::new();
522+
let statik = config.is_static(name);
523+
521524
let words = split_flags(output);
525+
526+
// Handle single-character arguments like `-I/usr/include`
522527
let parts = words
523528
.iter()
524529
.filter(|l| l.len() > 2)
525-
.map(|arg| (&arg[0..2], &arg[2..]))
526-
.collect::<Vec<_>>();
527-
528-
let mut dirs = Vec::new();
529-
let statik = config.is_static(name);
530-
for &(flag, val) in &parts {
530+
.map(|arg| (&arg[0..2], &arg[2..]));
531+
for (flag, val) in parts {
531532
match flag {
532533
"-L" => {
533534
let meta = format!("rustc-link-search=native={}", val);
@@ -570,6 +571,7 @@ impl Library {
570571
}
571572
}
572573

574+
// Handle multi-character arguments with space-separated value like `-framework foo`
573575
let mut iter = words.iter().flat_map(|arg| {
574576
if arg.starts_with("-Wl,") {
575577
arg[4..].split(',').collect()
@@ -578,13 +580,20 @@ impl Library {
578580
}
579581
});
580582
while let Some(part) = iter.next() {
581-
if part != "-framework" {
582-
continue;
583-
}
584-
if let Some(lib) = iter.next() {
585-
let meta = format!("rustc-link-lib=framework={}", lib);
586-
config.print_metadata(&meta);
587-
self.frameworks.push(lib.to_string());
583+
match part {
584+
"-framework" => {
585+
if let Some(lib) = iter.next() {
586+
let meta = format!("rustc-link-lib=framework={}", lib);
587+
config.print_metadata(&meta);
588+
self.frameworks.push(lib.to_string());
589+
}
590+
}
591+
"-isystem" | "-iquote" | "-idirafter" => {
592+
if let Some(inc) = iter.next() {
593+
self.include_paths.push(PathBuf::from(inc));
594+
}
595+
}
596+
_ => (),
588597
}
589598
}
590599
}

tests/foo.pc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ Description: A dynamic binary instrumentation framework
1212
Version: 3.10.0.SVN
1313
Requires:
1414
Libs: -L${libdir}/valgrind -lcoregrind-amd64-linux -lvex-amd64-linux -lgcc
15-
Cflags: -I${includedir}
15+
Cflags: -I${includedir} -isystem /usr/foo
1616

tests/test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ fn output_ok() {
9999
assert!(lib.libs.contains(&"gcc".to_string()));
100100
assert!(lib.libs.contains(&"coregrind-amd64-linux".to_string()));
101101
assert!(lib.link_paths.contains(&PathBuf::from("/usr/lib/valgrind")));
102+
assert!(lib
103+
.include_paths
104+
.contains(&PathBuf::from("/usr/include/valgrind")));
105+
assert!(lib.include_paths.contains(&PathBuf::from("/usr/foo")));
102106
}
103107

104108
#[test]

0 commit comments

Comments
 (0)