Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Add support of cross-building the engine for ARM64 Linux Host #20254

Conversation

HidenoriMatsubayashi
Copy link
Member

@HidenoriMatsubayashi HidenoriMatsubayashi commented Aug 5, 2020

Description

Added cross-building Flutter Engine for ARM64 Linux platforms. This PR is part of ARM64 Linux support in the Flutter SDK.

Related PRs

Related Issues

Tests

1. Build Test

First, I confirmed that Flutter Engine can be built for x64 and arm64. The procedure is as follows. All are operations on x64 Linux Host.

Get source code and setup build enviroment.

create .gclient file.
$ gclient sync
$ cd src

Cross-build for ARM64 Linux

$ ./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode release
$ ninja -C out/linux_release_arm64
-> Passed!

$ ./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode debug
$ ninja -C out/linux_debug_arm64
-> Passed!

Build for x64 Linux and Regression test.

$ ./flutter/tools/gn --unoptimized
$ ninja -C out/host_debug_unopt
-> Passed!

$ ./flutter/testing/run_tests.sh
-> All Tests Passed!

2. Run Flutter SDK and app on ARM64 Linux (Jetson Nano)

Second, using the artifacts for ARM64 built by the above procedure, I have confirmed that the Flutter SDK and Flutter app can work fine on Jetson Nano (ARM64 CPU).

All are operations on ARM64 Linux Host (Jetson Nano).

$ git clone https://github.com/flutter/flutter.git
$ export PATH=$PATH:{your working dir path}/flutter/bin
$ flutter doctor
   ... Error happened.

Copy dart-sdk which was locally built to ${your installpath}/bin/cache/.

$ flutter doctor
$ flutter config --enable-linux-desktop
$ flutter create sample
$ cd sample
$ flutter build linux
   ... Error happened.

Copy the Flutter SDK artifacts (build data) to ${your installpath}/bin/cache/artifacts/engine directory manually.

  • out/linux_debug_arm64/flutter_patched_sdk to ${your installpath}/bin/cache/artifacts/engine/common/flutter_patched_sdk

  • out/linux_debug_arm64/flutter_linux, gen/const_finder.dart.snapshot, flutter_tester, font-subset, gen/frontend_server.dart.snapshot, icudtl.dat, libflutter_linux_gtk.so, gen/flutter/lib/snapshot/isolate_snapshot.bin, gen/flutter/lib/snapshot/vm_isolate_snapshot.bin to ${your installpath}/bin/cache/artifacts/engine/artifacts/engine/linux-x64

  • out/linux_release_arm64/flutter_patched_sdk to ${your installpath}/bin/cache/artifacts/engine/common/flutter_patched_sdk_product

  • out/linux_release_arm64/flutter_linux, libflutter_linux_gtk.so to ${your installpath}/bin/cache/artifacts/engine/artifacts/engine/linux-x64-release

  • out/linux_release_arm64/clang_x64/gen_snapshot to ${your installpath}/bin/cache/artifacts/engine/artifacts/engine/linux-x64-release

  • For simple operation check, ${your installpath}/bin/cache/artifacts/engine/artifacts/engine/linux-x64-profile is omitted.
( $ flutter build linux --verbose )
$ flutter run -d linux

Screenshot from 2020-08-05 12-52-42

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

@iskakaushik
Copy link
Contributor

@christopherfujino to route to the right reviewer for this.

BUILD.gn Outdated
@@ -71,7 +71,7 @@ group("flutter") {
}

