Skip to content

feat(flutter): add a linux_arm64 toolchain - #5

Draft
pawelchcki wants to merge 1 commit into
SpencerC:mainfrom
pawelchcki:feat/linux-arm64-toolchain
Draft

feat(flutter): add a linux_arm64 toolchain#5
pawelchcki wants to merge 1 commit into
SpencerC:mainfrom
pawelchcki:feat/linux-arm64-toolchain

Conversation

@pawelchcki

Copy link
Copy Markdown

Problem

PLATFORMS registers linux as x86_64-only, so there is no way to build on arm64 Linux. That is increasingly common on CI (AWS CodeBuild arm images, Ampere/Graviton runners) and on developer machines.

The blocker is real but narrower than it looks: Flutter publishes no linux-arm64 SDK tarball, so there is no archive to point a new platform at.

What Flutter does publish

The architecture-specific pieces exist, per engine revision:

flutter/<engine>/dart-sdk-linux-arm64.zip     200
flutter/<engine>/linux-arm64/artifacts.zip    200   # flutter_tester, gen_snapshot, impellerc, icudtl.dat

And only bin/cache holds native code — the framework sources, the flutter_tools kernel snapshot (a JIT snapshot, so portable) and the templates in the x64 archive are architecture-independent.

Approach

linux_arm64 downloads the x64 release archive, deletes the native pieces of bin/cache along with the stamps that mark them current, and lets the existing fetch-time precache refetch them for the host:

  • the launcher's update_dart_sdk.sh selects the Dart SDK by uname -m
  • flutter_tools resolves engine artifacts through its own host-platform detection

This is the same bootstrap path a plain git clone of the SDK takes on arm64, which is how people run Flutter on arm64 Linux today.

Points worth reviewing

Fetch is host-restricted. Completing the linux_arm64 repository runs the launcher, so it can only be fetched on an arm64 Linux host. Bazel only fetches the host platform's SDK repository, so this is not a practical restriction — but it is enforced with an explicit error rather than a confusing failure later.

Failure is loud, not silent. _verify_rearchitected checks that dart-sdk/bin/dart and linux-arm64/flutter_tester exist after the precache. If a future release stops refetching them as a side effect of precache, it surfaces at fetch time with an actionable message instead of an exec-format error inside a build action.

One latent trap fixed along the way. Making _host_matches_platform architecture-aware would have silently disabled the linux artifact group on arm64 hosts, since _PRECACHE_GROUP_HOSTS values are OS names, not platform names. Those now route through a separate _host_is_os helper.

Existing platforms are untouched. _archive_platform and _platform_arch are identity mappings for everything except linux_arm64, and _PRECACHE_SENTINELS only gained an {arch} placeholder that substitutes to x64 everywhere else.

Testing

Verified on x86_64 that this is a no-op for the existing path: a full flutter build web --release, an 8-shard test suite and flutter analyze --fatal-infos for a real app all pass through the patched ruleset.

The arm64 path is verified against the published artifact URLs (both return 200 for the pinned engine revision, and I confirmed linux-arm64/artifacts.zip contains flutter_tester, gen_snapshot and impellerc) but has not yet been run end to end on arm64 hardware — that is why this is a draft. I am wiring it into arm64 CI now and will report back with a real run before marking it ready.

Would also like your view on whether _ARCHIVE_ALIASES is the shape you want for this, or whether you would rather see an explicit per-platform archive/artifact descriptor.

Flutter publishes no linux-arm64 SDK tarball, so `linux` is registered as
x86_64-only and there is no way to build on arm64 Linux -- increasingly
common on CI (AWS CodeBuild arm images, Ampere runners) and on developer
machines.

Flutter does publish the architecture-specific pieces per engine revision:
dart-sdk-linux-arm64.zip and linux-arm64/artifacts.zip (flutter_tester,
gen_snapshot, impellerc). Only bin/cache holds native code -- the framework
sources, the flutter_tools kernel snapshot and the templates in the x64
archive are architecture-independent.

So linux_arm64 downloads the x64 release archive, deletes the native pieces
of bin/cache along with the stamps that mark them current, and lets the
existing fetch-time precache refetch them for the host: the launcher's
update_dart_sdk.sh selects the Dart SDK by `uname -m`, and flutter_tools
resolves engine artifacts through its own host-platform detection. This is
the same bootstrap path a plain `git clone` of the SDK takes on arm64.

Consequences worth reviewing:

- The linux_arm64 repository can only be *fetched* on an arm64 Linux host,
  since completing it runs the launcher. Bazel only fetches the host
  platform's SDK repository, so this is not a practical restriction, but it
  is enforced with an explicit error rather than a confusing failure later.
- _verify_rearchitected fails at fetch time if the replacements did not
  appear, so a future release that stops refetching them as a side effect of
  precache surfaces here instead of as an exec-format error inside a build
  action.
- _host_matches_platform is now architecture-aware, which would have
  silently disabled the `linux` artifact group on arm64 hosts. Artifact
  groups are named after operating systems, so they now route through a
  separate _host_is_os helper.

The x64, macOS and Windows paths are unchanged: _archive_platform and
_platform_arch are identity mappings for every platform except linux_arm64.

Tested on x86_64 (no regression: a full web build, test suite and analyze
run of a real app all pass). The arm64 path has been verified against the
published artifact URLs but not yet run end to end on arm64 hardware --
hence the draft.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant