Skip to content

Commit

Permalink
Fix bugs in --clang-macro-fallback
Browse files Browse the repository at this point in the history
This commit resolves a bug where -include was not respected and a bug
where -MMD was passed to the fallback translation unit which would cause
the dependency file to be overwritten with useless information about
temporary files.
  • Loading branch information
jbaublitz committed Jan 10, 2025
1 parent 59a43e1 commit 1f4d647
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 119 deletions.
3 changes: 3 additions & 0 deletions bindgen-tests/one_header-another_header-precompile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

#include <one_header.h>
#include <another_header.h>
4 changes: 0 additions & 4 deletions bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,6 @@ impl Drop for TranslationUnit {
/// Translation unit used for macro fallback parsing
pub(crate) struct FallbackTranslationUnit {
file_path: String,
header_path: String,
pch_path: String,
idx: Box<Index>,
tu: TranslationUnit,
Expand All @@ -1932,7 +1931,6 @@ impl FallbackTranslationUnit {
/// Create a new fallback translation unit
pub(crate) fn new(
file: String,
header_path: String,
pch_path: String,
c_args: &[Box<str>],
) -> Option<Self> {
Expand All @@ -1954,7 +1952,6 @@ impl FallbackTranslationUnit {
)?;
Some(FallbackTranslationUnit {
file_path: file,
header_path,
pch_path,
tu: f_translation_unit,
idx: f_index,
Expand Down Expand Up @@ -1993,7 +1990,6 @@ impl FallbackTranslationUnit {
impl Drop for FallbackTranslationUnit {
fn drop(&mut self) {
let _ = std::fs::remove_file(&self.file_path);
let _ = std::fs::remove_file(&self.header_path);
let _ = std::fs::remove_file(&self.pch_path);
}
}
Expand Down
Binary file added bindgen/codegen/.mod.rs.swp
Binary file not shown.
208 changes: 93 additions & 115 deletions bindgen/ir/context.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ impl Builder {
}

// Transform input headers to arguments on the clang command line.
self.options.fallback_clang_args = self.options.clang_args.clone();
self.options.clang_args.extend(
self.options.input_headers
[..self.options.input_headers.len().saturating_sub(1)]
Expand Down
5 changes: 5 additions & 0 deletions bindgen/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,11 @@ options! {
// This field is handled specially inside the macro.
as_args: ignore,
},
/// The set of arguments to be passed straight through to Clang for the macro fallback code.
fallback_clang_args: Vec<Box<str>> {
methods: {},
as_args: ignore,
},
/// Tuples of unsaved file contents of the form (name, contents).
input_header_contents: Vec<(Box<str>, Box<str>)> {
methods: {
Expand Down
2 changes: 2 additions & 0 deletions file.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.macro_eval.o: /home/jbaublitz/bindgen-test/testheader.h \
/usr/include/libcryptsetup.h .macro_eval.c

0 comments on commit 1f4d647

Please sign in to comment.