Skip to content

Commit b3239c5

Browse files
authored
Add #include directives with headers for static wrappers (#2447)
1 parent 9f90b32 commit b3239c5

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@
166166
## Changed
167167
* Static functions with no arguments use `void` as their single argument
168168
instead of having no arguments when the `--wrap-static-fns` flag is used.
169+
* The source file generated when the `--wrap-static-fns` flag is enabled now
170+
contains `#include` directives with all the input headers and all the source
171+
code added with the `header_contents` method.
169172
## Removed
170173
* The following deprecated flags were removed: `--use-msvc-mangling`,
171174
`--rustfmt-bindings` and `--size_t-is-usize`.

bindgen-integration/build.rs

-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ fn setup_wrap_static_fns_test() {
242242
.arg("-o")
243243
.arg(&obj_path)
244244
.arg(out_path.join("wrap_static_fns.c"))
245-
.arg("-include")
246-
.arg(input_header_file_path)
247245
.output()
248246
.expect("`clang` command error");
249247
if !clang_output.status.success() {

bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#include "tests/headers/wrap-static-fns.h"
2+
3+
// Static wrappers
4+
15
int foo__extern(void) asm("foo__extern");
26
int foo__extern(void) { return foo(); }
37
int bar__extern(void) asm("bar__extern");

bindgen/codegen/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -4545,6 +4545,7 @@ pub(crate) mod utils {
45454545
use crate::ir::ty::TypeKind;
45464546
use crate::{args_are_cpp, file_is_cpp};
45474547
use std::borrow::Cow;
4548+
use std::io::Write;
45484549
use std::mem;
45494550
use std::path::PathBuf;
45504551
use std::str::FromStr;
@@ -4583,6 +4584,24 @@ pub(crate) mod utils {
45834584

45844585
let mut code = Vec::new();
45854586

4587+
if !context.options().input_headers.is_empty() {
4588+
for header in &context.options().input_headers {
4589+
writeln!(code, "#include \"{}\"", header)?;
4590+
}
4591+
4592+
writeln!(code)?;
4593+
}
4594+
4595+
if !context.options().input_header_contents.is_empty() {
4596+
for (name, contents) in &context.options().input_header_contents {
4597+
writeln!(code, "// {}\n{}", name, contents)?;
4598+
}
4599+
4600+
writeln!(code)?;
4601+
}
4602+
4603+
writeln!(code, "// Static wrappers\n")?;
4604+
45864605
for &id in &result.items_to_serialize {
45874606
let item = context.resolve_item(id);
45884607
item.serialize(context, (), &mut vec![], &mut code)?;

0 commit comments

Comments
 (0)