diff --git a/CHANGELOG.md b/CHANGELOG.md index 43cff3d9d4..25e9a16995 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 3cc0edb99b..2620ce24f5 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-tests/tests/expectations/tests/generated/wrap_static_fns.c b/bindgen-tests/tests/expectations/tests/generated/wrap_static_fns.c index 60c1685eaa..1057475fba 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"); diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index 3b6f72764b..352f6db038 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)?;