aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Barman <ludovicb@google.com>2023-11-04 15:13:59 +0000
committerLudovic Barman <ludovicb@google.com>2023-12-11 09:44:07 +0000
commit5127bb1f9bffe0bc7c1f2572659b9b2b23ccc256 (patch)
tree6ff75f6c9619217311c95c939af05f5f22b69bf9
parentbd72be9c136572316476b1d29b82f171ff9f307c (diff)
downloadgrpcio-5127bb1f9bffe0bc7c1f2572659b9b2b23ccc256.tar.gz
Rust protobuf 2->3: Update grpcio rust crate
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 Note: we have to patch lib.rs to rename the imported crate "protobuf" into "protobufv3" as done by Cargo.toml, but not yet supported in Soong (b/308790322). 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:21e501d290225560655acc48237ad8f47309903a) Merged-In: I7c9494eb48c41e75e51382dfa40ee682ed3c3a7d Change-Id: I7c9494eb48c41e75e51382dfa40ee682ed3c3a7d
-rw-r--r--Android.bp12
-rw-r--r--cargo2android.json6
-rw-r--r--cargo2android_cfgs.bp5
-rw-r--r--patches/lib.rs17
-rw-r--r--src/lib.rs6
5 files changed, 39 insertions, 7 deletions
diff --git a/Android.bp b/Android.bp
index 2fb65f0..8ea87cb 100644
--- a/Android.bp
+++ b/Android.bp
@@ -29,8 +29,8 @@ rust_library {
features: [
"_secure",
"boringssl",
- "protobuf",
- "protobuf-codec",
+ "protobufv3",
+ "protobufv3-codec",
],
rustlibs: [
"libfutures_executor",
@@ -39,11 +39,17 @@ rust_library {
"liblibc",
"liblog_rust",
"libparking_lot",
- "libprotobuf_deprecated",
+ "libprotobuf",
],
apex_available: [
"//apex_available:platform",
],
vendor_available: true,
min_sdk_version: "29",
+ cfgs: [
+ // cfg(soong) is used to distinguish code that only builds on Android, so
+ // that (most of) the same code can be built under both Soong and cargo.
+ "soong",
+ ]
+ ,
}
diff --git a/cargo2android.json b/cargo2android.json
index bc4594d..c908dd9 100644
--- a/cargo2android.json
+++ b/cargo2android.json
@@ -3,12 +3,10 @@
"//apex_available:platform"
],
"device": true,
- "features": "_secure,boringssl,protobuf-codec,protobuf",
+ "features": "_secure,boringssl,protobufv3-codec",
"min-sdk-version": "29",
"run": true,
"vendor-available": true,
"product-available": false,
- "dep-suffixes": {
- "protobuf": "_deprecated"
- }
+ "add-module-block": "cargo2android_cfgs.bp"
}
diff --git a/cargo2android_cfgs.bp b/cargo2android_cfgs.bp
new file mode 100644
index 0000000..328d17d
--- /dev/null
+++ b/cargo2android_cfgs.bp
@@ -0,0 +1,5 @@
+cfgs: [
+ // cfg(soong) is used to distinguish code that only builds on Android, so
+ // that (most of) the same code can be built under both Soong and cargo.
+ "soong",
+]
diff --git a/patches/lib.rs b/patches/lib.rs
new file mode 100644
index 0000000..0a1d2e9
--- /dev/null
+++ b/patches/lib.rs
@@ -0,0 +1,17 @@
+diff --git a/src/lib.rs b/src/lib.rs
+index c8cebca..ba47f95 100644
+--- a/src/lib.rs
++++ b/src/lib.rs
+@@ -29,6 +29,12 @@ use grpcio_sys as grpc_sys;
+ #[macro_use]
+ extern crate log;
+
++// grpcio with feature protobufv3-codec expects a "protobufv3" dependency,
++// but Android.bp is not able to rename dependencies yet. See b/308790322.
++// It is enabled unconditionally since protobufv3-codec also is.
++#[cfg(soong)]
++extern crate protobuf as protobufv3;
++
+ mod buf;
+ mod call;
+ mod channel;
diff --git a/src/lib.rs b/src/lib.rs
index c8cebca..ba47f95 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -29,6 +29,12 @@ use grpcio_sys as grpc_sys;
#[macro_use]
extern crate log;
+// grpcio with feature protobufv3-codec expects a "protobufv3" dependency,
+// but Android.bp is not able to rename dependencies yet. See b/308790322.
+// It is enabled unconditionally since protobufv3-codec also is.
+#[cfg(soong)]
+extern crate protobuf as protobufv3;
+
mod buf;
mod call;
mod channel;