# If on the host, compile tools.
if (current_toolchain == host_toolchain) {
if (current_toolchain == host_toolchain || is_linux) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition no longer matches the comment. Aren't these host tools? It's not clear to me why you are cross-compiling them.

Copy link
Member Author

@HidenoriMatsubayashi HidenoriMatsubayashi Aug 6, 2020

Choose a reason for hiding this comment

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

Yes, I have to modify the comment.

But I couldn't understand why if (current_toolchain == host_toolchain) was necessary. In order to run the Flutter SDK and Flutter Apps on ARM64 Linux platforms, we need to build dart-sdk, frontend_server.dart.snapshot and const_finder.dart.snapshot and so on. This condition is not necessary for cross build.

I think I got it for now. But I think you need to build the following in order to run Flutter SDK on ARM64 Linux. Correct?

  • //flutter/flutter_frontend_server:frontend_server
  • //third_party/dart:create_sdk
  • //flutter/web_sdk
  • //flutter/shell/testing
  • //flutter/tools/const_finder
  • //flutter/tools/font-subset

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know the answer to that offhand.

Are they uploaded as artifacts and then downloaded and run by the flutter tool? If so, then you are correct that they aren't host tools, in which case we should instead be deciding when to build them based on support Flutter SDK environments.

Copy link
Member Author

@HidenoriMatsubayashi HidenoriMatsubayashi Aug 17, 2020

Choose a reason for hiding this comment

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

@stuartmorgan
(cc: @christopherfujino please support me.)

Thank you for your reply.

Are they uploaded as artifacts and then downloaded and run by the flutter tool?

That's right.
I think that it is not necessary in the case where only cross build like Android and iOS, however it is necessary when running as Flutter SDK on Host.

I think that all can be built for ARM64 without problems.

//third_party/dart:create_sdk

This is dart-sdk and download to ${INSTALL_PATH}/flutter/bin/cache/dart-sdk. ARM64 is already supported (link)

//flutter/flutter_frontend_server:frontend_server

This is the Dart project, it can be built for ARM64.
It's downloaded to ${INSTALL_PATH}/flutter/bin/cache/artifacts/engine/linux-${arch}/frontend_server.dart.snapshot

//flutter/web_sdk

I'm not sure about this.

//flutter/shell/testing

This is the C++ source code for flutter_test?
It's downloaded to ${INSTALL_PATH}/flutter/bin/cache/artifacts/engine/linux-${arch}/flutter_tester

//flutter/tools/const_finder

This is the Dart project.
It's downloaded to ${INSTALL_PATH}/flutter/bin/cache/artifacts/engine/linux-${arch}/const_finder.dart.snapshot

//flutter/tools/font-subset

This is the C++ source code.
It's downloaded to ${INSTALL_PATH}/flutter/bin/cache/artifacts/engine/linux-${arch}/font-subset

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense; I thought "host" in the comment meant build host, rather that "Flutter host". I think you'll want (is_linux && !is_chromeos) though.

The comment should probably be something like:

# Flutter SDK artifacts should only be built when either doing host builds, or
# for cross-compiled desktop targets.

(I wouldn't mention Linux since macOS and/or Windows could be done this way in the future.)

Also, you should extract this to a variable like build_engine_artifacts since it's used in two places.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you so much. I fixed it. Could you review my change?

@HidenoriMatsubayashi HidenoriMatsubayashi changed the title Add Linux Host ARM64 Support Add support of cross-build the engine for ARM64 Linux Host Aug 6, 2020
@HidenoriMatsubayashi HidenoriMatsubayashi changed the title Add support of cross-build the engine for ARM64 Linux Host Add support of cross-building the engine for ARM64 Linux Host Aug 6, 2020
@incon
Copy link

incon commented Aug 29, 2020

Description

Added cross-building Flutter Engine for ARM64 Linux platforms. This PR is part of ARM64 Linux support in the Flutter SDK.

Related PRs

Related Issues

Tests

1. Build Test

First, I confirmed that Flutter Engine can be built for x64 and arm64. The procedure is as follows. All are operations on x64 Linux Host.

Get source code and setup build enviroment.

create .gclient file.
$ gclient sync
$ cd src

Cross-build for ARM64 Linux

$ ./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode release
$ ninja -C out/linux_release_arm64
-> Passed!

$ ./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode debug
$ ninja -C out/linux_debug_arm64
-> Passed!

Build for x64 Linux and Regression test.

$ ./flutter/tools/gn --unoptimized
$ ninja -C out/host_debug_unopt
-> Passed!

$ ./flutter/testing/run_tests.sh
-> All Tests Passed!

2. Run Flutter SDK and app on ARM64 Linux (Jetson Nano)

Second, using the artifacts for ARM64 built by the above procedure, I have confirmed that the Flutter SDK and Flutter app can work fine on Jetson Nano (ARM64 CPU).

All are operations on ARM64 Linux Host (Jetson Nano).

$ git clone https://github.com/flutter/flutter.git
$ export PATH=$PATH:{your working dir path}/flutter/bin
$ flutter doctor
   ... Error happened.
Copy the dart-sdk which was locally built to ${your installpath}/bin/cache/.
$ flutter doctor
$ flutter config --enable-linux-desktop
$ flutter create sample
$ cd sample
$ flutter build linux
   ... Error happened.
Copy the build data to built to ${your installpath}/bin/cache/artifacts/engine/common/flutter_patched_sdk, ${your installpath}/bin/cache/artifacts/engine/common/flutter_patched_sdk_product, ${your installpath}/bin/cache/artifacts/engine/artifacts/engine/linux-x64, ${your installpath}/bin/cache/artifacts/engine/artifacts/engine/linux-x64-release and ${your installpath}/bin/cache/artifacts/engine/artifacts/engine/linux-x64-profile.
( $ flutter build linux --verbose )
$ flutter run -d linux

Screenshot from 2020-08-05 12-52-42

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

I've been able to complete the build step on my Linux x86 Host machine.
I'm unsure on what files I need copy over to my Raspberry Pi in this step Copy the build data to built to ${your installpath}/bin/cache/artifacts/engine/common/flutter_patched_sdk, ${your installpath}/bin/cache/artifacts/engine/common/flutter_patched_sdk_product, ${your installpath}/bin/cache/artifacts/engine/artifacts/engine/linux-x64, ${your installpath}/bin/cache/artifacts/engine/artifacts/engine/linux-x64-release and ${your installpath}/bin/cache/artifacts/engine/artifacts/engine/linux-x64-profile.
Could you please need me know what files I need to copy and to where, thank you.

@HidenoriMatsubayashi
Copy link
Member Author

@incon
I updated the description.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

Needs GN formatting so it passes CI, but otherwise LGTM. @chinmaygarde should review as well since he's more familiar with the engine artifacts though, to make sure that new logic makes sense to him as well.

@HidenoriMatsubayashi
Copy link
Member Author

@stuartmorgan Thank you so much. I fixed the formatting error.

@cbracken cbracken merged commit 101d85a into flutter:master Sep 17, 2020
@cthurston
Copy link

cthurston commented Nov 30, 2020

Using these instructions to run on pi 4. The debug works and I can run and debug the sample application on the pi. Very nice.

However, I can't build a release. It seems that the clang_x64/gen_snapshot executable is still x86.

Update: I copied gen_snapshot_product to the gen_snapshot and it successfully built a release bundle. Wahoo!

Really nice write up has been created here:
https://wiki.loliot.net/docs/lang/flutter/engine/flutter-engine-for-linux-arm64/
https://wiki.loliot.net/docs/lang/flutter/engine/flutter-app-for-linux-arm64

dwrobel added a commit to dwrobel/engine that referenced this pull request Feb 2, 2021
ortogonal pushed a commit to ortogonal/engine that referenced this pull request Feb 9, 2021
dwrobel added a commit to dwrobel/engine that referenced this pull request Feb 12, 2021
dwrobel added a commit to dwrobel/engine that referenced this pull request Feb 18, 2021
zhzhzhy pushed a commit to zhzhzhy/Flutter-SDK-ARM64 that referenced this pull request Apr 9, 2021
zhzhzhy pushed a commit to zhzhzhy/Flutter-SDK-ARM64 that referenced this pull request Apr 9, 2021
tomasz-karczewski-red pushed a commit to tomasz-karczewski-red/flutter-engine that referenced this pull request Apr 9, 2021
zhzhzhy pushed a commit to zhzhzhy/Flutter-SDK-ARM64 that referenced this pull request Apr 9, 2021
zhzhzhy pushed a commit to zhzhzhy/Flutter-SDK-ARM64 that referenced this pull request Apr 9, 2021
@jwinarske
Copy link
Contributor

I don't understand why this PR claims cross compilation for aarch64. I was able to cross compile the engine for arrch64 long before this PR.

@cthurston
Copy link

I believe this PR is so that you can compile and run inside of a linux desktop that is running on arm64, a raspberry pi running raspberry pi OS for example.

@jwinarske
Copy link
Contributor

Yes I see the build on host, it also claims cross compilation. Imagine trying to build the engine on a raspberry pi? That would take an enternity... Hence why cross compiling is preferred, which already worked for ~2 years.

tomasz-karczewski-red pushed a commit to tomasz-karczewski-red/flutter-engine that referenced this pull request Jun 25, 2021
tomasz-karczewski-red pushed a commit to tomasz-karczewski-red/flutter-engine that referenced this pull request Jun 25, 2021
tomasz-karczewski-red pushed a commit to tomasz-karczewski-red/flutter-engine that referenced this pull request Jun 25, 2021
tomasz-karczewski-red pushed a commit to tomasz-karczewski-red/flutter-engine that referenced this pull request Jun 25, 2021
tomasz-karczewski-red pushed a commit to tomasz-karczewski-red/flutter-engine that referenced this pull request Jun 25, 2021
dwrobel added a commit to dwrobel/engine that referenced this pull request Jun 29, 2021
dwrobel added a commit to dwrobel/engine that referenced this pull request Jun 29, 2021
tomasz-karczewski-red pushed a commit to tomasz-karczewski-red/flutter-engine that referenced this pull request Aug 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants