Setting Up Your Own Local Copy of the Flutter Engine

Local Flutter Engine

Below are some links which provide an overview of the Dart/Flutter platform and compilation system.
  1. Architectural Overview - https://flutter.dev/docs/resources/architectural-overview
  2. FAQ - https://flutter.dev/docs/resources/faq
  3. Dart Overview - https://dart.dev/overview
  4. Optimizing Compiler for Dart - https://www.youtube.com/watch?v=xdMTNDMQw0A
  5. Dart AOT and JIT - https://www.youtube.com/watch?v=NoVYI94MJio 
  6. gclient - https://www.chromium.org/developers/how-tos/depottools 
  7. Compiling the flutter engine - https://github.com/flutter/flutter/wiki/Compiling-the-engine#compiling-for-macos-or-linux 
  8. Dart on LLVM - https://medium.com/dartlang/dart-on-llvm-b82e83f99a70
Note: dart has an JIT build chain and a AOT build chain. One is targeted for app development and the other is targeted for app release. The frontend language changes will need to be compatible in both. The assumption is that as long as I target existing AST structures/patterns (the dart Kernel), the compilation language won't matter.

This is the main article I used to get myself compiling against a custom flutter engine.

export PATH=$HOME/dev/chromium.googlesource.com/chromium/tools/depot_tools:$PATH

gclient sync

Running these commands will check the flutter engine with the appropriate dependencies. The next step is to run a sample project using my local flutter engine. The intuition is that patching the flutter engine will allow embedding extra language keywords and other languages.

Using a Custom Dark SDK

Looking for Dart mirrors to find where language is compiled to AST

Building an App using the Local Engine

I ran the flutter help command and looked for a local engine configuration option.

$ flutter help -v
Manage

Local build selection options (not normally required):
    --local-engine-src-path     Path to your engine src directory, if you are building Flutter locally.
                                Defaults to $FLUTTER_ENGINE if set, otherwise defaults to the path given in your pubspec.yaml dependency_overrides for sky_engine, if any.
    --local-engine              Name of a build output within the engine out directory, if you are building Flutter locally.
                                Use this to select a specific version of the engine if you have built multiple engine targets.
                                This path is relative to "--local-engine-src-path" or "--local-engine-src-out" (q.v.).

I'm not understanding fully why I must build/prepare my local flutter engine for each flavor/version before invoking. Also, I need to set a local dependency if "Additionally if you‘ve modified dart sources in flutter/engine" which sounds like someone would almost always need to set this configuration option.


(Assumption): It looks like the gn command prepares the necessary directory to be ready to build the artifacts specified in the directory. Ninja is used to prepare the artifacts and can take multiple targets.

$ ./flutter/tools/gn --unoptimized                                                  $ ninja -C out/ios_debug_sim_unopt -C out/ios_debug_unopt -C out/host_debug_unopt


I changed the pubspec.yaml to use local sky engine, but no sky services because it didn't exist in the out directory. I removed sky services and ran pub get, it passed.

I needed to run flutter clean and now I'm getting a compilation exception. I seem to have gotten farther. I should checkout version 2.0.5 of flutter and see if that can compile locally. It doesn't have github tags but the flutter --version command prints the engine revision: 241c87ad80. I'm testing with that.

Possible workflow after patching the flutter engine
$ ./flutter/tools/gn --unoptimized
$ ./flutter/tools/gn --ios --simulator --unoptimized                                  $ ./flutter/tools/gn --ios --unoptimized                                                                                                            
$ ninja -C out/ios_debug_sim_unopt -C out/ios_debug_unopt -C out/host_debug_unopt

Same error in compilation:

Unhandled exception:
Crash when compiling file:///usr/local/Caskroom/flutter/2.0.5/flutter/packages/flutter/lib/src/widgets/widget_inspector.dart,
at character offset 26515:
Bad state: No element
#0      List.single (dart:core-patch/growable_array.dart:342:22)
#1      ClassBuilderImpl.buildTypesWithBuiltArguments (package:front_end/src/fasta/builder/class_builder.dart:561:43)
#2      ClassBuilderImpl.buildType (package:front_end/src/fasta/builder/class_builder.dart:616:12)
#3      NamedTypeBuilder.build (package:front_end/src/fasta/builder/named_type_builder.dart:261:40)
#4      FunctionTypeBuilder.build (package:front_end/src/fasta/builder/function_type_builder.dart:83:21)
#5      BodyBuilder.buildDartType (package:front_end/src/fasta/kernel/body_builder.dart:6563:11)
#6      BodyBuilder.endFormalParameter (package:front_end/src/fasta/kernel/body_builder.dart:3641:7)
#7      Parser.parseFormalParameter (package:_fe_analyzer_shared/src/parser/parser_impl.dart:1720:14)
#8      Parser.parseOptionalNamedParameters (package:_fe_analyzer_shared/src/parser/parser_impl.dart:1792:11)
#9      Parser.parseFormalParametersRest (package:_fe_analyzer_shared/src/parser/parser_impl.dart:1378:17)
#10     Parser.parseFormalParameters (package:_fe_analyzer_shared/src/parser/parser_impl.dart:1352:12)
#11     Parser.parseFormalParametersOpt (package:_fe_analyzer_shared/src/parser/parser_impl.dart:1312:15)
#12     DietListener.buildFunctionBody (package:front_end/src/fasta/source/diet_listener.dart:973:22)
#13     DietListener._endClassMethod (package:front_end/src/fasta/source/diet_listener.dart:711:5)
#14     DietListener.endMixinMethod (package:front_end/src/fasta/source/diet_listener.dart:676:5)
#15     Parser.parseMethod (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3991:20)
#16     Parser.parseClassOrMixinOrExtensionMemberImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3723:15)
#17     Parser.parseClassOrMixinOrExtensionBody (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3382:15)
#18     Parser.parseMixin (package:_fe_analyzer_shared/src/parser/parser_impl.dart:2188:13)
#19     Parser.parseTopLevelKeywordDeclaration (package:_fe_analyzer_shared/src/parser/parser_impl.dart:620:18)
#20     Parser.parseTopLevelDeclarationImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:477:14)
#21     Parser.parseUnit (package:_fe_analyzer_shared/src/parser/parser_impl.dart:357:15)
#22     SourceLoader.buildBody (package:front_end/src/fasta/source/source_loader.dart:480:14)
And removing the links to the sky_engine and sky_services in the dependency overrides.

Comments

Popular posts from this blog

Adding a New Keyword to the Dart Language

Discovering How to Extend the Dart Language