Commit graph

20 commits

Author SHA1 Message Date
Ivan Lozano
3b591c771a 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
2024-05-03 14:01:09 -04:00
Ellen Arteca
810c37ec1e Adds support to bindgen to handle static inline fcts
Adds support for bindgen to be able to handle `static inline`
functions. This is done by adding a new boolean field to the `BindgenProperties`
struct, `Handle_static_inline` (default to false).
If this field is true, then the flags to trigger bindgen support of
static inline functions are passed in.

The rust-bindgen documentation list two ways of handling `static inline`
functions, both specified with command line args.
1) --generate-inline-functions
2) --experimental --wrap-static-fns

Option 1 requires some extra effort on the part of the C library developer, in
that they have to expose the function symbols: the docs (linked below) explain
that this is often done by compiling the library with inlining disabled, which
can be detrimental to performance.

Option 2 requires no effort on the part of the C library developer, but it does
require the `--experimental` flag, since this feature is still under development.

This CL goes with option 2.

Relevant docs: https://github.com/rust-lang/rust-bindgen/discussions/2405

This CL also adds a new test: TestBindgenHandleStaticInlining in bindgen_test.go

Test: m blueprint_tests
Change-Id: If28000e3f3ccecc65c4cae1c62d7bf455454239a
2024-04-23 00:48:25 +00:00
Ivan Lozano
1dbfa144f9 rust: Fix handling of bindgen header libs
Static libraries were being appended to the list of header library
dependencies. They should not be. This also makes sure we track them
appropriately in Make.

Test: m blueprint_tests
Change-Id: Ifa664f09fe2102aea57d22cbaaeba71f0c26074d
2024-03-29 16:30:30 +00:00
Ivan Lozano
829e1e9378 rust: Emit -x c++ for bindgen modules with cpp_std
rust_bindgen modules which defined cpp_std with a .h file were not
correctly emitting the `-x c++` flag. This CL addresses that, and
ensures that if either cpp_std or c_std is set then the appropriate
behavior occurs no matter the file extension.

Bug: 304269101
Test: Soong tests
Change-Id: I71a8ae30ac0ed502d9d3fbf2f3039b0c56529d39
2023-10-09 11:52:18 -04:00
Andrei Homescu
78a1f8dfb8 rust: Add Bindgen_flag_files property
Add a new Bindgen_flag_files property to bindgen modules
that let users specify files that contain extra flags for
bindgen.

Bug: 242243245
Test: presubmit
Change-Id: I21d987c08ac417c04aaa3bfb3b75d563fc662d5b
2023-07-27 07:03:14 +00:00
Ivan Lozano
9b44383788 rust: Add header library support to rust_bindgen.
Allow rust_bindgen modules to define dependencies that only provide
headers and may not necessarily need to be linked in.

Bug: 161141999
Test: Soong tests pass.
Test: Example module has appropriate include flags when compiling.
Change-Id: Ic9ce8b1204008ad8dcb18766c914e48bb292d485
2020-11-17 13:40:50 -05:00
Ivan Lozano
0a2a115457 rust: Add cflag checks against -xc++ and -std.
If -x c++ is passed through a modules cflags, it will be overridden by a
-x c and -std flag added by the build system if the extension is not
.hpp/.hh and cpp_std is not set. This leads to confusing behavior.

Instead, add a helpful error message to guide developers towards the
correct way to specify when a header is  a C++ header and which std
version should be used.

Bug: 171011490
Test: m nothing
Change-Id: I7e7cba504798d47ce1c753ba8699d7475a95095b
2020-10-16 10:52:46 -04:00
Colin Cross
405af07859 Revert "Make lots of tests run in parallel"
This reverts commit 323dc60712.

Reason for revert: Possible cause of test instability
Bug: 170513220
Test: soong tests

Change-Id: Iee168e9fbb4210569e6cffcc23e60d111403abb8
2020-10-09 18:34:24 -07:00
Colin Cross
323dc60712 Make lots of tests run in parallel
Putting t.Parallel() in each test makes them run in parallel.
Additional t.Parallel() could be added to each subtest, although
that requires making a local copy of the loop variable for
table driven tests.

Test: m checkbuild
Change-Id: I5d9869ead441093f4d7c5757f2447385333a95a4
2020-10-06 15:12:22 -07:00
Ivan Lozano
bc9e421215 rust: Allow rust_bindgen to use cc_defaults.
rust_bindgen modules can't inherit properties in cc_defaults that would
be useful for generating bindings (such as cflags). This CL moves these
common properties out into a new struct in cc and adds that struct to
cc_default.

Additionally, Cppflags is added to rust_bindgen to make sure that these
get picked up as well from cc_defaults.

