Public API for Flutter build rules
load("@rules_flutter//flutter:defs.bzl", "dart_format_test")
dart_format_test(name, srcs)
Fails when any of the given Dart sources are not dart-format clean.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| srcs | Dart sources checked with dart format --set-exit-if-changed. |
List of labels | required |
load("@rules_flutter//flutter:defs.bzl", "dart_proto_library")
dart_proto_library(name, deps)
Generates Dart sources from proto_library targets using the Dart protoc plugin.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | proto_library targets to generate Dart for. Generation covers the whole transitive proto closure (including well-known types such as google/protobuf/timestamp), matching what generated imports expect. | List of labels | required |
load("@rules_flutter//flutter:defs.bzl", "flutter_analyze_test")
flutter_analyze_test(name, srcs, cpu, embed, extra_args, fatal_infos, fatal_warnings,
pub_cache_materialization)
Runs flutter analyze hermetically against a prepared flutter_library workspace.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| srcs | Additional files overlaid before analyzing (e.g. analysis_options.yaml, test sources). | List of labels | optional | [] |
| cpu | Local CPUs to reserve for this test (execution requirement cpu:N); see flutter_test.cpu. 0 (default) declares nothing. |
Integer | optional | 0 |
| embed | flutter_library targets whose prepared workspace is analyzed. | List of labels | optional | [] |
| extra_args | Additional arguments forwarded to flutter analyze. | List of strings | optional | [] |
| fatal_infos | Treat info-level issues as fatal (--fatal-infos). | Boolean | optional | False |
| fatal_warnings | Treat warnings as fatal; set False to pass --no-fatal-warnings. | Boolean | optional | True |
| pub_cache_materialization | How the analyze run materializes the pub cache; see flutter_test.pub_cache_materialization. | String | optional | "auto" |
load("@rules_flutter//flutter:defs.bzl", "flutter_goldens")
flutter_goldens(name, srcs, embed, jobs, test_files, test_tags)
Regenerates Flutter golden images hermetically and writes them back to the source tree.
The build action runs flutter test --tags <test_tags> --update-goldens --run-skipped inside a prepared workspace (dart_proto_library trees and other
generated_srcs already mounted, so no source-tree pre-population/refresh is
required) and captures the produced **/goldens/** PNG trees as a declared
output — so an unchanged embed/test/lib graph is a cache hit and re-renders
nothing. bazel run copies the (cached) goldens back into the source tree for
review and commit.
By default it runs only golden-tagged tests (test_tags = ["golden"]), so a
golden-test failure fails the action but it is NOT a general widget-test gate —
keep a separate flutter_test target for that. The scoping is deliberate:
--run-skipped un-skips tests, and limiting it to the golden tag ensures tests
that are skip: true for unrelated reasons are never run. Set test_tags = []
to run every test under test_files (only safe when golden is the sole skip).
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| srcs | Test sources (including golden tests) to overlay into the workspace. | List of labels | optional | [] |
| embed | flutter_library target to embed (exactly one). | List of labels | optional | [] |
| jobs | Concurrency for flutter test -j (0 = flutter's default). |
Integer | optional | 0 |
| test_files | Test files or directories whose golden tests to (re)generate. Also bounds the write-back's clear step: only goldens under these roots are cleared before restoring the regenerated set. | List of strings | optional | ["test/"] |
| test_tags | Tags passed to flutter test --tags, scoping --run-skipped. Defaults to ["golden"] so only golden-tagged tests are un-skipped and rendered — a test that is skip: true for an unrelated reason (parked/flaky/platform) is never run. Set to [] to run every test under test_files (unscoped --run-skipped; only safe when golden is the sole skip). |
List of strings | optional | ["golden"] |
load("@rules_flutter//flutter:defs.bzl", "flutter_test")
flutter_test(name, srcs, cpu, embed, jobs, pub_cache_materialization, test_files)
Runs Flutter tests using a prepared flutter_library workspace.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| srcs | Test source files to copy into the runtime workspace. | List of labels | optional | [] |
| cpu | Local CPUs to reserve for this test (execution requirement cpu:N). 0 (default) declares nothing. Only useful together with jobs/sharding on large workers — reserving cores where none are spare just serializes tests that would otherwise overlap. |
Integer | optional | 0 |
| embed | flutter_library targets to embed for testing. | List of labels | optional | [] |
| jobs | Concurrency passed to flutter test -j. 0 (default) keeps flutter's own default (the number of cores). Cap this when several flutter_test targets run concurrently on one worker so their internal parallelism doesn't oversubscribe it. |
Integer | optional | 0 |
| pub_cache_materialization | How the test materializes the (multi-GB) pub cache at run time. auto (default) APFS-clones it on macOS (fresh copy-on-write inodes, kept writable) and byte-copies elsewhere — behaviorally identical to copy everywhere. copy forces the historical byte copy. hardlink opts into linking the dereferenced files (near-instant, but the links share inodes with the Bazel-owned tree and stay read-only; falls back to a copy when linking isn't possible). reference skips materialization entirely and points the regenerated package config into the Bazel-provided cache read-only. |
String | optional | "auto" |
| test_files | Test files or directories to run | List of strings | optional | ["test/"] |
load("@rules_flutter//flutter:defs.bzl", "DartLibraryInfo")
DartLibraryInfo(srcs, deps, import_path, pubspec, pub_deps, pub_cache, transitive_pub_caches,
assembled_cache)
Information about a Dart library
FIELDS
load("@rules_flutter//flutter:defs.bzl", "DartProtoAspectInfo")
DartProtoAspectInfo(trees)
Internal: per-proto_library Dart generation results, propagated along deps.
FIELDS
| Name | Description |
|---|---|
| trees | Depset of tree artifacts laid out by proto import path. |
load("@rules_flutter//flutter:defs.bzl", "DartProtoLibraryInfo")
DartProtoLibraryInfo(sources)
Generated Dart sources produced from .proto files.
FIELDS
load("@rules_flutter//flutter:defs.bzl", "FlutterLibraryInfo")
FlutterLibraryInfo(workspace, pub_get_log, pub_cache, pub_deps, dart_tool, pubspec, dart_sources,
other_sources, transitive_pub_caches, assembled_cache)
Outputs from flutter_library needed to build or test Flutter targets.
FIELDS
load("@rules_flutter//flutter:defs.bzl", "dart_library")
dart_library(name, create_update_target, create_format_target, create_sync_target,
update_visibility, update_tags, **kwargs)
Defines a dart_library target and optional .update/.format helpers.
PARAMETERS
load("@rules_flutter//flutter:defs.bzl", "flutter_app")
flutter_app(*, name, embed, srcs, visibility, tags, testonly, dart_defines, build_args, mode, env,
android_sdk, android_ndk, create_dev_target, dev_run_args, web, apk, appbundle, ios,
macos, linux, windows)
Macro that defines flutter_app platform targets.
Each platform attribute (web, apk, ios, macos, linux, windows) accepts
either labels for files that should be overlaid into the Flutter workspace when
building for that platform, or a dict spec with any of the keys srcs,
dart_defines, build_args, mode, env, android_sdk, android_ndk,
android_test, build_name, build_number, and tags to customize that
platform's build. A target is emitted only when the corresponding attribute
is provided. Spec tags extend the macro-level tags (e.g. to mark only
the mobile platforms manual).
Common dart_defines/build_args/mode/env apply to every platform;
per-platform values merge over them (build_args concatenates, dicts merge
with platform keys winning, mode overrides).
PARAMETERS
load("@rules_flutter//flutter:defs.bzl", "flutter_build_settings")
flutter_build_settings(name, mode_default, build_number, visibility)
Emit the command-line build settings a release/multi-env app needs.
flutter_app's mode and build_number are plain attributes meant to be
driven by select() on user build settings. This macro creates the usual
scaffolding so you don't hand-roll it:
{name}_mode: a string_flag over debug/profile/release (defaultmode_default), plus a{name}_<mode>config_setting for each mode.{name}_build_number: a string_flag (default empty) whenbuild_numberis True, so a release wrapper can inject a version code on the command line instead of rewriting pubspec.yaml.
Wire them into flutter_app, e.g.:
flutter_app(
name = "app",
apk = {
"srcs": [":android_srcs"],
"mode": select({
":settings_release": "release",
"//conditions:default": "debug",
}),
"build_number": ":settings_build_number",
"android_sdk": "@androidsdk//:sdk_path",
},
...
)
then build with --//your/pkg:settings_mode=release --//your/pkg:settings_build_number=42.
PARAMETERS
load("@rules_flutter//flutter:defs.bzl", "flutter_library")
flutter_library(name, create_update_target, create_format_target, create_sync_target,
update_visibility, update_tags, **kwargs)
Defines a flutter_library target and optional .update/.format helpers.
PARAMETERS