Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vars = {
"dart_sdk_revision": "5c6f8122c1ee85f833ea3b69b3b85dc07303e8d2",
"dart_sdk_git": "git@github.com:shorebirdtech/dart-sdk.git",
"updater_git": "https://github.com/shorebirdtech/updater.git",
"updater_rev": "71b5ed65fab03fcf241edf0c74d027de9998da51",
"updater_rev": "ba52a62b5d1b064cce363ef98c6165b1e2f78059",

# WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY
# See `lib/web_ui/README.md` for how to roll CanvasKit to a new version.
Expand Down
4 changes: 4 additions & 0 deletions common/config.gni
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ if (is_ios || is_mac || is_android || is_win) {
feature_defines_list += [ "SHOREBIRD_PLATFORM_SUPPORTED=1" ]
}

if (is_ios) {
feature_defines_list += [ "SHOREBIRD_USE_INTERPRETER=1" ]
}

if (is_ios || is_mac) {
flutter_cflags_objc = [
"-Werror=overriding-method-mismatch",
Expand Down
4 changes: 2 additions & 2 deletions runtime/dart_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ 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) {
#if FML_OS_IOS || FML_OS_MACOSX
#if SHOREBIRD_USE_INTERPRETER
// 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;
Expand Down Expand Up @@ -141,7 +141,7 @@ static std::shared_ptr<const fml::Mapping> SearchMapping(
}
}

#if FML_OS_IOS || FML_OS_MACOSX
#if SHOREBIRD_USE_INTERPRETER
} // !is_patch
#endif

Expand Down
20 changes: 2 additions & 18 deletions shell/common/shorebird/shorebird.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ bool ConfigureShorebird(const ShorebirdConfigArgs& args,
// within Dart, including updating as part of login, etc.
// https://github.com/shorebirdtech/shorebird/issues/950

// We only set the base snapshot on iOS for now.
// TODO: this won't compile as we don't have a settings object here.
// #if FML_OS_IOS || FML_OS_MACOSX
// SetBaseSnapshot(settings);
// #endif

FML_LOG(INFO) << "Checking for active patch";
char* c_active_path = shorebird_next_boot_patch_path();
if (c_active_path != NULL) {
Expand Down Expand Up @@ -172,16 +166,6 @@ bool ConfigureShorebird(const ShorebirdConfigArgs& args,
return true;
}

void ConfigureShorebird(const ShorebirdFlutterProjectArgs& args,
Settings& settings) {
// cache_path is used for both code_cache and app_storage, as we don't persist
// any data between releases. args.app_path is appended to
// the settings.application_library_path vector at this function's call site.
ConfigureShorebird(args.cache_path, args.cache_path, settings,
args.shorebird_yaml_contents, args.app_version,
args.app_build_number);
}

void ConfigureShorebird(std::string code_cache_path,
std::string app_storage_path,
Settings& settings,
Expand Down Expand Up @@ -239,7 +223,7 @@ void ConfigureShorebird(std::string code_cache_path,
// https://github.com/shorebirdtech/shorebird/issues/950

// We only set the base snapshot on iOS for now.
#if FML_OS_IOS || FML_OS_MACOSX
#if SHOREBIRD_USE_INTERPRETER
SetBaseSnapshot(settings);
#endif

Expand All @@ -249,7 +233,7 @@ void ConfigureShorebird(std::string code_cache_path,
shorebird_free_string(c_active_path);
FML_LOG(INFO) << "Shorebird updater: active path: " << active_path;

#if FML_OS_IOS || FML_OS_MACOSX
#if SHOREBIRD_USE_INTERPRETER
// On iOS we add the patch to the front of the list instead of clearing
// the list, to allow dart_shapshot.cc to still find the base snapshot
// for the vm isolate.
Expand Down
3 changes: 0 additions & 3 deletions shell/common/shorebird/shorebird.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ struct ShorebirdConfigArgs {
bool ConfigureShorebird(const ShorebirdConfigArgs& args,
std::string& patch_path);

void ConfigureShorebird(const ShorebirdFlutterProjectArgs& args,
Settings& settings);

void ConfigureShorebird(std::string code_cache_path,
std::string app_storage_path,
Settings& settings,
Expand Down
1 change: 1 addition & 0 deletions shell/platform/darwin/macos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ source_set("flutter_framework_source") {
":macos_gpu_configuration",
"//flutter/flow:flow",
"//flutter/fml",
"//flutter/shell/common/shorebird",
"//flutter/shell/platform/common:common_cpp_accessibility",
"//flutter/shell/platform/common:common_cpp_enums",
"//flutter/shell/platform/common:common_cpp_input",
Expand Down
79 changes: 51 additions & 28 deletions shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "flutter/common/constants.h"
#include "flutter/fml/paths.h"
#include "flutter/shell/common/shorebird/shorebird.h"
#include "flutter/shell/platform/common/app_lifecycle_state.h"
#include "flutter/shell/platform/common/engine_switches.h"
#include "flutter/shell/platform/embedder/embedder.h"
Expand Down Expand Up @@ -585,6 +586,40 @@ - (void)dealloc {
}
}

- (BOOL)configureShorebird:(NSString**)patchPath {
NSLog(@"[shorebird] setting up non-linker shorebird");
NSString* bundlePath =
[[NSBundle bundleWithURL:[NSBundle.mainBundle.privateFrameworksURL
URLByAppendingPathComponent:@"App.framework"]] bundlePath];
bundlePath = [bundlePath stringByAppendingString:@"/App"];
NSString* assetsPath = _project.assetsPath;
NSURL* shorebirdYamlPath = [NSURL URLWithString:@"shorebird.yaml"
relativeToURL:[NSURL fileURLWithPath:assetsPath]];
NSString* shorebirdYamlContents = [NSString stringWithContentsOfURL:shorebirdYamlPath
encoding:NSUTF8StringEncoding
error:nil];
NSString* appVersion =
[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString* appBuildNumber = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
std::string cache_path =
fml::paths::JoinPaths({getenv("HOME"), "Library", "Application Support", "shorebird"});
flutter::ReleaseVersion release_version = {appVersion.UTF8String, appBuildNumber.UTF8String};
flutter::ShorebirdConfigArgs shorebird_args(cache_path, cache_path, bundlePath.UTF8String,
shorebirdYamlContents.UTF8String, release_version);
NSLog(@"[shorebird] calling ConfigureShorebird");
std::string patch_path;
auto res = flutter::ConfigureShorebird(shorebird_args, patch_path);
if (!res) {
NSLog(@"[shorebird] ConfigureShorebird failed");
return NO;
}

NSLog(@"[shorebird] ConfigureShorebird success!");
*patchPath = [NSString stringWithUTF8String:patch_path.c_str()];
NSLog(@"[shorebird] patchPath: %@", *patchPath);
return YES;
}

- (BOOL)runWithEntrypoint:(NSString*)entrypoint {
if (self.running) {
return NO;
Expand Down Expand Up @@ -663,7 +698,19 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
.thread_priority_setter = SetThreadPriority};
flutterArguments.custom_task_runners = &custom_task_runners;

[self loadAOTData:_project.assetsPath];
NSString* elfPath;
BOOL configureShorebirdRes = [self configureShorebird:&elfPath];
if (!configureShorebirdRes) {
// No patch exists, or we failed to configure shorebird. This is a fallback.
// Upstream, this code lives in -(void)loadAOTData:.
//
// This is the location where the test fixture places the snapshot file.
// For applications built by Flutter tool, this is in "App.framework".
elfPath = [NSString pathWithComponents:@[ _project.assetsPath, @"app_elf_snapshot.so" ]];
}

[self loadAOTData:elfPath];

if (_aotData) {
flutterArguments.aot_data = _aotData;
}
Expand All @@ -680,29 +727,8 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
[engine onVSync:baton];
};

NSString* bundlePath =
[[NSBundle bundleWithURL:[NSBundle.mainBundle.privateFrameworksURL
URLByAppendingPathComponent:@"App.framework"]] bundlePath];
bundlePath = [bundlePath stringByAppendingString:@"/App"];
flutterArguments.shorebird_args.app_path = bundlePath.UTF8String;
NSString* assetsPath = _project.assetsPath;
NSURL* shorebirdYamlPath = [NSURL URLWithString:@"shorebird.yaml"
relativeToURL:[NSURL fileURLWithPath:assetsPath]];
NSString* shorebirdYamlContents = [NSString stringWithContentsOfURL:shorebirdYamlPath
encoding:NSUTF8StringEncoding
error:nil];
NSString* appVersion =
[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString* appBuildNumber = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
flutterArguments.shorebird_args.app_version = appVersion.UTF8String;
flutterArguments.shorebird_args.app_build_number = appBuildNumber.UTF8String;

std::string cache_path =
fml::paths::JoinPaths({getenv("HOME"), "Library", "Application Support", "shorebird"});
flutterArguments.shorebird_args.cache_path = cache_path.c_str();
flutterArguments.shorebird_args.shorebird_yaml_contents = shorebirdYamlContents.UTF8String;

FlutterRendererConfig rendererConfig = [_renderer createRendererConfig];

FlutterEngineResult result = _embedderAPI.Initialize(
FLUTTER_ENGINE_VERSION, &rendererConfig, &flutterArguments, (__bridge void*)(self), &_engine);
if (result != kSuccess) {
Expand Down Expand Up @@ -732,19 +758,16 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
return YES;
}

- (void)loadAOTData:(NSString*)assetsDir {
- (void)loadAOTData:(NSString*)elfPath {
if (!_embedderAPI.RunsAOTCompiledDartCode()) {
return;
}

BOOL isDirOut = false; // required for NSFileManager fileExistsAtPath.
NSFileManager* fileManager = [NSFileManager defaultManager];

// This is the location where the test fixture places the snapshot file.
// For applications built by Flutter tool, this is in "App.framework".
NSString* elfPath = [NSString pathWithComponents:@[ assetsDir, @"app_elf_snapshot.so" ]];

if (![fileManager fileExistsAtPath:elfPath isDirectory:&isDirOut]) {
FML_LOG(INFO) << "in loadAOTData, elfPath does not exist: " << elfPath.UTF8String;
return;
}

Expand Down
1 change: 0 additions & 1 deletion shell/platform/embedder/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ template("embedder_source_set") {
"//flutter/lib/ui",
"//flutter/runtime:libdart",
"//flutter/shell/common",
"//flutter/shell/common/shorebird",
"//flutter/skia",
"//flutter/third_party/tonic",
]
Expand Down
13 changes: 0 additions & 13 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ extern const intptr_t kPlatformStrongDillSize;
#include "flutter/fml/paths.h"
#include "flutter/fml/trace_event.h"
#include "flutter/shell/common/rasterizer.h"
#include "flutter/shell/common/shorebird/shorebird.h"
#include "flutter/shell/common/switches.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/embedder/embedder_engine.h"
Expand Down Expand Up @@ -2306,18 +2305,6 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
"Could not infer the Flutter project to run from given arguments.");
}

// FIXME: This is probably the wrong place to call ConfigureShorebird, as
// some platforms (i.e., Windows) need to to swap out the app path before
// this point.
// Begin shorebird
#if FML_OS_MACOSX
if (args->shorebird_args.shorebird_yaml_contents) {
settings.application_library_path.push_back(args->shorebird_args.app_path);
flutter::ConfigureShorebird(args->shorebird_args, settings);
}
#endif
// End shorebird

// Create the engine but don't launch the shell or run the root isolate.
auto embedder_engine = std::make_unique<flutter::EmbedderEngine>(
std::move(thread_host), //
Expand Down
39 changes: 0 additions & 39 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2204,42 +2204,6 @@ typedef void (*FlutterLogMessageCallback)(const char* /* tag */,
/// FlutterEngine instance in AOT mode.
typedef struct _FlutterEngineAOTData* FlutterEngineAOTData;

typedef struct {
/// The version of the app (e.g., 1.0.0).
///
/// The string can be collected after the call to `FlutterEngineInitialize`
/// returns. The string must be NULL terminated.
const char* app_version;

/// The build number of the app (e.g., 1).
///
/// The string can be collected after the call to `FlutterEngineInitialize`
/// returns. The string must be NULL terminated.
const char* app_build_number;

/// The text contents of the shorebird.yaml file bundled with the compiled
/// app. Note that this is _not_ the same as the shorebird.yaml that exists in
/// the user's project.
///
/// The string can be collected after the call to `FlutterEngineInitialize`
/// returns. The string must be NULL terminated.
const char* shorebird_yaml_contents;

/// The path to the directory where Shorebird will store patches and state
/// data.
///
/// The string can be collected after the call to `FlutterEngineInitialize`
/// returns. The string must be NULL terminated.
const char* cache_path;

/// The path to the executable file. This is a Mach-O executable file on
/// macOS.
///
/// The string can be collected after the call to `FlutterEngineInitialize`
/// returns. The string must be NULL terminated.
const char* app_path;
} ShorebirdFlutterProjectArgs;

typedef struct {
/// The size of this struct. Must be sizeof(FlutterProjectArgs).
size_t struct_size;
Expand Down Expand Up @@ -2539,9 +2503,6 @@ typedef struct {
/// being registered on the framework side. The callback is invoked from
/// a task posted to the platform thread.
FlutterChannelUpdateCallback channel_update_callback;

/// Data used to initialize Shorebird as part of engine initialization.
ShorebirdFlutterProjectArgs shorebird_args;
} FlutterProjectArgs;

#ifndef FLUTTER_ENGINE_NO_PROTOTYPES
Expand Down