Skip to content

Commit

Permalink
Support pass extra args to protoc
Browse files Browse the repository at this point in the history
  • Loading branch information
H2Sxxa committed Jul 21, 2024
1 parent 9edc426 commit f65ccbb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions flutter_ffi_plugin/bin/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ class RinfConfigMessage {
final String rustOutputDir;
final String dartOutputDir;
final bool rustSerde;
final List<String> extraArgs;

RinfConfigMessage({
required this.inputDir,
required this.rustOutputDir,
required this.dartOutputDir,
required this.rustSerde,
required this.extraArgs,
});

factory RinfConfigMessage.defaultConfig() {
Expand All @@ -20,6 +22,7 @@ class RinfConfigMessage {
rustOutputDir: DEFAULT_RUST_OUTPUT_DIR,
dartOutputDir: DEFAULT_DART_OUTPUT_DIR,
rustSerde: DEFAULT_RUST_SERDE,
extraArgs: DEFAULT_EXTRA_ARGS,
);
}

Expand All @@ -37,6 +40,7 @@ class RinfConfigMessage {
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,
extraArgs: List.from(yaml[KEY_EXTRA_ARGS]),
);
}

Expand All @@ -46,24 +50,28 @@ class RinfConfigMessage {
$KEY_INPUT_DIR: $inputDir
$KEY_RUST_OUTPUT_DIR: $rustOutputDir
$KEY_DART_OUTPUT_DIR: $dartOutputDir
$KEY_RUST_SERDE: $rustSerde''';
$KEY_RUST_SERDE: $rustSerde
$KEY_EXTRA_ARGS: ${extraArgs.join(" ")}''';
}

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 KEY_EXTRA_ARGS = "extra_args";

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 DEFAULT_EXTRA_ARGS = <String>[];

static const MESSAGE_CONFIG_KEYS = [
KEY_INPUT_DIR,
KEY_RUST_OUTPUT_DIR,
KEY_DART_OUTPUT_DIR,
KEY_RUST_SERDE
KEY_RUST_SERDE,
KEY_EXTRA_ARGS,
];
}

Expand Down
1 change: 1 addition & 0 deletions flutter_ffi_plugin/bin/src/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Future<void> generateMessageCode({
...protoPaths,
'--prost_out=$rustFullPath',
...(messageConfig.rustSerde ? ['--prost-serde_out=$rustFullPath'] : []),
...messageConfig.extraArgs,
...resourceNames.map((name) => '$name.proto'),
]);
if (protocRustResult.exitCode != 0) {
Expand Down

0 comments on commit f65ccbb

Please sign in to comment.