diff options
author | Andrey Pushkar <mail@apushkar.me> | 2020-08-01 19:26:16 +0300 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2021-01-10 15:39:20 +0100 |
commit | 51778893c4cb18eb11cbfe83a72046f7cb0f3eac (patch) | |
tree | dff6e83c252ab6c6475274445f28b3933123d33a /src | |
parent | 9de0d64fc041633c6d0a386a577ddf8ba25dafc3 (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.rs | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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()) } |