nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: rust-lang/rust-bindgen
Pull request #2447 (2023-03-17 05:03:12)

Add `#include` directives with headers for static wrappers
Partial fix for https://github.com/rust-lang/rust-bindgen/issues/2445


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 43cff3d9..25e9a169 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -166,6 +166,9 @@
 ## Changed
  * Static functions with no arguments use `void` as their single argument
    instead of having no arguments when the `--wrap-static-fns` flag is used.
+ * The source file generated when the `--wrap-static-fns` flag is enabled now
+   contains `#include` directives with all the input headers and all the source
+   code added with the `header_contents` method.
 ## Removed
  * The following deprecated flags were removed: `--use-msvc-mangling`,
    `--rustfmt-bindings` and `--size_t-is-usize`.
diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs
index 3cc0edb9..2620ce24 100644
--- a/bindgen-integration/build.rs
+++ b/bindgen-integration/build.rs
@@ -242,8 +242,6 @@ fn setup_wrap_static_fns_test() {
         .arg("-o")
         .arg(&obj_path)
         .arg(out_path.join("wrap_static_fns.c"))
-        .arg("-include")
-        .arg(input_header_file_path)
         .output()
         .expect("`clang` command error");
     if !clang_output.status.success() {
diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs
index 3b6f7276..352f6db0 100644
--- a/bindgen/codegen/mod.rs
+++ b/bindgen/codegen/mod.rs
@@ -4545,6 +4545,7 @@ pub(crate) mod utils {
     use crate::ir::ty::TypeKind;
     use crate::{args_are_cpp, file_is_cpp};
     use std::borrow::Cow;
+    use std::io::Write;
     use std::mem;
     use std::path::PathBuf;
     use std::str::FromStr;
@@ -4583,6 +4584,24 @@ pub(crate) mod utils {
 
         let mut code = Vec::new();
 
+        if !context.options().input_headers.is_empty() {
+            for header in &context.options().input_headers {
+                writeln!(code, "#include \"{}\"", header)?;
+            }
+
+            writeln!(code)?;
+        }
+
+        if !context.options().input_header_contents.is_empty() {
+            for (name, contents) in &context.options().input_header_contents {
+                writeln!(code, "// {}\n{}", name, contents)?;
+            }
+
+            writeln!(code)?;
+        }
+
+        writeln!(code, "// Static wrappers\n")?;
+
         for &id in &result.items_to_serialize {
             let item = context.resolve_item(id);
             item.serialize(context, (), &mut vec![], &mut code)?;


Test patch:
diff --git a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c
index 60c1685e..1057475f 100644
--- a/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c
+++ b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c
@@ -1,3 +1,7 @@
+#include "tests/headers/wrap-static-fns.h"
+
+// Static wrappers
+
 int foo__extern(void) asm("foo__extern");
 int foo__extern(void) { return foo(); }
 int bar__extern(void) asm("bar__extern");
Repository: rust-lang/rust-bindgen
Pull request #2466 (2023-03-24 03:10:54)

Rename `cli` feature to `__cli`
This is done to prevent users from thinking this should be an user-facing feature


Patch:
diff --git a/bindgen-cli/Cargo.toml b/bindgen-cli/Cargo.toml
index fd56d546..cc00fdda 100644
--- a/bindgen-cli/Cargo.toml
+++ b/bindgen-cli/Cargo.toml
@@ -21,7 +21,7 @@ path = "main.rs"
 name = "bindgen"
 
 [dependencies]
-bindgen = { path = "../bindgen", version = "=0.64.0", features = ["cli", "experimental"] }
+bindgen = { path = "../bindgen", version = "=0.64.0", features = ["__cli", "experimental"] }
 shlex = "1"
 clap = { version = "4", features = ["derive"] }
 env_logger = { version = "0.10.0", optional = true }
diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml
index ccc0d5b6..2b27f2a1 100644
--- a/bindgen/Cargo.toml
+++ b/bindgen/Cargo.toml
@@ -48,7 +48,7 @@ static = ["clang-sys/static"]
 runtime = ["clang-sys/runtime"]
 # Dynamically discover a `rustfmt` binary using the `which` crate
 which-rustfmt = ["which"]
-cli = []
+__cli = []
 experimental = []
 
 # These features only exist for CI testing -- don't use them if you're not hacking
diff --git a/bindgen/callbacks.rs b/bindgen/callbacks.rs
index 92ed6f4e..d85e5655 100644
--- a/bindgen/callbacks.rs
+++ b/bindgen/callbacks.rs
@@ -25,7 +25,7 @@ impl Default for MacroParsingBehavior {
 /// A trait to allow configuring different kinds of types in different
 /// situations.
 pub trait ParseCallbacks: fmt::Debug {
-    #[cfg(feature = "cli")]
+    #[cfg(feature = "__cli")]
     #[doc(hidden)]
     fn cli_args(&self) -> Vec<String> {
         vec![]
diff --git a/bindgen/lib.rs b/bindgen/lib.rs
index 673eacce..e1f0a660 100644
--- a/bindgen/lib.rs
+++ b/bindgen/lib.rs
@@ -357,10 +357,10 @@ impl Builder {
             input_headers,
             // These cannot be added from the CLI.
             input_header_contents: _,
-            #[cfg(feature = "cli")]
+            #[cfg(feature = "__cli")]
             parse_callbacks,
-            // ParseCallbacks cannot represent CLI flags if the `"cli"` feature is disabled.
-            #[cfg(not(feature = "cli"))]
+            // ParseCallbacks cannot represent CLI flags if the `"__cli"` feature is disabled.
+            #[cfg(not(feature = "__cli"))]
                 parse_callbacks: _,
             codegen_config,
             conservative_inline_namespaces,
@@ -794,7 +794,7 @@ impl Builder {
             output_vector.push("--wrap-unsafe-ops".into());
         }
 
-        #[cfg(feature = "cli")]
+        #[cfg(feature = "__cli")]
         for callbacks in parse_callbacks {
             output_vector.extend(callbacks.cli_args());
         }


Test patch:
diff --git a/bindgen-tests/Cargo.toml b/bindgen-tests/Cargo.toml
index ace5b381..3e529fb3 100644
--- a/bindgen-tests/Cargo.toml
+++ b/bindgen-tests/Cargo.toml
@@ -5,7 +5,7 @@ version = "0.1.0"
 publish = false
 
 [dev-dependencies]
-bindgen = { path = "../bindgen", features = ["cli", "experimental"] }
+bindgen = { path = "../bindgen", features = ["__cli", "experimental"] }
 diff = "0.1"
 shlex = "1"
 clap = { version = "4", features = ["derive"] }