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

Rebase 3.16.9 #77

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,10 @@ group("flutter") {

# path_ops
"//flutter/tools/path_ops",
]

if (host_os == "linux") {
public_deps += [
# Built alongside gen_snapshot for 64 bit targets
"//third_party/dart/runtime/bin:analyze_snapshot",
]
}
# Built alongside gen_snapshot arm64 targets.
"//third_party/dart/runtime/bin:analyze_snapshot",
]

if (full_dart_sdk) {
public_deps += [ "//flutter/web_sdk" ]
Expand Down Expand Up @@ -165,6 +161,7 @@ group("unittests") {
"//flutter/runtime:no_dart_plugin_registrant_unittests",
"//flutter/runtime:runtime_unittests",
"//flutter/shell/common:shell_unittests",
"//flutter/shell/common/shorebird:shorebird_unittests",
"//flutter/shell/platform/embedder:embedder_a11y_unittests",
"//flutter/shell/platform/embedder:embedder_proctable_unittests",
"//flutter/shell/platform/embedder:embedder_unittests",
Expand Down Expand Up @@ -287,3 +284,19 @@ if (host_os == "win") {
outputs = [ "$root_build_dir/gen_snapshot/gen_snapshot.exe" ]
}
}

# A top-level target for analyze_snapshot, modeled after the gen_snapshot
# target above.
if (host_os == "win") {
_analyze_snapshot_target =
"//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)"

copy("analyze_snapshot") {
deps = [ _analyze_snapshot_target ]

analyze_snapshot_out_dir =
get_label_info(_analyze_snapshot_target, "root_out_dir")
sources = [ "$analyze_snapshot_out_dir/analyze_snapshot.exe" ]
outputs = [ "$root_build_dir/analyze_snapshot/analyze_snapshot.exe" ]
}
}
12 changes: 10 additions & 2 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ vars = {
'ocmock_git': 'https://github.com/erikdoe/ocmock.git',
'skia_revision': '795ed944ff5bde5916d193824589d3bacfa61a7d',

'dart_sdk_revision': '041c44649d5d43de8fa01a8d17539d84be69634d',
'dart_sdk_git': 'git@github.com:shorebirdtech/dart-sdk.git',
'updater_git': 'https://github.com/shorebirdtech/updater.git',
'updater_rev': 'ed013eb257b63e4a70c8bcb656bbb5ecd8dff4b5',

# WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY
# See `lib/web_ui/README.md` for how to roll CanvasKit to a new version.
'canvaskit_cipd_instance': '61aeJQ9laGfEFF_Vlc_u0MCkqB6xb2hAYHRBxKH-Uw4C',
Expand Down Expand Up @@ -262,7 +267,7 @@ allowed_hosts = [
]

deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'f27d99b4428dea312646130d60c33a2d38fa9dc6',
'src': 'https://github.com/shorebirdtech/buildroot.git' + '@' + '2c3c95dc8cdb71fa176fe2e7886ef2022cbdc3bb',

# Fuchsia compatibility
#
Expand Down Expand Up @@ -329,7 +334,7 @@ deps = {
Var('fuchsia_git') + '/protobuf-gn' + '@' + Var('dart_protobuf_gn_rev'),

'src/third_party/dart':
Var('dart_git') + '/sdk.git' + '@' + Var('dart_revision'),
Var('dart_sdk_git') + '@' + Var('dart_sdk_revision'),

# WARNING: Unused Dart dependencies in the list below till "WARNING:" marker are removed automatically - see create_updated_flutter_deps.py.

Expand Down Expand Up @@ -595,6 +600,9 @@ deps = {
'src/third_party/ocmock':
Var('ocmock_git') + '@' + Var('ocmock_rev'),

'src/third_party/updater':
Var('updater_git') + '@' + Var('updater_rev'),

'src/third_party/libjpeg-turbo':
Var('fuchsia_git') + '/third_party/libjpeg-turbo' + '@' + '0fb821f3b2e570b2783a94ccd9a2fb1f4916ae9f',

Expand Down
13 changes: 12 additions & 1 deletion build/archives/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,25 @@ if (is_mac) {
}

if (host_os == "win") {
# This rule archives both gen_snapshot *and* analyze_snapshot. The name is
# misleading. We (shorebird) have updated this rule to include
# analyze_snapshot but did not update the name because it is referenced
# elsewhere in the tooling.
zip_bundle("archive_win_gen_snapshot") {
deps = [ "//flutter:gen_snapshot" ]
deps = [
"//flutter:analyze_snapshot",
"//flutter:gen_snapshot",
]
output = "$full_target_platform_name-$flutter_runtime_mode/windows-x64.zip"
files = [
{
source = "$root_out_dir/gen_snapshot/gen_snapshot.exe"
destination = "gen_snapshot.exe"
},
{
source = "$root_out_dir/analyze_snapshot/analyze_snapshot.exe"
destination = "analyze_snapshot.exe"
},
]
}
}
27 changes: 25 additions & 2 deletions lib/snapshot/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ group("generate_snapshot_bins") {
deps += [ ":create_macos_gen_snapshots" ]
} else if (host_os == "mac" &&
(target_cpu == "arm" || target_cpu == "arm64")) {
deps += [ ":create_arm_gen_snapshot" ]
deps += [
":create_arm_analyze_snapshot",
":create_arm_gen_snapshot",
]
}

# Build analyze_snapshot for 64-bit target CPUs.
if (host_os == "linux" && (target_cpu == "x64" || target_cpu == "arm64")) {
if (target_cpu == "arm64") {
deps +=
[ "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)" ]
}
Expand Down Expand Up @@ -270,6 +273,26 @@ if (host_os == "mac" && target_os != "mac" &&
deps = [ "//third_party/dart/runtime/bin:gen_snapshot($host_toolchain)" ]
visibility = [ ":*" ]
}

copy("create_arm_analyze_snapshot") {
# The toolchain-specific output directory. For cross-compiles, this is a
# clang-x64 or clang-arm64 subdirectory of the top-level build directory.
host_output_dir = get_label_info(
"//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)",
"root_out_dir")

# Determine suffixed output gen_snapshot name.
target_cpu_suffix = target_cpu
if (target_cpu == "arm") {
target_cpu_suffix = "armv7"
}

sources = [ "${host_output_dir}/analyze_snapshot" ]
outputs = [ "${host_output_dir}/analyze_snapshot_${target_cpu_suffix}" ]
deps =
[ "//third_party/dart/runtime/bin:analyze_snapshot($host_toolchain)" ]
visibility = [ ":*" ]
}
}

# Creates a `gen_snapshot` binary suffixed with the target CPU architecture.
Expand Down
105 changes: 83 additions & 22 deletions runtime/dart_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <sstream>

#include <third_party/dart/runtime/bin/elf_loader.h>
#include "flutter/fml/native_library.h"
#include "flutter/fml/paths.h"
#include "flutter/fml/trace_event.h"
Expand Down Expand Up @@ -56,33 +57,93 @@ static std::shared_ptr<const fml::Mapping> SearchMapping(
const std::vector<std::string>& native_library_path,
const char* native_library_symbol_name,
bool is_executable) {
// Ask the embedder. There is no fallback as we expect the embedders (via
// their embedding APIs) to just specify the mappings directly.
if (embedder_mapping_callback) {
// Note that mapping will be nullptr if the mapping callback returns an
// invalid mapping. If all the other methods for resolving the data also
// fail, the engine will stop with accompanying error logs.
if (auto mapping = embedder_mapping_callback()) {
return mapping;
#if FML_OS_IOS
// Detect when we're trying to load a Shorebird patch.
auto patch_path = native_library_path.front();
bool is_patch = patch_path.find(".vmcode") != std::string::npos;
if (is_patch) {
// We use this terrible hack to load in the patch and then extract the
// symbols from it when the path is not App.framework/App but rather
// foo.vmcode, etc. We read the symbols into static variables, but then I
// believe we need to hold onto the ELF itself, otherwise the symbols
// become invalid.
// "leaked_elf" is meant to indicate that we're not freeing the ELF.
static Dart_LoadedElf* leaked_elf = nullptr;
// The VM Snapshot is identical for all binaries produced by a given version
// of Dart. Our linker checks this and will fail to link if ever the VM
// snapshot changes.
const uint8_t* ignored_vm_data = nullptr;
const uint8_t* ignored_vm_instrs = nullptr;
static const uint8_t* isolate_data = nullptr;
static const uint8_t* isolate_instrs = nullptr;
if (leaked_elf == nullptr) {
const char* error = nullptr;
// vmcode files are elf files prefixed with a shorebird linker header.
auto elf_mapping = GetFileMapping(patch_path, false /* executable */);
int elf_file_offset = Shorebird_ReadLinkHeader(elf_mapping->GetMapping(),
elf_mapping->GetSize());

leaked_elf = Dart_LoadELF(patch_path.c_str(), elf_file_offset, &error,
&ignored_vm_data, &ignored_vm_instrs,
&isolate_data, &isolate_instrs,
/* load as read-only, not rx */ false);
if (leaked_elf != nullptr) {
FML_LOG(INFO) << "Loaded ELF";
} else {
FML_LOG(FATAL) << "Failed to load ELF at " << patch_path
<< " error: " << error;
abort();
}
}
}

// Attempt to open file at path specified.
if (!file_path.empty()) {
if (auto file_mapping = GetFileMapping(file_path, is_executable)) {
return file_mapping;
FML_LOG(INFO) << "Loading symbol from ELF " << native_library_symbol_name;

if (native_library_symbol_name == DartSnapshot::kIsolateDataSymbol) {
return std::make_unique<const fml::NonOwnedMapping>(isolate_data, 0,
nullptr, true);
} else if (native_library_symbol_name ==
DartSnapshot::kIsolateInstructionsSymbol) {
return std::make_unique<const fml::NonOwnedMapping>(isolate_instrs, 0,
nullptr, true);
}
// Fall through to normal lookups for VM data and instructions.
// This fallthrough depends on the fact that NativeLibrary below can't
// read the ELF out of our .vmcode files.
} else {
// Only try to open the file if we're not loading a patch.
#endif

// Ask the embedder. There is no fallback as we expect the embedders (via
// their embedding APIs) to just specify the mappings directly.
if (embedder_mapping_callback) {
// Note that mapping will be nullptr if the mapping callback returns an
// invalid mapping. If all the other methods for resolving the data also
// fail, the engine will stop with accompanying error logs.
if (auto mapping = embedder_mapping_callback()) {
return mapping;
}
}
}

// Look in application specified native library if specified.
for (const std::string& path : native_library_path) {
auto native_library = fml::NativeLibrary::Create(path.c_str());
auto symbol_mapping = std::make_unique<const fml::SymbolMapping>(
native_library, native_library_symbol_name);
if (symbol_mapping->GetMapping() != nullptr) {
return symbol_mapping;
// Attempt to open file at path specified.
if (!file_path.empty()) {
if (auto file_mapping = GetFileMapping(file_path, is_executable)) {
return file_mapping;
}
}
}

// Look in application specified native library if specified.
for (const std::string& path : native_library_path) {
auto native_library = fml::NativeLibrary::Create(path.c_str());
auto symbol_mapping = std::make_unique<const fml::SymbolMapping>(
native_library, native_library_symbol_name);
if (symbol_mapping->GetMapping() != nullptr) {
return symbol_mapping;
}
}

#if FML_OS_IOS
} // !is_patch
#endif

// Look inside the currently loaded process.
{
Expand Down
2 changes: 2 additions & 0 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ source_set("common") {
"//third_party/skia",
]

include_dirs = [ "//flutter/updater" ]

if (impeller_supports_rendering) {
sources += [
"snapshot_controller_impeller.cc",
Expand Down
10 changes: 10 additions & 0 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include "third_party/skia/include/utils/SkBase64.h"
#include "third_party/tonic/common/log.h"

#include "third_party/updater/library/include/updater.h"

namespace flutter {

constexpr char kSkiaChannel[] = "flutter/skia";
Expand Down Expand Up @@ -425,6 +427,14 @@ Shell::Shell(DartVMRef vm,
volatile_path_tracker_(std::move(volatile_path_tracker)),
weak_factory_gpu_(nullptr),
weak_factory_(this) {
// FIXME: This is probably the wrong place to hook into.
#if FML_OS_ANDROID || FML_OS_IOS
if (!vm_) {
shorebird_report_launch_failure();
} else {
shorebird_report_launch_success();
}
#endif
FML_CHECK(!settings.enable_software_rendering || !settings.enable_impeller)
<< "Software rendering is incompatible with Impeller.";
FML_CHECK(vm_) << "Must have access to VM to create a shell.";
Expand Down
55 changes: 55 additions & 0 deletions shell/common/shorebird/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import("//flutter/common/config.gni")
import("//flutter/testing/testing.gni")

source_set("snapshots_data_handle") {
sources = [
"snapshots_data_handle.cc",
"snapshots_data_handle.h",
]

deps = [
"//flutter/fml",
"//flutter/runtime",
"//flutter/runtime:libdart",
"//flutter/shell/common",
]
}

source_set("shorebird") {
sources = [
"shorebird.cc",
"shorebird.h",
]

deps = [
":snapshots_data_handle",
"//flutter/fml",
"//flutter/runtime",
"//flutter/runtime:libdart",
"//flutter/shell/common",
]

include_dirs = [ "//flutter/updater" ]
}

if (enable_unittests) {
test_fixtures("shorebird_fixtures") {
fixtures = []
}

executable("shorebird_unittests") {
testonly = true

sources = [ "snapshots_data_handle_unittests.cc" ]

# This only includes snapshots_data_handle and not shorebird because
# shorebird fails to link due to a missing updater lib.
deps = [
":shorebird_fixtures",
":snapshots_data_handle",
"//flutter/runtime",
"//flutter/testing",
"//flutter/testing:fixture_test",
]
}
}
Loading