| flutter-embedder.git |
| ======================================= |
| |
| The Flutter Embedder for Fuchsia is a new in-progress runtime for Flutter apps |
| on Fuchsia. This runtime is built on top of Flutter's |
| [embedder platform](https://github.com/flutter/flutter/wiki/Custom-Flutter-Engine-Embedders). |
| |
| This repository is a work in progress and should be considered |
| experimental. |
| |
| ## Requirements |
| |
| If you're using WSL2 (Windows Subsystem for Linux), see |
| [SETUP_WINDOWS.md](https://fuchsia.googlesource.com/flutter-embedder/+/refs/heads/main/SETUP_WINDOWS.md) |
| first. |
| |
| 1. Set `$FUCHSIA_EMBEDDER_DIR` to your flutter-embedder.git checkout location, |
| for example `~/flutter-embedder`. |
| |
| ```sh |
| export FUCHSIA_EMBEDDER_DIR=$HOME/flutter-embedder |
| ``` |
| |
| 2. Bootstrap the repository's dependencies: |
| |
| ```sh |
| $FUCHSIA_EMBEDDER_DIR/scripts/bootstrap.sh |
| ``` |
| |
| This script initializes tools (including `bazel` and `ffx`), installs some Git |
| hooks and downloads the `workstation_eng.qemu-x64` product bundle, which you can |
| use to run the examples below. |
| |
| ## Run an example app |
| |
| 1. Start the emulator. |
| |
| If running in a graphical environment: |
| |
| ```sh |
| $FUCHSIA_EMBEDDER_DIR/tools/ffx emu start workstation_eng.qemu-x64 |
| ``` |
| |
| If running in a terminal environment: |
| |
| ```sh |
| $FUCHSIA_EMBEDDER_DIR/tools/ffx emu start --headless workstation_eng.qemu-x64 |
| ``` |
| |
| 2. Set the default target in ffx to be `fuchsia-emulator`: |
| |
| ```sh |
| $FUCHSIA_EMBEDDER_DIR/tools/ffx target default set fuchsia-emulator |
| ``` |
| |
| 3. (optional) Watch the device log in a separate window: |
| |
| ```sh |
| $FUCHSIA_EMBEDDER_DIR/tools/ffx log |
| ``` |
| |
| 4. Run an example app: |
| |
| ```sh |
| $FUCHSIA_EMBEDDER_DIR/scripts/build_and_run_example.sh hello_flutter |
| ``` |
| |
| **TODO(akbiggs): The app occasionally gets stuck on a loading screen |
| instead of rendering. Re-running the app usually fixes it. We need to |
| fix this.** |
| |
| ## Syncing engine artifacts |
| |
| Occasionally you will need to update the Flutter Engine artifacts (`embedder.h` and |
| `libengine_flutter.so`) that are used by the embedder to run Flutter apps. A script |
| is provided for this workflow. |
| |
| ### Requirements |
| |
| 1. You will |
| [need to get the Flutter Engine source code](https://github.com/flutter/flutter/wiki/Setting-up-the-Engine-development-environment). |
| **Note that this is not just cloning https://github.com/flutter/engine.** |
| |
| 2. Set `$ENGINE_DIR` to the `src` folder of your Flutter Engine checkout location, |
| for example `~/engine/src`. |
| |
| 3. `$DEPOT_TOOLS` should be set to your |
| [`depot_tools`](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up) |
| location, for example `~/depot_tools`. |
| |
| 4. For `sync_engine_artifacts_to_revision.sh`, you will need to `git stash` or `git commit` any local |
| changes to the Flutter Engine. This is not necesssary for `build_and_copy_engine_artifacts.sh`. |
| |
| ### Running the script |
| |
| You can run the script with a `flutter/engine` Git commit to sync the Engine artifacts to |
| that revision. |
| |
| ```sh |
| $FUCHSIA_EMBEDDER_DIR/scripts/sync_engine_artifacts_to_revision.sh <ENGINE_COMMIT_SHA> |
| ``` |
| |
| A common workflow is to sync your Engine commit to the Flutter tool in this repository, |
| for example when updating the Flutter tool to a new version. To do this: |
| |
| ```sh |
| $FUCHSIA_EMBEDDER_DIR/scripts/sync_engine_artifacts_to_revision.sh $(cat $FUCHSIA_EMBEDDER_DIR/third_party/dart-pkg/internal/flutter/flutter/bin/internal/engine.version) |
| ``` |
| |
| If you want to test local changes to the Engine, you can run `build_and_copy_engine_artifacts.sh` |
| instead, which simply builds and copies your Engine into `$FUCHSIA_EMBEDDER_DIR`. |
| |
| ```sh |
| $FUCHSIA_EMBEDDER_DIR/scripts/build_and_copy_engine_artifacts.sh |
| ``` |
| |
| ## Uploading changes for review |
| |
| flutter-embedder reviews are handled using Gerrit at https://fuchsia-review.googlesource.com, which uses a single commit per |
| code review. See |
| [this guide](https://fuchsia.dev/fuchsia-src/development/source_code/contribute_changes) |
| for an intro to Gerrit. |
| |
| An alternative Gerrit workflow is a branchless workflow where you do all your work |
| from `origin/main` without creating new branches. We describe such a workflow below, |
| but it's not mandatory, it's just provided as an example. |
| |
| An example branchless workflow for creating a new change is: |
| |
| ```sh |
| # Start work from an up-to-date main branch. |
| git fetch origin |
| git checkout origin/main |
| # Modify some files... |
| ... |
| # Stage and commit your changes. |
| git add file1.cc file2.h |
| git commit -m "[embedder] My cool new feature." |
| # Upload for review. |
| git push origin HEAD:refs/for/main |
| ``` |
| |
| An example branchless workflow to apply feedback during a code review is: |
| |
| 1. Visit https://fuchsia-review.googlesource.com and find your change. |
| 2. Select `... > Download patch > Checkout` and copy the command. |
| 3. Run the following commands: |
| |
| ```sh |
| # Start from main with your change on top. |
| <paste the command you copied above> |
| # Make some changes to some files to apply the feedback... |
| ... |
| # Stage and amend your changes to your commit. |
| git add file1.cc file2.h |
| git commit --amend |
| # Upload your updated change for review. |
| git push origin HEAD:refs/for/main |
| ``` |
| |
| An example branchless workflow to create a chain of changes is: |
| |
| ```sh |
| # Start work from an up-to-date main branch. |
| git fetch origin |
| git checkout origin/main |
| # Modify some files... |
| ... |
| # Stage and commit your changes. |
| git add file1.cc file2.h |
| git commit -m "[embedder] My cool new feature 1." |
| # Upload for review. |
| git push origin HEAD:refs/for/main |
| # Do some more work on top of your cool new feature. |
| git add file3.cc file4.h |
| git commit -m "[embedder] My cool new feature 2." |
| # Create a second code review for your second feature. |
| # The second code review will only show changes for |
| # your second feature and it will indicate that it is based on |
| # top of the first feature. |
| git push origin HEAD:refs/for/main |
| ``` |
| |
| A branchless workflow comes with some benefits: |
| |
| 1. It reduces the amount of local branches you have to track. |
| 2. It reduces the amount of local branches you have to clean up after submission. |
| 3. It reduces the amount of overhead to starting new work (just `git checkout origin/main`). |
| |
| However a branchless workflow also prevents you from storing multiple |
| chains of commits locally. Uploading your changes to https://fuchsia-review.googlesource.com |
| frequently can help address that problem, as https://fuchsia-review.googlesource.com then |
| acts as the storage for each of your ongoing changes. This also keeps your changes in a |
| state where they're easy to share and hand off to other people. |