summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrey Pushkar <mail@apushkar.me>2020-08-01 19:26:16 +0300
committerEmilio Cobos Álvarez <emilio@crisal.io>2021-01-10 15:39:20 +0100
commit51778893c4cb18eb11cbfe83a72046f7cb0f3eac (patch)
treedff6e83c252ab6c6475274445f28b3933123d33a /src
parent9de0d64fc041633c6d0a386a577ddf8ba25dafc3 (diff)
Use absolute paths for unsaved files passed to clang and prepend -include directives to them.
Fixes #1771 Closes #1857
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index b9e1bcc5..2329dee9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -596,8 +596,16 @@ impl Builder {
///
/// The file `name` will be added to the clang arguments.
pub fn header_contents(mut self, name: &str, contents: &str) -> Builder {
+ // Apparently clang relies on having virtual FS correspondent to
+ // the real one, so we need absolute paths here
+ let absolute_path = env::current_dir()
+ .expect("Cannot retrieve current directory")
+ .join(name)
+ .to_str()
+ .expect("Cannot convert current directory name to string")
+ .to_owned();
self.input_header_contents
- .push((name.into(), contents.into()));
+ .push((absolute_path, contents.into()));
self
}
@@ -2154,7 +2162,10 @@ impl Bindings {
}
}
- for f in options.input_unsaved_files.iter() {
+ for (idx, f) in options.input_unsaved_files.iter().enumerate() {
+ if idx != 0 || options.input_header.is_some() {
+ options.clang_args.push("-include".to_owned());
+ }
options.clang_args.push(f.name.to_str().unwrap().to_owned())
}