Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(message): enable usage of the protoc-gen-prost-serde plugin #332

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading