diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 02fe3cdec5..ca168c0d31 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -7,7 +7,11 @@ // files, and therefore any `#include` harms reproducibility. Additionally, // the test case isn't minimal since the included file almost assuredly // contains things that aren't necessary to reproduce the bug, and makes -// tracking it down much more difficult. If necessary, see +// tracking it down much more difficult. +// +// Use the `--dump-preprocessed-input` flag or the +// `bindgen::Builder::dump_preprocessed_input` method to make your test case +// standalone and without `#include`s, and then use C-Reduce to minimize it: // https://github.com/servo/rust-bindgen/blob/master/CONTRIBUTING.md#using-creduce-to-minimize-test-cases ``` @@ -59,8 +63,8 @@ bindings is missing a field that exists in the C/C++ struct, note that here.
``` -Insert debug logging when running bindgen with the `RUST_LOG=bindgen` environment -variable set. +Insert debug logging when running bindgen (not when compiling bindgen's output) +with the `RUST_LOG=bindgen` environment variable set. ```
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 56f75ab1f8..1eb6f76bdb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -283,11 +283,6 @@ Afterwards, there should be a `__bindgen.i` or `__bindgen.ii` file containing the combined and preprocessed input headers, which is usable as an isolated, standalone test case. -Note that the preprocessor likely removed all comments, so if the bug you're -trying to pin down involves source annotations (for example, `/**
*/`), then you will have to manually reapply them to the -preprocessed file. - ### Writing a Predicate Script Writing a `predicate.sh` script for a `bindgen` test case is fairly diff --git a/src/lib.rs b/src/lib.rs index 312155a51d..700ca7e9c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,7 +91,7 @@ use std::fs::{File, OpenOptions}; use std::iter; use std::io::{self, Write}; use std::path::{Path, PathBuf}; -use std::process::Command; +use std::process::{Command, Stdio}; use std::sync::Arc; use syntax::ast; @@ -870,14 +870,27 @@ impl Builder { let mut cmd = Command::new(&clang.path); cmd.arg("-save-temps") + .arg("-E") + .arg("-C") .arg("-c") - .arg(&wrapper_path); + .arg(&wrapper_path) + .stdout(Stdio::piped()); for a in &self.options.clang_args { cmd.arg(a); } - if cmd.spawn()?.wait()?.success() { + let mut child = cmd.spawn()?; + + let mut preprocessed = child.stdout.take().unwrap(); + let mut file = File::create(if is_cpp { + "__bindgen.ii" + } else { + "__bindgen.i" + })?; + io::copy(&mut preprocessed, &mut file)?; + + if child.wait()?.success() { Ok(()) } else { Err(io::Error::new(io::ErrorKind::Other, diff --git a/tests/headers/arg_keyword.hpp b/tests/headers/arg_keyword.hpp index 9f0af85030..283fcf2306 100644 --- a/tests/headers/arg_keyword.hpp +++ b/tests/headers/arg_keyword.hpp @@ -1 +1,3 @@ +// This comment exists to ensure that `--dump-preprocessed-input` doesn't strip +// comments. void foo(const char* type);