Skip to content

Commit

Permalink
Merge pull request #332 from NeoVance/rinf-serde-serialization-option
Browse files Browse the repository at this point in the history
feat(message): enable usage of the protoc-gen-prost-serde plugin
  • Loading branch information
temeddix committed May 22, 2024
2 parents 62ff156 + bc1776d commit df27952
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions documentation/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions flutter_ffi_plugin/bin/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +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,
rustSerde: DEFAULT_RUST_SERDE,
);
}

Expand All @@ -33,6 +36,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,
);
}

Expand All @@ -47,15 +51,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
];
}

Expand Down Expand Up @@ -110,6 +117,7 @@ rinf:
/// input_dir: messages
/// rust_output_dir: native/hub/src/messages
/// dart_output_dir: lib/messages
/// rust_serde: true
/// ```
Future<RinfConfig> loadVerifiedRinfConfig(String pubspecYamlFile) async {
final pubspec = loadYaml(await File(pubspecYamlFile).readAsString());
Expand Down
2 changes: 2 additions & 0 deletions flutter_ffi_plugin/bin/src/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Future<void> 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());
Expand All @@ -105,6 +106,7 @@ Future<void> 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) {
Expand Down

0 comments on commit df27952

Please sign in to comment.