Skip to content

Commit

Permalink
Add #include directives with headers for static wrappers (#2447)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdrz committed Mar 17, 2023
1 parent 9f90b32 commit b3239c5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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`.
Expand Down
2 changes: 0 additions & 2 deletions bindgen-integration/build.rs
Expand Up @@ -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() {
Expand Down
@@ -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");
Expand Down
19 changes: 19 additions & 0 deletions bindgen/codegen/mod.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;
Expand Down

0 comments on commit b3239c5

Please sign in to comment.