Bug: 163598610
Test: rust_bindgen module uses cflags in cc_defaults.
Test: New Soong test passes
Change-Id: I702442a355244dc01954083f98a2eebbcea12e47
2020-09-25 16:15:26 -04:00
Thiébaud Weksteen
e0510d7a69 rust: Fix module name in bindgen_test
Test: m nothing
Change-Id: Ifc1dda4433906f3496e86f5b29b7d9ec694d735c
2020-09-25 15:50:09 +02:00
Thiébaud Weksteen
4820c2c8d2 Merge "Avoid Rust source provider rule duplication" 2020-09-25 13:14:01 +00:00
Thiébaud Weksteen
295c72bebc Avoid Rust source provider rule duplication
Until now, source provider modules duplicated the rule to generate the
source for each variant. Add a inter-variant dependency between the
source and the other variants (e.g. rlib, dylib) to avoid this
duplication. Add documentation on this behaviour.

Bug: 162588681
Test: m
Change-Id: I41c9e2220f8875245415e17374852e540dfd47ec
2020-09-25 11:36:13 +02:00
Ivan Lozano
3d94752b34 rust: Add rust_bindgen std version w/ cc defaults.
Adds the c_std and cpp_std properties to rust_bindgen, and use the
default values from cc if these are undefined.

This assumes by default that the header extension indicates whether
the header is a C or C++ header file. This default can be overridden
by setting either c_std or cpp_std.

Test: Soong tests pass, "-std=" arg included in bindgen calls
Bug: 163580541
Change-Id: I5b0d3b8eae9a54dd91d8a0aca583d7803a344f27
2020-09-24 13:45:09 -04:00
Matthew Maurer
217a1e406e Merge "[rust] Escape flags for bindgen" 2020-08-06 21:33:49 +00:00
Ivan Lozano
c564d2d5a4 Add support for custom bindgen binaries.
In some cases customized logic is required to generate the expected
bindgen bindings. This adds support for rust_bindgen modules to define a
HostTool module to use instead of bindgen.

Bug: 161816141
Test: New Soong tests pass.
Test: Local test case shows custom_binary module being used for bindgen
      generation.

Change-Id: Id52aec4f25c38206d7e585d8e662be7836aa1d4b
2020-08-05 10:51:43 -04:00
Stephen Crane
12e2cb71c7 [rust] Escape flags for bindgen
Bindgen flags and cflags should be escaped, as they may contain shell
globs or other special characters.

Test: Updated Soong test passes.
Change-Id: I3df8ef25391f53a191f0494c5ff8c641d4d4b6f8
2020-08-04 12:29:54 -07:00
Ivan Lozano
26ecd6c597 [rust] Add SourceProviders as crates support.
This allows SourceProvider modules to create rust_library variants so
that generated source can be referenced as an external crate rather than
via an include macro. This is done by including rust_bindgen modules
like any other library, as a dependency in either rlibs, dylibs, or
rustlibs.

This renames the stem and flags properties for rust_bindgen modules to
source_stem and bindgen_flags, respectively. This deconflicts with the
usage in baseCompiler.

This also removes 'subName' from the Module struct and moves it over to
SourceProvider, which was the only user. This allows us to set it in
baseSourceProvider's AndroidMk; setting it in Module's AndroidMk was
causing problems finding NOTICE files for bindgen library variants.

Bug: 159064919
Test: New Soong tests pass.
Test: Local test rust_binary can use rust_bindgen module as a crate.

Change-Id: Ieb2cb614c2dd0b5aa7120541d77f6f822a6a1806
2020-08-04 08:13:24 -04:00
Ivan Lozano
45901edb9a Ensure hermetic device rust_bindgen.
rust_bindgen was not hermetic previously as it would pull in host
headers for device targets. This fixes that by using the same flags we
use when compiling with Clang. This also makes sure our rust_bindgen
headers are built as similar as possible to their respective
cc_libraries.

This also pulls in the bionic dependencies as well, which provide the
headers required for device targets.

Bug: 162007475
Test: device rust_bindgen deps file does not reference host headers.

Change-Id: I4efdf333e011a6c6d73a0345e5485823f166d17a
2020-07-28 14:53:57 -04:00
Ivan Lozano
4fef93c53f Add SourceProviders and a rust_bindgen module type
Add SourceProvider modules which provides a base interface for more
complex code generation usecases such as bindgen. Also adds the
rust_bindgen module type which calls bindgen to generate Rust FFI
bindings to C.

Bug: 159064919
Test: Local test module generates bindings.
Test: New Soong tests pass.

Change-Id: Ie31467bbbe423497666ad837cf5fe1acd1e76bd8
2020-07-20 13:40:14 -04:00