Skip to content

tools: Support --host-arch option in flutter precache - #190480

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
cbracken:migrate-arm64-update-precache
Aug 7, 2026
Merged

tools: Support --host-arch option in flutter precache#190480
auto-submit[bot] merged 3 commits into
flutter:masterfrom
cbracken:migrate-arm64-update-precache

Conversation

@cbracken

@cbracken cbracken commented Aug 3, 2026

Copy link
Copy Markdown
Member

Adds a --host-arch=<x64|arm64> option to flutter precache and adds support for the FLUTTER_HOST_ARCH environment variable in OperatingSystemUtils.hostPlatform.

When specified, this overrides the default hardware detection check (sysctl hw.optional.arm64 on macOS), and causes flutter precache to download host engine artifacts for the specified architecture instead.

This is required to allow arm64 macOS CI hosts to download and cache x64 host engine artifacts when cross-packaging x64 Flutter SDK release archives on an arm64 host in the packaging/packaging recipe in packaging.py.

See: https://flutter.googlesource.com/recipes/+/refs/heads/main/recipes/packaging/packaging.py

Issue: #189144

Pre-launch Checklist

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

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@cbracken
cbracken requested review from bkonyi and jtmcdole August 3, 2026 22:29
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 3, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Aug 3, 2026

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

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.

Code Review

This pull request adds a --host-arch option to the precache command and introduces a FLUTTER_HOST_ARCH environment variable override to allow overriding the host platform architecture. The review feedback suggests refactoring _MacOSUtils.hostPlatform to delegate to super.hostPlatform to avoid code duplication, and simplifying the PrecacheCommand constructor and associated tests by removing the redundant os parameter and field.

Comment thread packages/flutter_tools/lib/src/base/os.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/precache.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/precache.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/precache.dart Outdated
Comment thread packages/flutter_tools/test/commands.shard/hermetic/precache_test.dart Outdated
@cbracken
cbracken force-pushed the migrate-arm64-update-precache branch 3 times, most recently from 9fbf0f9 to ba2d728 Compare August 4, 2026 06:55

@bkonyi bkonyi left a comment

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.

LGTM overall, just a couple of nits.

Comment thread packages/flutter_tools/lib/src/base/os.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/precache.dart Outdated
Comment thread packages/flutter_tools/lib/src/base/os.dart Outdated
Adds a `--host-arch=<x64|arm64>` option to `flutter precache` and
adds support for the `FLUTTER_HOST_ARCH` environment variable in
`OperatingSystemUtils.hostPlatform`.

When specified, this overrides the default hardware detection check
(`sysctl hw.optional.arm64` on macOS), and causes `flutter precache` to
download host engine artifacts for the specified architecture instead.

This is required to allow arm64 macOS CI hosts to download and cache x64
host engine artifacts when cross-packaging x64 Flutter SDK release
archives on an arm64 host in the `packaging/packaging` recipe in
`packaging.py`.

See: https://flutter.googlesource.com/recipes/+/refs/heads/main/recipes/packaging/packaging.py

Issue: flutter#189144
os.dart:
OperatingSystemUtils.hostPlatform now owns hostPlatformOverride and the
env var precedence logic.

precache.dart:
Kill the redundant os.

precache_test.dart:
Simplified the test.

os_test.dart:
Drop the unused sysctl commands queued in the precendence test since
they're not needed.
@cbracken
cbracken force-pushed the migrate-arm64-update-precache branch 4 times, most recently from 207047e to b813e05 Compare August 7, 2026 03:06
@cbracken
cbracken force-pushed the migrate-arm64-update-precache branch from b813e05 to 9bdc48c Compare August 7, 2026 03:14

@bkonyi bkonyi left a comment

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.

LGTM w/ one question

@@ -217,6 +217,7 @@ class Cache {
final Platform _platform;
final FileSystem _fileSystem;
final OperatingSystemUtils _osUtils;

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.

Can we not just make _osUtils public?

if (hostPlatformOverride case final HostPlatform override) {
return override;
}
if (_platform.environment['FLUTTER_HOST_ARCH'] case final String overrideArch) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A+, no notes. Just an informative "if you ever want to use multiple keys from that map", this pattern works:

class Platform {
  final environment = <String, Object?>{};
}

void main() async {
  final _platform = Platform()
    ..environment['FLUTTER_HOST_ARCH'] = 'arch128'
    ..environment['FOO'] = 'bar';

  if (_platform.environment case {
    'FLUTTER_HOST_ARCH': final String overrideArch,
    'FOO': final String foo,
  }) {
    print((overrideArch: overrideArch, foo: foo));
    // (foo: bar, overrideArch: arch128)
 }
}

@jtmcdole jtmcdole added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 7, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 7, 2026
Merged via the queue into flutter:master with commit 80234e1 Aug 7, 2026
22 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants