rust: Support for generated c files from bindgen

To handle static inline functions, bindgen generates a C file which is
expected to be compiled and linked into dependents on the generated
bindgen source.

This CL adds support for cc modules ingesting this output and for
bindgen to produce it (and link it against the bindgen rust_library
variant as well).

Bug: 290347127
Test: m blueprint_tests
Test: Example module with static inline functions builds locally
Change-Id: I167a8356eb6e0059fc21169fd3bfc6bf4d9c812f
This commit is contained in:
Ivan Lozano
2024-05-02 10:07:04 -04:00
parent 08f670ab4a
commit 3b591c771a
3 changed files with 102 additions and 15 deletions

View File

@@ -228,9 +228,39 @@ func TestBindgenFlagFile(t *testing.T) {
// we may be able to check libbinder.RuleParams.Command to see if it contains $(cat /dev/null flag_file.txt)
}
func TestBindgenHandleStaticInlining(t *testing.T) {
ctx := testRust(t, `
rust_bindgen {
name: "libbindgen",
wrapper_src: "src/any.h",
crate_name: "bindgen",
stem: "libbindgen",
source_stem: "bindings",
handle_static_inline: true,
static_inline_library: "libbindgen_staticfns"
}
cc_library_static {
name: "libbindgen_staticfns",
srcs: [":libbindgen"],
include_dirs: ["src/"],
}
`)
libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs")
// Make sure the flag to support `static inline` functions is present
if !strings.Contains(libbindgen.Args["flags"], "--wrap-static-fns") {
t.Errorf("missing flag to handle static inlining in rust_bindgen rule: flags %#v", libbindgen.Args["flags"])
}
if !strings.Contains(libbindgen.Args["flags"], "--wrap-static-fns-path") {
t.Errorf("missing flag to define path for static inlining C source from bindgen (--wrap-static-fns-path): flags %#v", libbindgen.Args["flags"])
}
}
func TestBindgenStaticInlineProperties(t *testing.T) {
// Make sure handle_static_inline without static_inline_library generates an error
testRustError(t, "requires declaring static_inline_library to the corresponding cc_library module that includes the generated C source from bindgen", `
rust_bindgen {
name: "libbindgen",
wrapper_src: "src/any.h",
@@ -240,9 +270,20 @@ func TestBindgenHandleStaticInlining(t *testing.T) {
handle_static_inline: true
}
`)
libbindgen := ctx.ModuleForTests("libbindgen", "android_arm64_armv8-a_source").Output("bindings.rs")
// Make sure the flag to support `static inline` functions is present
if !strings.Contains(libbindgen.Args["flags"], "--wrap-static-fns") {
t.Errorf("missing flag to handle static inlining in rust_bindgen rule: flags %#v", libbindgen.Args["flags"])
}
testRustError(t, "requires declaring handle_static_inline", `
rust_bindgen {
name: "libbindgen",
wrapper_src: "src/any.h",
crate_name: "bindgen",
stem: "libbindgen",
source_stem: "bindings",
static_inline_library: "libbindgen_staticfns"
}
cc_library_static {
name: "libbindgen_staticfns",
srcs: [":libbindgen"],
include_dirs: ["src/"],
}
`)
}