From ec271c094824b4a2af9ab358b495793ac83ded45 Mon Sep 17 00:00:00 2001 From: Devon Bagley Date: Tue, 21 May 2024 12:19:41 -0700 Subject: [PATCH 1/3] feat(message): enable usage of the protoc-gen-prost-serde plugin --- flutter_ffi_plugin/bin/src/config.dart | 14 ++++++++++---- flutter_ffi_plugin/bin/src/message.dart | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/flutter_ffi_plugin/bin/src/config.dart b/flutter_ffi_plugin/bin/src/config.dart index 146736ae..9a29ff46 100644 --- a/flutter_ffi_plugin/bin/src/config.dart +++ b/flutter_ffi_plugin/bin/src/config.dart @@ -5,19 +5,21 @@ class RinfConfigMessage { final String inputDir; final String rustOutputDir; final String dartOutputDir; + final bool rustSerde; RinfConfigMessage({ required this.inputDir, required this.rustOutputDir, required this.dartOutputDir, + required this.rustSerde, }); factory RinfConfigMessage.defaultConfig() { return RinfConfigMessage( - inputDir: DEFAULT_INPUT_DIR, - rustOutputDir: DEFAULT_RUST_OUTPUT_DIR, - dartOutputDir: DEFAULT_DART_OUTPUT_DIR, - ); + inputDir: DEFAULT_INPUT_DIR, + rustOutputDir: DEFAULT_RUST_OUTPUT_DIR, + dartOutputDir: DEFAULT_DART_OUTPUT_DIR, + rustSerde: DEFAULT_RUST_SERDE); } factory RinfConfigMessage.from(YamlMap yaml) { @@ -33,6 +35,7 @@ class RinfConfigMessage { inputDir: yaml[KEY_INPUT_DIR] ?? DEFAULT_INPUT_DIR, rustOutputDir: yaml[KEY_RUST_OUTPUT_DIR] ?? DEFAULT_RUST_OUTPUT_DIR, dartOutputDir: yaml[KEY_DART_OUTPUT_DIR] ?? DEFAULT_DART_OUTPUT_DIR, + rustSerde: yaml[KEY_RUST_SERDE] ?? DEFAULT_RUST_SERDE, ); } @@ -47,15 +50,18 @@ class RinfConfigMessage { static const KEY_INPUT_DIR = "input_dir"; static const KEY_RUST_OUTPUT_DIR = "rust_output_dir"; static const KEY_DART_OUTPUT_DIR = "dart_output_dir"; + static const KEY_RUST_SERDE = "rust_serde"; static const DEFAULT_INPUT_DIR = "messages/"; static const DEFAULT_RUST_OUTPUT_DIR = "native/hub/src/messages/"; static const DEFAULT_DART_OUTPUT_DIR = "lib/messages/"; + static const DEFAULT_RUST_SERDE = false; static const MESSAGE_CONFIG_KEYS = [ KEY_INPUT_DIR, KEY_RUST_OUTPUT_DIR, KEY_DART_OUTPUT_DIR, + KEY_RUST_SERDE ]; } diff --git a/flutter_ffi_plugin/bin/src/message.dart b/flutter_ffi_plugin/bin/src/message.dart index 30cec94a..4eef4626 100644 --- a/flutter_ffi_plugin/bin/src/message.dart +++ b/flutter_ffi_plugin/bin/src/message.dart @@ -83,6 +83,7 @@ Future generateMessageCode({ final cargoInstallCommand = await Process.run('cargo', [ 'install', 'protoc-gen-prost', + ...(messageConfig.rustSerde ? ['protoc-gen-prost-serde'] : []) ]); if (cargoInstallCommand.exitCode != 0) { print(cargoInstallCommand.stderr.toString().trim()); @@ -105,6 +106,7 @@ Future generateMessageCode({ final protocRustResult = await Process.run('protoc', [ ...protoPaths, '--prost_out=$rustFullPath', + ...(messageConfig.rustSerde ? ['--prost-serde_out=$rustFullPath'] : []), ...resourceNames.map((name) => '$name.proto'), ]); if (protocRustResult.exitCode != 0) { From abe2706b777e6e43fb12f354b9b745016618975f Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Thu, 23 May 2024 00:27:50 +0900 Subject: [PATCH 2/3] Improve formatting --- flutter_ffi_plugin/bin/src/config.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/flutter_ffi_plugin/bin/src/config.dart b/flutter_ffi_plugin/bin/src/config.dart index 9a29ff46..c197456b 100644 --- a/flutter_ffi_plugin/bin/src/config.dart +++ b/flutter_ffi_plugin/bin/src/config.dart @@ -16,10 +16,11 @@ class RinfConfigMessage { factory RinfConfigMessage.defaultConfig() { return RinfConfigMessage( - inputDir: DEFAULT_INPUT_DIR, - rustOutputDir: DEFAULT_RUST_OUTPUT_DIR, - dartOutputDir: DEFAULT_DART_OUTPUT_DIR, - rustSerde: DEFAULT_RUST_SERDE); + inputDir: DEFAULT_INPUT_DIR, + rustOutputDir: DEFAULT_RUST_OUTPUT_DIR, + dartOutputDir: DEFAULT_DART_OUTPUT_DIR, + rustSerde: DEFAULT_RUST_SERDE, + ); } factory RinfConfigMessage.from(YamlMap yaml) { From bc1776d0438fb04188e9274ed6eefcd17a4fef18 Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Thu, 23 May 2024 00:32:26 +0900 Subject: [PATCH 3/3] Update docs and comments --- documentation/docs/configuration.md | 1 + flutter_ffi_plugin/bin/src/config.dart | 1 + 2 files changed, 2 insertions(+) diff --git a/documentation/docs/configuration.md b/documentation/docs/configuration.md index f53e2fa9..9ed7b433 100644 --- a/documentation/docs/configuration.md +++ b/documentation/docs/configuration.md @@ -8,6 +8,7 @@ rinf: input_dir: messages/ rust_output_dir: native/hub/src/messages/ dart_output_dir: lib/messages/ + rust_serde: true ``` You can check the current configuration status by running the command below in the CLI. diff --git a/flutter_ffi_plugin/bin/src/config.dart b/flutter_ffi_plugin/bin/src/config.dart index c197456b..1ce18098 100644 --- a/flutter_ffi_plugin/bin/src/config.dart +++ b/flutter_ffi_plugin/bin/src/config.dart @@ -117,6 +117,7 @@ rinf: /// input_dir: messages /// rust_output_dir: native/hub/src/messages /// dart_output_dir: lib/messages +/// rust_serde: true /// ``` Future loadVerifiedRinfConfig(String pubspecYamlFile) async { final pubspec = loadYaml(await File(pubspecYamlFile).readAsString());