Skip to content

Commit 10ea03c

Browse files
author
bors-servo
authored
Auto merge of rust-lang#817 - fitzgen:include-comments-in-preprocessed-file, r=emilio
Preserve comments when dumping preprocessed input headers It should be really easy to generate standalone, isolated test cases for bindgen bugs now \o/ See each commit for further details. r? @emilio
2 parents 63de24e + 02da653 commit 10ea03c

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
// files, and therefore any `#include` harms reproducibility. Additionally,
88
// the test case isn't minimal since the included file almost assuredly
99
// contains things that aren't necessary to reproduce the bug, and makes
10-
// tracking it down much more difficult. If necessary, see
10+
// tracking it down much more difficult.
11+
//
12+
// Use the `--dump-preprocessed-input` flag or the
13+
// `bindgen::Builder::dump_preprocessed_input` method to make your test case
14+
// standalone and without `#include`s, and then use C-Reduce to minimize it:
1115
// https://github.com/servo/rust-bindgen/blob/master/CONTRIBUTING.md#using-creduce-to-minimize-test-cases
1216
```
1317

@@ -59,8 +63,8 @@ bindings is missing a field that exists in the C/C++ struct, note that here.
5963
<details>
6064

6165
```
62-
Insert debug logging when running bindgen with the `RUST_LOG=bindgen` environment
63-
variable set.
66+
Insert debug logging when running bindgen (not when compiling bindgen's output)
67+
with the `RUST_LOG=bindgen` environment variable set.
6468
```
6569

6670
</details>

CONTRIBUTING.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,6 @@ Afterwards, there should be a `__bindgen.i` or `__bindgen.ii` file containing
283283
the combined and preprocessed input headers, which is usable as an isolated,
284284
standalone test case.
285285

286-
Note that the preprocessor likely removed all comments, so if the bug you're
287-
trying to pin down involves source annotations (for example, `/** <div
288-
rustbindgen opaque> */`), then you will have to manually reapply them to the
289-
preprocessed file.
290-
291286
### Writing a Predicate Script
292287

293288
Writing a `predicate.sh` script for a `bindgen` test case is fairly

src/lib.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ use std::fs::{File, OpenOptions};
9191
use std::iter;
9292
use std::io::{self, Write};
9393
use std::path::{Path, PathBuf};
94-
use std::process::Command;
94+
use std::process::{Command, Stdio};
9595
use std::sync::Arc;
9696

9797
use syntax::ast;
@@ -870,14 +870,27 @@ impl Builder {
870870

871871
let mut cmd = Command::new(&clang.path);
872872
cmd.arg("-save-temps")
873+
.arg("-E")
874+
.arg("-C")
873875
.arg("-c")
874-
.arg(&wrapper_path);
876+
.arg(&wrapper_path)
877+
.stdout(Stdio::piped());
875878

876879
for a in &self.options.clang_args {
877880
cmd.arg(a);
878881
}
879882

880-
if cmd.spawn()?.wait()?.success() {
883+
let mut child = cmd.spawn()?;
884+
885+
let mut preprocessed = child.stdout.take().unwrap();
886+
let mut file = File::create(if is_cpp {
887+
"__bindgen.ii"
888+
} else {
889+
"__bindgen.i"
890+
})?;
891+
io::copy(&mut preprocessed, &mut file)?;
892+
893+
if child.wait()?.success() {
881894
Ok(())
882895
} else {
883896
Err(io::Error::new(io::ErrorKind::Other,

tests/headers/arg_keyword.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
// This comment exists to ensure that `--dump-preprocessed-input` doesn't strip
2+
// comments.
13
void foo(const char* type);

0 commit comments

Comments
 (0)