Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT snapshots can't be found on some platforms when just the assets path is specified. #100640

Closed
akbiggs opened this issue Mar 23, 2022 · 6 comments
Assignees
Labels
c: proposal A detailed proposal for a change to Flutter e: embedder Users of the Embedder API engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project platform-linux Building on or for Linux specifically

Comments

@akbiggs
Copy link
Contributor

akbiggs commented Mar 23, 2022

The embedder does not appear to work with JIT snapshots on some platforms. In the GLFW example on Linux (which only sets FlutterProjectSettings.asset_path), we get an error that the Dart VM could not be initialized. With gn --unopt --build-embedder-examples:

% $ENGINE_DIR/out/host_debug_unopt/embedder_example $ENGINE_DIR/flutter/examples/glfw/myapp $ENGINE_DIR/third_party/icu/common/icudtl.dat 
[ERROR:flutter/runtime/dart_vm_data.cc(18)] VM snapshot invalid and could not be inferred from settings.
[ERROR:flutter/runtime/dart_vm.cc(269)] Could not set up VM data to bootstrap the VM from.
[ERROR:flutter/runtime/dart_vm_lifecycle.cc(84)] Could not create Dart VM instance.
[FATAL:flutter/shell/common/shell.cc(143)] Check failed: vm. Must be able to initialize the VM.
zsh: IOT instruction  $ENGINE_DIR/out/host_debug_unopt/embedder_example 

We suspect that this is not an issue on Windows and Mac because of this logic: https://github.com/flutter/engine/blob/main/runtime/dart_snapshot.cc#L72

A hack to fix this issue is to add these two lines here:

    settings.vm_snapshot_data_path =
        fml::paths::JoinPaths({settings.assets_path, "vm_snapshot_data"});
    settings.isolate_snapshot_data_path =
        fml::paths::JoinPaths({settings.assets_path,
        "isolate_snapshot_data"});

But we should add proper support to embedder.h.

@darshankawar darshankawar added in triage Presently being triaged by the triage team engine flutter/engine repository. See also e: labels. e: embedder Users of the Embedder API platform-linux Building on or for Linux specifically e: glfw GLFW desktop embedding c: proposal A detailed proposal for a change to Flutter and removed in triage Presently being triaged by the triage team labels Mar 24, 2022
@chinmaygarde
Copy link
Member

Specifying just the assets using FlutterProjectSettings.asset_path depends on the snapshots being present in known locations. I think your workaround to explicitly specify the snapshot assets is the right way to go.

I am going to retitle this issue as the current wording indicates that JIT snapshots aren't supported at all. When it looks like one use of the API is not able to resolve these snapshots.

@chinmaygarde chinmaygarde changed the title JIT snapshot support for Embedder JIT snapshots can Mar 28, 2022
@chinmaygarde chinmaygarde changed the title JIT snapshots can JIT snapshots can't be found on some platforms when just the assets path is specified. Mar 28, 2022
@chinmaygarde chinmaygarde added the P3 Issues that are less important to the Flutter project label Mar 28, 2022
@akbiggs
Copy link
Contributor Author

akbiggs commented Mar 28, 2022

Sorry, I'm having a hard time telling from the implementation: what do I set instead of just assets_path for JIT snapshots? The workaround requires changes to the Engine code itself, not my Embedder.

@akbiggs
Copy link
Contributor Author

akbiggs commented May 2, 2022

@chinmaygarde @iskakaushik Sorry to bother you. I was wondering how to use the current embedder API to resolve JIT snapshots as Chinmay mentioned above. Is there a way to modify the flutter::Settings using the embedder API? I thought that was private.

@betrevisan
Copy link

I launched the Flutter engine on Linux both when only specifying the assets path and when also explicitly specifying the snapshots. Both versions launched successfully on my end as the SearchMapping function was able to resolve the VM and the Isolate snapshots (https://github.com/flutter/engine/blob/5540f885a8064f72890d444ede44e3986c0a69c5/runtime/dart_snapshot.cc#L53). The difference was that, when explicitly specifying the snapshots, SearchMapping would return a file mapping whereas, when only the assets path was specified, it would return a symbol mapping after looking into the native library. Even though both seemed to work fine, I will be implementing a feature to allow users to explicitly specify snapshots. This is also to make the JIT mode be consistent with the existing AOT mode, which allows users to explicitly describe such paths.

@betrevisan
Copy link

This issue has been addressed in flutter/engine#34244, which allows users to explicitly specify the JIT snapshot locations using the embedder's project args.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: proposal A detailed proposal for a change to Flutter e: embedder Users of the Embedder API engine flutter/engine repository. See also e: labels. P3 Issues that are less important to the Flutter project platform-linux Building on or for Linux specifically
Projects
None yet
Development

No branches or pull requests

6 participants