Skip to main content

Code generator

Provide parameters to codegen

It is equivalent to provide a parameter using the three approaches below.

Configuration file

The suggested mode to run flutter_rust_bridge_codegen, is to create flutter_rust_bridge.yaml configuration file, and invoke command line without arguments.

All these file names work (though I personally suggest to use flutter_rust_bridge.yaml, because it matches the Flutter convention, the "pubspec.yaml"):

Full name list
  • .flutter_rust_bridge.yml
  • .flutter_rust_bridge.yaml
  • .flutter_rust_bridge.json
  • flutter_rust_bridge.yml
  • flutter_rust_bridge.yaml (suggested)
  • flutter_rust_bridge.json

The flutter_rust_bridge_codegen create/integrate already creates a configuration file for you, which is often sufficient.

The parameter names are the same as the one shown in command line help, except that there are no no_ negations here. You can also refer to the fields of this struct (may need to switch to latest version) for parameter names. Anyway, if a wrong name is provided, it will be immediately recognized and reported.

Command line arguments

For example, suppose you want to provide rust_input argument, then just do --rust-input your_value.

Inside pubspec.yaml

Similarly, if you're calling flutter_rust_bridge_codegen from the root of your Dart project, you can also fill in your config under the flutter_rust_bridge entry in pubspec.yaml:

# put this somewhere in your pubspec.yaml
flutter_rust_bridge:
rust_input: rust/src/api/**/*.rs
dart_output: lib/src/rust
# ...

Explanation of each parameter

Simply add --help to see full documentation. The following is a snapshot when running the command with --help:

flutter_rust_bridge_codegen

High-level memory-safe binding generator for Flutter/Dart <-> Rust

Usage: flutter_rust_bridge_codegen [OPTIONS] <COMMAND>

Commands:
generate Execute the main code generator
create Create a new Flutter + Rust project
integrate Integrate Rust into existing Flutter project
build-web Compile for the Web (WASM)
help Print this message or the help of the given subcommand(s)

Options:
-v, --verbose Show debug messages
-h, --help Print help
-V, --version Print version

flutter_rust_bridge_codegen generate

Execute the main code generator

Usage: flutter_rust_bridge_codegen generate [OPTIONS]

Options:
--watch
Automatically re-generate the output whenever the changes are detected on the input files

--config-file <CONFIG_FILE>
Path to a YAML config file.

If present, other options and flags will be ignored. Accepts the same options as the CLI, but uses snake_case keys.

-r, --rust-input <RUST_INPUT>
Glob pattern of input Rust files

-d, --dart-output <DART_OUTPUT>
Directory of output generated Dart code

-c, --c-output <C_OUTPUT>
Output path of generated C header

--duplicated-c-output <DUPLICATED_C_OUTPUT>
Duplicate the files generated at the location `--c-output` specifies

--rust-root <RUST_ROOT>
Crate directory for your Rust project

--rust-output <RUST_OUTPUT>
Output path of generated Rust code

--dart-entrypoint-class-name <DART_ENTRYPOINT_CLASS_NAME>
Generated dart entrypoint class name

--dart-format-line-length <DART_FORMAT_LINE_LENGTH>
Line length for Dart formatting

--no-dart-enums-style
The generated Dart enums will not have their variant names camelCased

--no-add-mod-to-lib
Skip automatically adding `mod frb_generated;` to `lib.rs`

--llvm-path <LLVM_PATH>...
Path to the installed LLVM

--llvm-compiler-opts <LLVM_COMPILER_OPTS>
LLVM compiler opts

--dart-root <DART_ROOT>...
Path to root of Dart project, otherwise inferred from --dart-output

--no-build-runner
Skip running build_runner even when codegen-required code is detected

--extra-headers <EXTRA_HEADERS>
extra_headers is used to add dependencies header

--no-web
Disable web module generation

--no-deps-check
Skip dependencies check

--default-external-library-loader-web-prefix <DEFAULT_EXTERNAL_LIBRARY_LOADER_WEB_PREFIX>
The value for defaultExternalLibraryLoader.webPrefix

--no-dart3
Disable language features introduced in Dart 3

--full-dep
Enable full dependencies

--dump [<DUMP>...]
A list of data to be dumped. If specified without a value, defaults to all

[possible values: config, source, source-graph, ir, generator-info, generator-spec, generator-text]

--dump-all
Dump all internal data. Same as `--dump` with all possible choices chosen

-h, --help
Print help (see a summary with '-h')

flutter_rust_bridge_codegen build-web

Build for web platform

Usage: flutter_rust_bridge build-web [arguments]
-h, --help Print this usage information.
--dart-root Root folder of dart package
-c, --rust-root Directory of the rust package
(defaults to "rust")
-o, --output=<PKG> Output path
--release Compile in release mode
-v, --[no-]verbose Display more verbose information
--cargo-build-args Arguments passed to cargo-build
--wasm-bindgen-args Arguments passed to wasm-bindgen
--dart-compile-js-entrypoint If specified, compile Dart into JavaScript and use this option as entrypoint

Run "flutter_rust_bridge help" to see global options.

flutter_rust_bridge_codegen create

Create a new Flutter + Rust project

Usage: flutter_rust_bridge_codegen create [OPTIONS] <NAME>

Arguments:
<NAME> Name of the new project

Options:
--org <ORG>
The organization responsible for your new Flutter project, in reverse domain name notation
--rust-crate-name <RUST_CRATE_NAME>
The name of the generated Rust crate
--rust-crate-dir <RUST_CRATE_DIR>
The directory of the generated Rust crate
-h, --help
Print help

flutter_rust_bridge_codegen integrate

Integrate Rust into existing Flutter project

Usage: flutter_rust_bridge_codegen integrate [OPTIONS]

Options:
--no-enable-integration-test Generate code related to integration test
--rust-crate-name <RUST_CRATE_NAME> The name of the generated Rust crate
--rust-crate-dir <RUST_CRATE_DIR> The directory of the generated Rust crate
-h, --help Print help