- Move "gclient bootstrap" out of engine/README.md into a section in the "Setting up the Engine development environment" doc. - In the "gclient bootstrap" section, instruct Googlers to follow the RBE setup docs. - Update the "Additional Steps for Web Engine" to reflect the fact that the user's gclient file is copied from a template that contains a commented-out web engine entry. - Link to the "Engine Tool" docs instead of to "Compiling the engine" for the next steps. - In the RBE doc: - Update the gclient instructions to reflect that the gclient file may be copied from rbe.gclient. - Move the "gcloud" section into the "Getting started" parent section. The gcloud setup is required before any of the next steps. - Instead of suggested the "gcloud auth application-default login" command in case of an error, directly instruct the user to run this command. It's required for things to work. - Add a "Too many open files" section to the Troubleshooting parent section. <!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> *Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.* *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). 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. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
18 KiB
If you've never built the engine before, first see Setting up the Engine development environment.
Contents
Depending on the platform you are making changes for, you may be interested in all or only some of the sections below:
- General Compilation Tips
- Using a custom Dart SDK
- Compiling for Android
- Compiling for iOS (from macOS)
- Compiling for macOS or Linux
- Compiling for Windows
- Compiling for Fuchsia
- Compiling for the Web
- Compiling for testing
General Compilation Tips
- Instead of compiling manually as described in this file, it's recommended to use
et, the engine tool, located at https://github.com/flutter/flutter/blob/main/engine/src/flutter/tools/engine_tool. - For local development and testing, it's generally preferable to use
--unoptbuilds. These builds will have additional logging and checks enabled, and generally use build and link flags that lead to faster compilation and better debugging symbols. If you are trying to do performance testing with a local build, do not use the--unoptflag. - Link Time Optimization: Optimized builds also perform Link Time Optimization of all
binaries. This makes the linker take a lot of time and memory to produce binaries. If
you need optimized binaries but don't want to perform LTO, add the
--no-ltoflag. - Android and iOS expect both a
hostandandroid(orios) build. It is critical to recompile the host build after upgrading the Dart SDK (e.g. via agclient syncafter merging up to head), since artifacts from the host build need to be version matched to artifacts in the Android/iOS build. - Web, Desktop, and Fuchsia builds have only one build target (i.e.
hostorfuchsia). - Make sure to exclude the
outdirectory from any backup scripts, as many large binary artifacts are generated. This is also generally true for all of the directories outside of theengine/src/flutterdirectory. - See gclient bootstrap
section for details on how to setup
gclient.
Updating the engine
Before compiling, you should typically make sure that your engine code is up to date with the latest master:
git fetch upstream master
git rebase upstream/master
gclient sync -D
Using a custom Dart SDK
When targeting the host and desktop, on CI we use a pre-built Dart SDK vended by the Dart team.
To build and use the SDK from the Dart sources downloaded by gclient sync, after editing those
source files, pass the flag --no-prebuilt-dart-sdk to //flutter/tools/gn.
Compiling for Android (from macOS or Linux)
These steps build the engine used by flutter run for Android devices.
Run the following steps from the engine/src directory in your local checkout. See Setting up the Engine development environment.
-
Make sure your engine code is up to date.
-
Prepare your build files
./flutter/tools/gn --android --unoptimizedfor device-side executables../flutter/tools/gn --android --android-cpu arm64 --unoptimizedfor newer 64-bit Android devices../flutter/tools/gn --android --android-cpu x86 --unoptimizedfor x86 emulators../flutter/tools/gn --android --android-cpu x64 --unoptimizedfor x64 emulators../flutter/tools/gn --unoptimizedfor host-side executables, needed to compile the code.- On Apple Silicon ("M" chips), add
--mac-cpu arm64to avoid using emulation. This will generatehost_debug_unopt_arm64.
- On Apple Silicon ("M" chips), add
💡 TIP: When developing on a Mac with ARM (M CPU), prefer
host_debug_unopt_arm64.You can continue to use
host_debug_unopt(required for Intel Macs), but the engine will be run under Rosetta which may be slower. See Developing with Flutter on Apple Silicon for more information.
- Build your executables
ninja -C out/android_debug_unoptfor device-side executables.ninja -C out/android_debug_unopt_arm64for newer 64-bit Android devices.ninja -C out/android_debug_unopt_x86for x86 emulators.ninja -C out/android_debug_unopt_x64for x64 emulators.ninja -C out/host_debug_unopt(orninja -C out/host_debug_unopt_arm64, see above) for host-side executables.- These commands can be combined. Ex:
ninja -C out/android_debug_unopt && ninja -C out/host_debug_unopt - For MacOS, you will need older version of XCode(9.4 or below) to compile android_debug_unopt and android_debug_unopt_x86. If you only care about x64, you can ignore this
This builds a debug-enabled ("unoptimized") binary configured to run Dart in checked mode ("debug"). There are other versions, see Flutter's modes.
If you're going to be debugging crashes in the engine, make sure you add
android:debuggable="true" to the <application> element in the
android/AndroidManifest.xml file for the Flutter app you are using
to test the engine.
See The flutter tool for instructions on how to use the flutter tool with a local engine.
You will typically use the android_debug_unopt build to debug the engine on a device, and
android_debug_unopt_x64 to debug in on a simulator. Modifying dart sources in the engine will
require adding a dependency_override section in you app's pubspec.yaml as detailed
here.
Note that if you use particular android or ios engine build, you will need to have corresponding
host build available next to it: if you use android_debug_unopt, you should have built host_debug_unopt,
android_profile -> host_profile, etc. One caveat concerns cpu-flavored builds like android_debug_unopt_x86: you won't be able to build host_debug_unopt_x86 as that configuration is not supported. What you are expected to do is to build host_debug_unopt and symlink host_debug_unopt_x86 to it.
Compiling everything that matters on Linux
The following script will update all the builds that matter if you're developing on Linux and testing on Android and your .gclient file is located at ~/dev/flutter/engine/.gclient:
set -ex
cd ~/dev/flutter
git fetch upstream master
git rebase upstream/master
cd engine
gclient sync -D
cd src
flutter/tools/gn --unoptimized --runtime-mode=debug
flutter/tools/gn --android --unoptimized --runtime-mode=debug
flutter/tools/gn --android --runtime-mode=profile
flutter/tools/gn --android --runtime-mode=release
cd out
find . -mindepth 1 -maxdepth 1 -type d | xargs -n 1 sh -c 'ninja -C $0 || exit 255'
For --runtime-mode=profile build, please also consider adding --no-lto option to the gn command. It will make linking much faster with a small sacrifice on the binary size and memory usage (which probably doesn't matter for debugging or performance benchmark purposes.)
Compiling for iOS (from macOS)
These steps build the engine used by flutter run for iOS devices.
Run the following steps, from the engine/src directory:
-
Make sure your engine code is up to date.
-
./flutter/tools/gn --ios --unoptimizedto prepare build files for device-side executables (or--ios --simulator --unoptimizedfor simulator).- This also produces an Xcode project for working with the engine source code at
out/ios_debug_unopt/flutter_engine.xcodeproj - For a discussion on the various flags and modes, see Flutter's modes.
- Add the
--simulator-cpu=arm64argument for an arm64 Mac simulator to output toout/ios_debug_sim_unopt_arm64.
- This also produces an Xcode project for working with the engine source code at
-
./flutter/tools/gn --unoptimizedto prepare the build files for host-side executables.- On Apple Silicon ("M" chips), add
--mac-cpu arm64to avoid using emulation. This will generatehost_debug_unopt_arm64.
- On Apple Silicon ("M" chips), add
-
ninja -C out/ios_debug_unopt && ninja -C out/host_debug_unoptto build all artifacts (useout/ios_debug_sim_unoptfor Simulator).
See The flutter tool for instructions on how to use the flutter tool with a local engine.
You will typically use the ios_debug_unopt build to debug the engine on a device, and
ios_debug_sim_unopt to debug in on a simulator. Modifying dart sources in the engine will
require adding a dependency_override section in you app's pubspec.yaml as detailed
here.
See also instructions for debugging the engine in a Flutter app in Xcode.
Compiling for macOS or Linux
These steps build the desktop embedding, and the engine used by flutter test on a host workstation.
-
Make sure your engine code is up to date.
-
On macOS install Metal build tools:
xcodebuild -downloadComponent MetalToolchain -
./flutter/tools/gn --unoptimizedto prepare your build files.--unoptimizeddisables C++ compiler optimizations. On macOS, binaries are emitted unstripped; on Linux, unstripped binaries are emitted to anexe.unstrippedsubdirectory of the build.- For Apple Silicon, use
./flutter/tools/gn --unoptimized --mac-cpu=arm64.
-
ninja -C out/host_debug_unoptto build a desktop unoptimized binary.- If you skipped
--unoptimized, useninja -C out/host_debuginstead. - For Apple Silicon, use
ninja -C out/host_debug_unopt_arm64.
- If you skipped
See The flutter tool for instructions on how to use the flutter tool with a local engine.
You will typically use the host_debug_unopt build in this setup. Modifying dart sources in the engine will
require adding a dependency_override section in you app's pubspec.yaml as detailed
here.
If you have ccache installed on your system, you can enable this by using --ccache on gn in step 2 above.
This can speed up subsequent builds, especially when switching branches.
Compiling for Windows
Warning
You can only build selected binaries on Windows (mainly
gen_snapshotand the desktop embedding).
On Windows, ensure that the engine checkout is not deeply nested. This avoid the issue of the build scripts working with excessively long paths.
-
Make sure you have Visual Studio installed (non-Googlers only). Debugging Tools for Windows 10 must be installed.
-
Make sure your engine code is up to date.
-
Ensure long path support is enabled on your machine. Launch PowerShell as an administrator and run:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -Force
- If you are not a Google employee, you must set the following environment variables to point the depot tools at Visual Studio:
DEPOT_TOOLS_WIN_TOOLCHAIN=0
GYP_MSVS_OVERRIDE_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" # (or your location for Visual Studio)
WINDOWSSDKDIR="C:\Program Files (x86)\Windows Kits\10" # (or your location for Windows Kits)
Also, be sure that Python27 is before any other python in your Path.
-
switch to
engine/src/directory. -
python .\flutter\tools\gn --unoptimizedto prepare your build files.- If you are only building
gen_snapshot:python .\flutter\tools\gn [--unoptimized] --runtime-mode=[debug|profile|release] [--android].
- If you are only building
-
ninja -C .\out\<dir created by previous step>to build.- If you used a non-debug configuration, use
ninja -C .\out\<dir created by previous step> gen_snapshot. Release and profile are not yet supported for the desktop shell.
- If you used a non-debug configuration, use
Compiling for Fuchsia
Build components for Fuchsia
- Building fuchsia is only supported on linux. You need to update
engine/.gclient, or../.gclientif current directory isengine/src, withcustom_vars.
solutions = [
{
# ...
"custom_vars": {
"download_fuchsia_deps": True,
"run_fuchsia_emu": True,
},
},
]
You may ignore
"run_fuchsia_emu": Trueif you won't run tests locally.
Run gclient sync -D.
Warning
When running tests locally, you will also need kvm enabled, or nested virtualization on the gcloud VMs. Fuchsia and the tests will all be executed on the qemu.
- Prepare and build
./flutter/tools/gn --fuchsia --no-lto
- It will create a
out/fuchsia_debug_x64. - Use
--fuchsia-cpu arm64to build components for arm64. It will be created in a folderout/fuchsia_debug_arm64. - Use
--runtime-mode=releaseor--runtime-mode=profileto select other profiles as other platforms. - Ignore
--no-ltoto use lto or link-time optimization.
ninja -C out/fuchsia_debug_x64 -k 0
- It builds all but ignores known errors.
- Or specify following targets to avoid using
-k 0.
flutter/shell/platform/fuchsia:fuchsia \
flutter/shell/platform/fuchsia/dart_runner:dart_runner_tests \
fuchsia_tests
- Use
autoninjaif it's available. -C out/fuchsia_release_x64for release build; other configurations are similar with a different folder name inout/.
- Run all tests locally
python3 flutter/tools/fuchsia/with_envs.py flutter/testing/fuchsia/run_tests.py
- It runs the tests in
out/fuchsia_debug_x64by default. According to the configuration, it may take 5 minutes with regular gtest output to the terminal. - Add
fuchsia_release_x64at the end of the command for release build; other configurations are similar with a different folder name inout/.
python3 flutter/tools/fuchsia/with_envs.py flutter/testing/fuchsia/run_tests.py fuchsia_release_x64
Compiling for the Web
For building the engine for the Web we use the felt tool.
To test Flutter with a local build of the Web engine, add --local-web-sdk=wasm_release to your flutter command, e.g.:
flutter run --local-web-sdk=wasm_release -d chrome
flutter test --local-web-sdk=wasm_release test/path/to/your_test.dart
Compiling for the Web on Windows
Compiling the web engine might take a few extra steps on Windows. Use cmd.exe and "run as administrator".
- Make sure you have Visual Studio installed. Set the following environment variables. For Visual Studio use the path of the version you installed.
GYP_MSVS_OVERRIDE_PATH = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"GYP_MSVS_VERSION = 2017
- Make sure, depot_tools, ninja and python are installed and added to the path. Also set the following environment variable for depot tools:
DEPOT_TOOLS_WIN_TOOLCHAIN = 0- Tip: if you get a python error try to use Python 2 instead of 3
- Make sure your engine code is up to date.
- Tip: If you get a git authentication errors on this step try Git Bash instead
python .\flutter\tools\gn --unoptimized --full-dart-sdkto prepare your build files.ninja -C .\out\<dir created by previous step>to build.
To test Flutter with a local build of the Web engine, add --local-web-sdk=wasm_release to your flutter command, e.g.:
flutter run --local-web-sdk=wasm_release -d chrome
flutter test --local-web-sdk=wasm_release test/path/to/your_test.dart
For testing the engine again use felt tool this time with felt_windows.bat.
felt_windows.bat test
Compiling for testing
Dart tests
To run dart tests, build the engine:
flutter/tools/gn --unoptimized
ninja -C out/host_debug_unopt/
execute run_tests for native:
python3 flutter/testing/run_tests.py --type dart
and felt for web:
cd flutter/lib/web_ui
dev/felt test [test file]
Troubleshooting Compile Errors
Version Solving Failed
From time to time, as the Dart versions increase, you might see dependency errors such as:
The current Dart SDK version is 2.7.0-dev.0.0.flutter-1ef444139c.
Because ui depends on <a pub package> 1.0.0 which requires SDK version >=2.7.0 <3.0.0, version solving failed.
Running gclient sync does not update the tags, there are two solutions:
- under
engine/src/third_party/dartrungit fetch --tags origin - or run gclient sync with with tags parameter:
gclient sync --with_tags
See also: Debugging the engine, which includes instructions on running a Flutter app with a local engine.