Commit graph

29 commits

Author SHA1 Message Date
Colin Cross
f526863a40 Shard rust protobuf sources
Shorten the command line for generating rust protobuf sources
by sharding the sources into groups of 50 source files.

Bug: 322564768
Bug: 336323108
Test: builds
Change-Id: Ia8069cdaf49f9a42d14a83139545ba61277418e0
2024-04-23 10:47:00 -07:00
Ludovic Barman
78b2519e19 Remove unused use_protobuf3 flag
This is a No-op.
Protobuf3 is used regardless of this flag since https://android-review.git.corp.google.com/c/platform/build/soong/+/2817733

Test: m rust

Bug: 308790516
Change-Id: I1bfbca5d8a30e4e10f03e4e045d6c6ceddb30c87
2023-12-21 17:53:51 +00:00
Colin Cross
51428c451a Merge changes I6f116385,Id77f514d,I73479de1,If58f4b53 into main
* changes:
  Convert ModuleProvder to generic providers API
  Convert OtherModuleProvider to generic providers API
  Convert Provider to generic providers API
  Convert SetProvider to generic providers API
2023-12-18 22:43:45 +00:00
Ludovic Barman
19739bf6a5 Rust protobuf 2->3: Update build system
tldr: remove protobuf2 from Android Rust and upgrade everything to pb3.

These commits update:
- The grpcio rust crate to use protobuf 3
- The build system to always use the new libprotobuf (pb3) instead of the _deprecated variant (for pb2); they also force-enable libprotobuf everywhere, ignoring the use_protobuf3 flag, removes the tests related to pb2
- The following modules, which required syntax changes:
-- packages/modules/Bluetooth
-- device/google/cuttlefish
-- vendor/auto

Bug: 308790516
Test: m rust
Ignore-AOSP-First: must be done in main to upgrade cuttlefish+vendor with the rest all at once
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:7d0783ce22b3d7d369786d4b16067c79c033185b)
Merged-In: I1d07c433aca41ccfe2e710821cf930c413dc12d6

Change-Id: I1d07c433aca41ccfe2e710821cf930c413dc12d6
2023-12-15 13:23:33 +00:00
Colin Cross
402130276c Convert SetProvider to generic providers API
Convert all of the callers of SetProvider to use the type-safe
android.SetProvider API.

Bug: 316410648
Test: builds
Change-Id: If58f4b5355264ddab2045bc3591a4eac19cd58fc
2023-12-14 16:12:20 -08:00
Colin Cross
8ff105860d Remove ConvertWithBp2build implementations
Remove the ConvertWithBp2build implementations from all the module
types, along with the related code.

Bug: 315353489
Test: m blueprint_tests
Change-Id: I212672286686a318893bc7348ddd5a5ec51e77a7
2023-12-08 13:51:05 -08:00
Ivan Lozano
d106efe76d rust: Import protos from dependent rust_protobuf
rust_protobuf were unable to import protos from other rust_protobuf
modules. This CL adds support for that. rust_protobuf modules which are
listed in rustlibs will have their modules imported into the generated
protobuf stub. Additionally, rust_protobuf modules which define
"exported_include_dirs" will export those include paths to dependent
rust_protobuf modules.

Bug: 301266700
Test: m rust
Change-Id: I132edffa4d77e0ac80a7ac934f873374c8e94c1b
2023-09-27 20:53:54 -04:00
Vinh Tran
47faaad254 Add bp2build for rust_protobuf module
We only supported bp2build for rust_protobuf_host because the non-host toolchain for rust is not checked in yet. aosp/2759750 changed a converted module from rust_protobuf_host to rust_protobuf and broke CI.

This CL adds bp2build support for rust_protobuf but makes the target incompatible with android os for now untilnon-host rust toolchain is checked in.

Bug: 301956497
Test: b build //build/make/tools/aconfig:all --config=android
Change-Id: I739896c79f32674000c2603e394f16860a6fc57d
2023-09-25 17:37:59 -04:00
Chris Parsons
637458d326 Have ConvertWBp2build use Bp2buildMutatorContext
This no-op refactoring facilitates some upcoming functional changes for
"bp2build allowlist v2". The work requires that the bp2build conversion
mutator be changed from a TopDown mutator to a BottomUp mutator.
Refactoring all bp2build-related methods so that they use Bp2buildMutatorContext
makes it easier to make this functional change without touching tens of
files and multiple projects.

Bug: 285631638
Test: m bp2build
Change-Id: I3d1ef3064146e959c6f0dc315350fc9764bf2bd2
2023-09-20 14:49:35 +00:00
Vinh Tran
0c4b9ec5e0 Implement bp2build converter for rust_protobuf_host
Test: go test
Bug: 295925256
Change-Id: I43b7359da8fc19f4338e2583448b7617194df5e6
2023-08-25 18:00:33 -04:00
Vinh Tran
4eeb2a9514 Remove dylibs prop from rust module types
For device build, rust defaults to dylib linkage for rustlibs deps. `dylibs` prop was provided for flexibility.

By removing it, we're enforcing users to either use the default linkage (dylibs for device and rlibs for host) or rlibs prop explicitly. This means no dylibs for host modules. This makes sense because host modules always uses rlib linkage against libstd. The flexibility with dylibs prop opened room for linkage collisions because the dependencies don't link against libstd the same way.

Test: go test
Change-Id: I2fc221daa8a9bb42bdcf6d9823c723a4ddabe7b5
2023-08-14 14:03:28 -04:00
Jeff Vander Stoep
c1490ec25e Add option to use protobuf3
Users of the rust_protobuf module can use the 'use_protobuf3'
option to select version 3 of the protobuf crate instead of the
current default of version 2. This unblocks teams that would like
to use protobuf 3 immediately and provides a mechanism for us to
incrementally migrate users of protobuf 2 to protobuf 3.

Test: Adds tests that are executed during every build.
Bug: 270895633
Change-Id: Ib6a18b77cfa7dc3cc604cea05269004b3712bbb6
2023-04-24 11:33:50 +02:00
Jeff Vander Stoep
91c0466094 rust_proto: use protobuf crate version 2.x
Test: build
Bug: 270895633
Change-Id: I04e5e7fe70b8c509cd1b35852b75a0f24a633ce9
2023-03-24 09:32:36 +01:00
Matthew Maurer
e94f3e73dd Revert^4 "rust: Only allow bindgen to produce rlibs."
199c188502

Change-Id: I28b353fa89354cc572806b2274169342a473a03c
2022-08-10 20:25:50 +00:00
Matthew Maurer
199c188502 Revert^3 "rust: Only allow bindgen to produce rlibs."
9cc801ab7a

Change-Id: Ib59840b51b316c0ad03bc66565814dd96be0b072
2022-08-02 23:26:16 +00:00
Matthew Maurer
9cc801ab7a Revert^2 "rust: Only allow bindgen to produce rlibs."
b983c8971b

Change-Id: Ic82433885f7932be8cfe65433330527214807684
2022-08-02 16:57:30 +00:00
Matthew Maurer
b983c8971b Revert "rust: Only allow bindgen to produce rlibs."
This reverts commit 53a452d1ff.

Reason for revert: Broken build

Change-Id: I4c1c6f2166c3729ef1916ad7c21e32599c5e692f
2022-08-01 21:59:00 +00:00
Matthew Maurer
53a452d1ff rust: Only allow bindgen to produce rlibs.
Generated bindings are intended to be slim translation layers, usually
consisting of nothing more than type signatures and constants.
Generally, they should also be used in exactly one location by the safe
wrapper for these bindings. By preventing them from building as
`dylib`s, we avoid the per-library overhead of these non-reused pieces
of code.

Additionally, default visibility restrict all bindgen modules to their
subpackages. This is being done both:
* to encourage use of a single safe bindings crate
* to avoid diamond dependency graphs with mixed rlib/dylib dependencies

Bug: 166332519
Test: m; Make sample module use dylib bindgen dependency, see build failure.
Change-Id: I8e9d9cb851c2ec99f4ed63e6e18c4ba26b29721c
2022-08-01 16:28:51 +00:00
David Duarte
b6be48d6c9 rust: Support protobuf wrappers well known types
Test: m nothing

Change-Id: I271474f59745670cbba98704182d0966eae6b0ee
2022-01-04 08:52:45 +00:00
Ivan Lozano
6eff900b67 Merge rust_protobuf and rust_grpcio module types.
To allow grpc protobufs to include non-grpc protos in a singular
library, we need to allow them to be defined as part of the same module.

This CL merges the two previously distinct module types into
rust_protobuf, and adds a new property for declaring which protos
contain grpc definitions.

