Skip to content

feat: support Linux ARM64 by invalidating bundled x64 stamps - #1

Merged
ooaklee merged 2 commits into
masterfrom
feat/linux-arm64-support
Jul 5, 2026
Merged

feat: support Linux ARM64 by invalidating bundled x64 stamps#1
ooaklee merged 2 commits into
masterfrom
feat/linux-arm64-support

Conversation

@ooaklee

@ooaklee ooaklee commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Merging the upstream-bound feature branch into the fork's default branch so it's available here regardless of when the upstream PR (asdf-community#58 on asdf-community/asdf-flutter) is merged.

See that PR for full context, or the ADR at `docs/adr/adr001-linux-arm64-support.md` for the diagnosis and rationale.

Problem

On Linux `aarch64` hosts, `asdf install flutter ` completes successfully but the first `flutter` invocation fails with:

```
.../bin/internal/shared.sh: line 273:
.../bin/cache/dart-sdk/bin/dart: cannot execute binary file: Exec format error
```

Root cause

Flutter's Linux tarball bundles an x86-64 dart-sdk plus matching `engine-dart-sdk.stamp` and `flutter_tools.stamp`. Because the stamps match on first run, Flutter's self-heal (`update_dart_sdk.sh`, the script that detects host arch and fetches the matching dart-sdk) is never reached. The wrong-arch dart binary stays in place.

`releases_linux.json` exposes no `dart_sdk_arch` field (all 719 entries are `x64`), so the macOS-style archive filtering can't be reused on Linux.

Fix

After extraction, on non-`x86_64` Linux hosts delete both stamps so `update_dart_sdk.sh` runs on first invocation, detects the host arch via `uname -m`, and fetches the matching dart-sdk (e.g. `dart-sdk-linux-arm64.zip`).

The stamp-invalidation logic is extracted into a standalone function (`invalidate_bundled_stamps_for_non_x64_linux`) so it can be unit-tested in isolation. Architecture detection is delegated to Flutter's own `update_dart_sdk.sh`, which already handles `aarch64` and `riscv64` correctly.

Changes

  • `bin/install` - new `invalidate_bundled_stamps_for_non_x64_linux()`; top-level execution guarded by a `BASH_SOURCE` check so the file can be sourced by tests; `dirname $0` -> `dirname "${BASH_SOURCE[0]}"`.
  • `bin/utils.sh` - drive-by fix: `${VAR:=default}` -> `: "${VAR:=default}"` (the previous form returned exit 127 under `set -e`).
  • `test/install.bats` - 7 bats tests covering x86_64 (preserve), aarch64 (remove each stamp), riscv64 (remove both), darwin arm64/x86_64 (preserve), and an unknown-arch default-branch guard.
  • `.github/workflows/test.yml` - CI matrix on `ubuntu-24.04` (x86_64) and `ubuntu-24.04-arm` (aarch64).
  • `docs/adr/adr001-linux-arm64-support.md` - ADR documenting the context, decision, and consequences.
  • `README.md` - new troubleshooting section with a link to the ADR.

Verification

  • Reproduced the original `Exec format error` on `aarch64` Linux with `3.44.4-stable`.
  • After applying the fix: `file bin/cache/dart-sdk/bin/dart` reports `ELF 64-bit ... ARM aarch64`; `flutter --version` reports `Flutter 3.44.4 • channel stable`; `dart --version` reports `on "linux_arm64"`.
  • `bats test/` - 7/7 passing locally on aarch64.

Leon Silcott added 2 commits July 5, 2026 12:33
Flutter's official Linux tarball bundles an x86-64 dart-sdk under
bin/cache/dart-sdk/ plus matching engine-dart-sdk.stamp and
flutter_tools.stamp. On non-x86_64 Linux hosts (aarch64, riscv64) the
bundled dart binary cannot execute, and the first `flutter` invocation
fails with:

  .../bin/internal/shared.sh: line 273:
  .../bin/cache/dart-sdk/bin/dart: cannot execute binary file: Exec format error

Because both shipped stamps match on first run, Flutter's self-heal
(update_dart_sdk.sh) is never reached - it is only invoked when
flutter_tools.stamp is invalid - so the wrong-arch dart binary is never
replaced.

Fix: after extraction, on non-x86_64 Linux hosts delete both
engine-dart-sdk.stamp and flutter_tools.stamp so update_dart_sdk.sh
runs on first invocation, detects the host arch, and fetches the
matching dart-sdk (e.g. dart-sdk-linux-arm64.zip).

The stamp-invalidation logic is extracted into a standalone function
(invalidate_bundled_stamps_for_non_x64_linux) so it can be unit-tested
in isolation. A bats suite (test/install.bats) guards the regression on
both x86_64 (stamps preserved) and aarch64 (stamps removed), and CI
runs the suite on ubuntu-24.04 and ubuntu-24.04-arm runners.

Drive-by fix: bin/utils.sh line 3 used ${VAR:=default} without a
leading ':' no-op, which tried to execute the URL as a command and
returned exit 127 under `set -e`. Fixed to the standard
`: "${VAR:=default}"` idiom.

See docs/adr/adr001-linux-arm64-support.md for the full diagnosis and
rationale, and the README troubleshooting section for user-facing
context.
@ooaklee
ooaklee merged commit 4bdf72d into master Jul 5, 2026
2 checks passed
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