Skip to content

Commit

Permalink
feat: upgrade engine to Flutter 3.16.3
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Dec 11, 2023
2 parents 54a7145 + 0757a90 commit 72aad83
Show file tree
Hide file tree
Showing 20 changed files with 563 additions and 39 deletions.
26 changes: 19 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 @@ -286,3 +282,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': '072a1dacbcf3522ee8a0e7043436b500c0cbbef9',
'dart_sdk_git': 'git@github.com:shorebirdtech/dart-sdk.git',
'updater_git': 'https://github.com/shorebirdtech/updater.git',
'updater_rev': 'd785568094c176d956ccf7ae918bf8d64c0d09b7',

# 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"
},
]
}
}
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_third_party
Original file line number Diff line number Diff line change
Expand Up @@ -61899,4 +61899,8 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
====================================================================================================

<<<<<<< HEAD
Total license count: 868
=======
Total license count: 888
>>>>>>> shorebird/dev
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
12 changes: 12 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,16 @@ 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. Currently we only
// link the shorebird updater on Android, so if we don't guard this other
// non-android targets (e.g. flutter_tester) will fail to link.
#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
Loading

0 comments on commit 72aad83

Please sign in to comment.