Bug: 172952239
Test: rust_grpcio modules converted to rust_protobuf modules and build.
Test: Example rust_protobuf module with both proto types builds.
Change-Id: I0e627fd97bc6f74de89d309e3344694a1e76586d
2020-12-11 16:19:02 -05:00
Ivan Lozano
9d74a52706 Rust: WriteFileRule instead of printf for protos
Use WriteFileRule instead of a rule that calls printf for generating the
module source file for rust_protobuf.

Bug: 171361369
Test: rust_protobuf modules compile
Change-Id: Ie83a30e19d7d09875f3d209662526783862d8ea0
2020-12-10 15:35:05 -05:00
Colin Cross
f1a035e6be Pass pctx and ctx to NewRuleBuilder
Enable the RuleBuilder and RuleBuilderCommand methods to access
the BuilderContext by passing it to NewRuleBuilder instead of
RuleBuilder.Build.

Test: genrule_test.go
Test: rule_builder_test.go
Test: m checkbuild
Change-Id: I63e6597e19167393876dc2259d6f521363b7dabc
2020-12-01 16:22:16 -08:00
Ivan Lozano
57f434e858 rust: Add support for multiple protos per module.
This further emulates the rust-protobuf gen_mod_rs flag by providing
support for generating a single module containing multiple protobuf
definitions.

Bug: 171361369
Test: New Soong tests.
Test: Example module containing multiple protos works.
Change-Id: I815f9628a8289ae512758073dac49bc4535abf01
2020-11-30 14:55:00 +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
Zach Johnson
3df4e6364b rust_grpcio well known types support, default deps
The usage of the well known type Empty requires a hack in the module
above the grpc implementation, this is now the generated stem_mod.rs

This also adds additional implicit dependencies that are required by
the grpc protobuf generated code. This includes the addition of a
'header_libs' property for library dependencies which export include
paths required by protos.

We also now include both the protos and the grpcio in the library
variant via the mod_stem.rs.

Bug: 172592789
Bug: 171504899
Test: m nothing
Test: Example rust_grpcio module build command includes dependencies,
      include paths.
Change-Id: I187a13cd5cdea991828a1020314de16727e4f74e
2020-11-11 12:09:26 -08:00
Matthew Maurer
5819e58fdc rust: Fix GRPC generator invocation
When using the grpc generator, the plugin expects to also have access to
the protobuf generator. This patch ensures that aprotoc will use the
Soong copy of the protobuf generator, rather than trying to use a
locally installed version from PATH.

Test: m nothing
Change-Id: I26da4d18c97017da7d8cd9515a07a2b7b2575342
2020-11-06 01:40:41 +00:00
Ivan Lozano
6a3d1e9831 Add rust_grpcio module type.
Adds a new SourceProvider type to generate grpcio code from protos.
Since it's so similar to protobuf, it's basically just a different type
of rust_protobuf.

Bug: 171504899
Test: Example module compiles.
Change-Id: I9882f3ac4d4aeaae0191f2b557e9612b5c7a9ac9
2020-11-05 08:53:52 -05:00
Chih-Hung Hsieh
c49649c059 Use protobuf-codegen default and add mod_stem.rs
* Upgrade to new protobuf-codegen; use its standard
  default output without local change.
* Allow a sourceProvider to have multiple output files.
  For a stem.proto file, output stem.rs and mod_stem.rs.
* New protobuf-codegen option gen_mod_rs always generates
  output file named "mod.rs". To generate multiple .proto
  files into the same output directory, we need to rename
  mod.rs to mod_<stem>.rs.
* Instead of using the gen_mod_rs option and renaming mod.rs
  to mod_<stem>.rs, we generate the same mod_<stem>.rs
  directly with a simple printf command.

Bug: 170256643
Test: atest -c --host --include-subdirs external/crosvm
Change-Id: Ia09e41029099a6de4d35c96dbabd9ba5514c9019
2020-10-09 13:38:37 -07:00
Treehugger Robot
588aae727b Add rust_protobuf module.
This adds a new SourceProvider module type to handle protobuf code
generation. See the new test for an example of how to call this.

Bug: 143953733
Test: New soong tests pass.
Test: Replacing genrules in crosvm with rust_protobuf modules.
Change-Id: Ie3117129cde37b8736bc18ee09bf5cde27c01c34
2020-08-31 14:05:39 -04:00