Skip to content

[flutter_hook_config] Add the flutter_hook_config package#11701

Open
bdero wants to merge 1 commit into
flutter:mainfrom
bdero:bdero/flutter-hook-config
Open

[flutter_hook_config] Add the flutter_hook_config package#11701
bdero wants to merge 1 commit into
flutter:mainfrom
bdero:bdero/flutter-hook-config

Conversation

@bdero
Copy link
Copy Markdown
Member

@bdero bdero commented May 13, 2026

Towards flutter/flutter#186299

This came out of an exchange with @dcharkes here: flutter/flutter#186300 (comment)

Adds flutter_hook_config, a package:hooks protocol extension owned by Flutter.

The intent: flutter_tools constructs a FlutterExtension and passes it to every build and link hook invocation, populating it with engine host-tool paths resolved through Artifacts.getHostArtifact (so the --local-engine override applies, same as for flutter_tools' own build steps). Build hooks then read those paths through a typed accessor instead of re-deriving them by walking the SDK cache directory, which is what packages like flutter_gpu_shaders do today (and which misses --local-engine).

What a Flutter build hook looks like with it:

import 'package:flutter_hook_config/flutter_hook_config.dart';
import 'package:hooks/hooks.dart';

void main(List<String> args) async {
  await build(args, (input, output) async {
    if (input.config.buildForFlutter) {
      final impellerc = input.config.flutter.impellerc; // absolute Uri
      // ... invoke impellerc to compile a shader bundle ...
    } else {
      // Plain `dart` build, or a Flutter SDK without this extension:
      // fall back to the hook's own tool discovery.
    }
  });
}

v1 exposes impellerc and libtessellator; more host artifacts can be added later as null-checked fields. Pure Dart, depends on hooks: ^1.0.0, starts at 0.1.0 while the shape stabilizes. The flutter_tools side lands in a separate flutter/flutter PR and depends on this being published first.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 13, 2026
Comment thread .github/labeler.yml
- any-glob-to-any-file:
- packages/file_selector/**/*

'p: flutter_hook_config':
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: label needs to be created

@bdero
Copy link
Copy Markdown
Member Author

bdero commented May 13, 2026

Note for shipping this: flutter_hook_config is a brand-new package, so on its first publish the release workflow will publish it under the bot publisher account rather than the flutter.dev verified publisher. Someone on the Flutter team with publisher-account access will need to do the one-time transfer from the package's Admin tab on pub.dev afterward (per the packages release process docs; access is tracked internally at b/191674407). Happy to coordinate in #hackers-ecosystem.

Also flagging: the top-level README.md row and the issue_tracker URL reference pub.dev/packages/flutter_hook_config and the flutter/flutter label p: flutter_hook_config, neither of which exists yet, so the badges/links will 404 until the package publishes and the label is created.

@bdero bdero force-pushed the bdero/flutter-hook-config branch from 8af09f1 to fa73758 Compare May 13, 2026 02:27
@github-actions github-actions Bot removed the CICD Run CI/CD label May 13, 2026
@bdero bdero force-pushed the bdero/flutter-hook-config branch from fa73758 to e4b62e5 Compare May 13, 2026 02:27
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 13, 2026
#
# Name/Organization <email address>

Google Inc.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this following the template of other new packages. I assume this is correct but not 100% sure. I'm CLA signed of course, but I no longer work at Google.

@bdero bdero force-pushed the bdero/flutter-hook-config branch from e4b62e5 to e9f14eb Compare May 13, 2026 02:40
@github-actions github-actions Bot removed the CICD Run CI/CD label May 13, 2026
@bdero bdero added the CICD Run CI/CD label May 13, 2026
@bdero bdero force-pushed the bdero/flutter-hook-config branch from e9f14eb to 0264309 Compare May 13, 2026 02:59
@github-actions github-actions Bot removed the CICD Run CI/CD label May 13, 2026
@bdero bdero force-pushed the bdero/flutter-hook-config branch from 0264309 to 674a6a7 Compare May 13, 2026 03:00
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 13, 2026
@github-project-automation github-project-automation Bot moved this to 🤔 Needs Triage in Flutter GPU May 13, 2026
@bdero bdero moved this from 🤔 Needs Triage to 🔧 Internals in Flutter GPU May 13, 2026
@bdero bdero force-pushed the bdero/flutter-hook-config branch from 674a6a7 to db28bc4 Compare May 13, 2026 03:30
@github-actions github-actions Bot removed the CICD Run CI/CD label May 13, 2026
@bdero bdero added CICD Run CI/CD and removed CICD Run CI/CD labels May 13, 2026
@bdero bdero requested review from dcharkes and stuartmorgan-g May 13, 2026 17:02
@bdero bdero marked this pull request as ready for review May 13, 2026 17:02
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the flutter_hook_config package, a package:hooks protocol extension that allows the Flutter SDK to provide engine host-tool paths like impellerc and libtessellator to build and link hooks. The PR includes the package's core configuration logic, a ProtocolExtension implementation, documentation, and unit tests. A review comment suggests improving the assertions in the setupFlutter method to explicitly verify that provided URIs use the 'file' scheme, ensuring more descriptive error messages for developers.

Comment thread packages/flutter_hook_config/lib/src/config.dart Outdated
@bdero bdero removed the CICD Run CI/CD label May 13, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 13, 2026
Comment thread packages/flutter_hook_config/lib/src/config.dart Outdated
///
/// When the SDK is invoked with `--local-engine`, this points at the locally
/// built `impellerc`, matching the engine the app is being built against.
Uri get impellerc => _filePath(_impellercKey);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two related? Do they change together? If yes they should maybe be nested in an object together.

Also, does every Flutter have impeller? E.g. With third-party forks of Flutter is there ever a possibility there's no impeller? If yes, then that wrapper object should be nullable. And if it's not null both fields are non-nullably provided.

Do we need a some kind of version number for this? e.g. if any of these files change or the underlying formats change, you'd want the hook to be rerun.

Copy link
Copy Markdown
Member Author

@bdero bdero May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, does every Flutter have impeller? With third-party forks of Flutter is there ever a possibility there's no impeller? If yes, then that wrapper object should be nullable. And if it's not null both fields are non-nullably provided.

impellerc is used for both Impeller and Skia. Even if one were to do the heavy work of ripping out Impeller from the engine (since we don't even ship Skia on iOS), features like the Fragment Program API/RuntimeEffect use impellerc to compile shaders regardless of the graphics backend (impellerc transpiles to SkSL for Skia).

The impellerc dependency is baked elsewhere in flutter_tools already.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a some kind of version number for this? e.g. if any of these files change or the underlying formats change, you'd want the hook to be rerun.

Hmm yes that's a good point and we should think about this... Since the artifacts are per-engine build, maybe the right thing to do would be to add a config.flutter.engineVersion, so that the cache key gets invalidated whenever the engine artifacts change. I can just grab the engine revision from Cache.engineRevision in flutter_tools.

Does that seem right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added engineVersion.

sdk: ^3.9.0

dependencies:
hooks: ^1.0.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: I'm publishing a 2.0.0 soon, because we need to add a method to the ProtocolExtension (dart-lang/native#3358).

@bdero bdero force-pushed the bdero/flutter-hook-config branch from 097ace0 to bb9071f Compare May 13, 2026 22:59
@bdero bdero removed the CICD Run CI/CD label May 13, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 13, 2026
@bdero bdero force-pushed the bdero/flutter-hook-config branch from bb9071f to be4ada9 Compare May 13, 2026 22:59
@bdero bdero removed the CICD Run CI/CD label May 13, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 13, 2026
A package:hooks protocol extension that lets the Flutter SDK expose
engine host-tool paths (impellerc, libtessellator) to build and link
hooks in a typed way, replacing the per-package SDK-cache-walking that
packages like flutter_gpu_shaders do today and making the
--local-engine override propagate to hooks for free.

Towards flutter/flutter#186299
@bdero bdero force-pushed the bdero/flutter-hook-config branch from be4ada9 to 9d5bfd0 Compare May 14, 2026 03:11
@bdero bdero removed the CICD Run CI/CD label May 14, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 14, 2026
@bdero bdero requested a review from dcharkes May 14, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD

Projects

Status: 🔧 Internals

Development

Successfully merging this pull request may close these issues.

2 participants