Skip to content

Commit

Permalink
feat(message): enable usage of the protoc-gen-prost-serde plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoVance committed May 21, 2024
1 parent e6fd600 commit ec271c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions flutter_ffi_plugin/bin/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
);
}

Expand All @@ -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
];
}

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 ec271c0

Please sign in to comment.