Description
Change intent
(edit: Updated 2024-01-24 to reflect use of the hook/
toplevel directory.)
A package toplevel hook/
directory will be reserved for scripts run by the Dart and Flutter SDK at specific lifecycle events with a specific commandline API.
Examples:
hook/build.dart
will be run before kernel compilation of Dart packages.hook/link.dart
will be run after kernel compilation of Dart packages, before making an application bundle.
If these scripts exist, they will be invoked by the Dart and Flutter build systems.
If these scripts exist, they must implement the commandline API.
For more context:
For more
Justification
Other languages standardize on a top level build script that builds code in other languages.
Most notably Rust defines a top level build.rs
in packages to build native non-Rust code.
Reasoning for using hook/build.dart
and hook/link.dart
in Dart.
- A Dart package public surface is the
lib/
andbin/
directory. But build scripts should not be part of the programmatic or CLI API of a package. - A package private scripts reside in
tool/
. But build scripts should be run from the context outside that package itself. - The
build/
directory is already reserved in Flutter. So nesting the build script inside thebuild/
directory doesn't work.
Alternatives considered
- toplevel
build.dart
andlink.dart
. Rejected because we might want more scripts. - toplevel
build_assets.dart
andlink_assets.dart
. Rejected because of longer names. - [native_assets][ffi] Make
build.dart
path configurable #54111
Impact
Anyone using a top level hook/
directory will need to migrate to a different file name.
We are aware of one use:
Mitigation
Migrate existing uses of hook/
to tool/
, which is probably what those scripts are.
Action items after accepting proposal:
Metadata
Metadata
Assignees
Labels
Type
Projects
Status