diff --git a/DEPS b/DEPS index fcaa3a57e2877..0c1599c9eeed0 100644 --- a/DEPS +++ b/DEPS @@ -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. diff --git a/common/config.gni b/common/config.gni index 66d300d99670d..351af4a41746d 100644 --- a/common/config.gni +++ b/common/config.gni @@ -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", diff --git a/runtime/dart_snapshot.cc b/runtime/dart_snapshot.cc index 1a62b3406ef3e..d735b299cad42 100644 --- a/runtime/dart_snapshot.cc +++ b/runtime/dart_snapshot.cc @@ -57,7 +57,7 @@ static std::shared_ptr SearchMapping( const std::vector& 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; @@ -141,7 +141,7 @@ static std::shared_ptr SearchMapping( } } -#if FML_OS_IOS || FML_OS_MACOSX +#if SHOREBIRD_USE_INTERPRETER } // !is_patch #endif diff --git a/shell/common/shorebird/shorebird.cc b/shell/common/shorebird/shorebird.cc index 77608a0e29563..602a0521ae7b0 100644 --- a/shell/common/shorebird/shorebird.cc +++ b/shell/common/shorebird/shorebird.cc @@ -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) { @@ -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, @@ -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 @@ -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. diff --git a/shell/common/shorebird/shorebird.h b/shell/common/shorebird/shorebird.h index b4efa4c28321b..3e9ccce9ee3f6 100644 --- a/shell/common/shorebird/shorebird.h +++ b/shell/common/shorebird/shorebird.h @@ -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, diff --git a/shell/platform/darwin/macos/BUILD.gn b/shell/platform/darwin/macos/BUILD.gn index 2975a38fb8d08..b7ce1ca36ffe2 100644 --- a/shell/platform/darwin/macos/BUILD.gn +++ b/shell/platform/darwin/macos/BUILD.gn @@ -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", diff --git a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm index c870f0d3f55ea..adc9a0534a910 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterEngine.mm @@ -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" @@ -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; @@ -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; } @@ -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) { @@ -732,7 +758,7 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint { return YES; } -- (void)loadAOTData:(NSString*)assetsDir { +- (void)loadAOTData:(NSString*)elfPath { if (!_embedderAPI.RunsAOTCompiledDartCode()) { return; } @@ -740,11 +766,8 @@ - (void)loadAOTData:(NSString*)assetsDir { 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; } diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index c620e74761979..38c7e2db98e87 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -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", ] diff --git a/shell/platform/embedder/embedder.cc b/shell/platform/embedder/embedder.cc index f1646d85eab08..2adf56c592e0a 100644 --- a/shell/platform/embedder/embedder.cc +++ b/shell/platform/embedder/embedder.cc @@ -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" @@ -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( std::move(thread_host), // diff --git a/shell/platform/embedder/embedder.h b/shell/platform/embedder/embedder.h index 482a4cad90f6c..9e9b875a2cc36 100644 --- a/shell/platform/embedder/embedder.h +++ b/shell/platform/embedder/embedder.h @@ -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; @@ -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