Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit 4491830

Browse files
authored
feat: macOS support (#89)
* feat: add macOS support * cleanup * formatting * hackity hack hack * wip (still not showing up in Console.app) * Get patches working * formatting * cleanup * cleanup * cleanup * cleanup * add comments * link dart elf_loader in flutter_tester * include updater lib when compiling for macos to make flutter_tester build * formatting * formatting * formatting * remove unnecessary imports * remove unnecessary imports * remove unnecessary imports * cleanup * cleanup * cleanup * cleanup and comments * split shorebird flutter project args into separate struct * fix build * fix formatting * fix cache path
1 parent dbcc9df commit 4491830

File tree

12 files changed

+107
-6
lines changed

12 files changed

+107
-6
lines changed

runtime/dart_snapshot.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static std::shared_ptr<const fml::Mapping> SearchMapping(
5757
const std::vector<std::string>& native_library_path,
5858
const char* native_library_symbol_name,
5959
bool is_executable) {
60-
#if FML_OS_IOS
60+
#if FML_OS_IOS || FML_OS_MACOSX
6161
// Detect when we're trying to load a Shorebird patch.
6262
auto patch_path = native_library_path.front();
6363
bool is_patch = patch_path.find(".vmcode") != std::string::npos;
@@ -141,7 +141,7 @@ static std::shared_ptr<const fml::Mapping> SearchMapping(
141141
}
142142
}
143143

144-
#if FML_OS_IOS
144+
#if FML_OS_IOS || FML_OS_MACOSX
145145
} // !is_patch
146146
#endif
147147

shell/common/BUILD.gn

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ source_set("common") {
162162

163163
deps += [ "//flutter/impeller" ]
164164
}
165+
166+
# Needed to compile flutter_tester for macOS.
167+
if (host_os == "mac" && target_os == "mac") {
168+
if (target_cpu == "arm64") {
169+
libs = [ "//third_party/updater/target/aarch64-apple-darwin/release/libupdater.a" ]
170+
} else if (target_cpu == "x64") {
171+
libs = [
172+
"//third_party/updater/target/x86_64-apple-darwin/release/libupdater.a",
173+
]
174+
}
175+
}
165176
}
166177

167178
# These are in their own source_set to avoid a dependency cycle with //common/graphics

shell/common/shell.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ Shell::Shell(DartVMRef vm,
452452
volatile_path_tracker_(std::move(volatile_path_tracker)),
453453
weak_factory_gpu_(nullptr),
454454
weak_factory_(this) {
455-
// FIXME: This is probably the wrong place to hook into.
456-
#if FML_OS_ANDROID || FML_OS_IOS
455+
// FIXME: This is probably the wrong place to hook into.
456+
#if FML_OS_ANDROID || FML_OS_IOS || FML_OS_MACOSX
457457
if (!vm_) {
458458
shorebird_report_launch_failure();
459459
} else {

shell/common/shorebird/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ source_set("shorebird") {
2727
"//flutter/runtime",
2828
"//flutter/runtime:libdart",
2929
"//flutter/shell/common",
30+
"//flutter/shell/platform/embedder:embedder_headers",
3031
]
3132

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

shell/common/shorebird/shorebird.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ FileCallbacks ShorebirdFileCallbacks() {
8080
};
8181
}
8282

83+
void ConfigureShorebird(const ShorebirdFlutterProjectArgs& args,
84+
flutter::Settings& settings) {
85+
// cache_path is used for both code_cache and app_storage, as we don't persist
86+
// any data between releases. args.app_path is appended to
87+
// the settings.application_library_path vector at this function's call site.
88+
ConfigureShorebird(args.cache_path, args.cache_path, settings,
89+
args.shorebird_yaml_contents, args.app_version,
90+
args.app_build_number);
91+
}
92+
8393
void ConfigureShorebird(std::string code_cache_path,
8494
std::string app_storage_path,
8595
Settings& settings,
@@ -137,7 +147,7 @@ void ConfigureShorebird(std::string code_cache_path,
137147
// https://github.com/shorebirdtech/shorebird/issues/950
138148

139149
// We only set the base snapshot on iOS for now.
140-
#if FML_OS_IOS
150+
#if FML_OS_IOS || FML_OS_MACOSX
141151
SetBaseSnapshot(settings);
142152
#endif
143153

@@ -147,7 +157,7 @@ void ConfigureShorebird(std::string code_cache_path,
147157
shorebird_free_string(c_active_path);
148158
FML_LOG(INFO) << "Shorebird updater: active path: " << active_path;
149159

150-
#if FML_OS_IOS
160+
#if FML_OS_IOS || FML_OS_MACOSX
151161
// On iOS we add the patch to the front of the list instead of clearing
152162
// the list, to allow dart_shapshot.cc to still find the base snapshot
153163
// for the vm isolate.

shell/common/shorebird/shorebird.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
#define FLUTTER_SHELL_COMMON_SHOREBIRD_SHOREBIRD_H_
33

44
#include "flutter/common/settings.h"
5+
#include "shell/platform/embedder/embedder.h"
56

67
namespace flutter {
78

9+
void ConfigureShorebird(const ShorebirdFlutterProjectArgs& args,
10+
flutter::Settings& settings);
11+
812
void ConfigureShorebird(std::string code_cache_path,
913
std::string app_storage_path,
1014
flutter::Settings& settings,

shell/platform/darwin/macos/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ source_set("flutter_framework_source") {
127127
"//flutter/shell/platform/common:common_cpp_enums",
128128
"//flutter/shell/platform/common:common_cpp_input",
129129
"//flutter/shell/platform/common:common_cpp_switches",
130+
"//flutter/shell/platform/darwin/common",
130131
"//flutter/shell/platform/darwin/common:availability_version_check",
131132
"//flutter/shell/platform/darwin/common:framework_common",
132133
"//flutter/shell/platform/darwin/graphics:graphics",

shell/platform/darwin/macos/framework/Source/FlutterEngine.mm

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <vector>
1111

1212
#include "flutter/common/constants.h"
13+
#include "flutter/fml/paths.h"
1314
#include "flutter/shell/platform/common/app_lifecycle_state.h"
1415
#include "flutter/shell/platform/common/engine_switches.h"
1516
#include "flutter/shell/platform/embedder/embedder.h"
@@ -673,6 +674,28 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
673674
[engine onVSync:baton];
674675
};
675676

677+
NSString* bundlePath =
678+
[[NSBundle bundleWithURL:[NSBundle.mainBundle.privateFrameworksURL
679+
URLByAppendingPathComponent:@"App.framework"]] bundlePath];
680+
bundlePath = [bundlePath stringByAppendingString:@"/App"];
681+
flutterArguments.shorebird_args.app_path = bundlePath.UTF8String;
682+
NSString* assetsPath = _project.assetsPath;
683+
NSURL* shorebirdYamlPath = [NSURL URLWithString:@"shorebird.yaml"
684+
relativeToURL:[NSURL fileURLWithPath:assetsPath]];
685+
NSString* shorebirdYamlContents = [NSString stringWithContentsOfURL:shorebirdYamlPath
686+
encoding:NSUTF8StringEncoding
687+
error:nil];
688+
NSString* appVersion =
689+
[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
690+
NSString* appBuildNumber = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"];
691+
flutterArguments.shorebird_args.app_version = appVersion.UTF8String;
692+
flutterArguments.shorebird_args.app_build_number = appBuildNumber.UTF8String;
693+
694+
std::string cache_path =
695+
fml::paths::JoinPaths({getenv("HOME"), "Library", "Application Support", "shorebird"});
696+
flutterArguments.shorebird_args.cache_path = cache_path.c_str();
697+
flutterArguments.shorebird_args.shorebird_yaml_contents = shorebirdYamlContents.UTF8String;
698+
676699
FlutterRendererConfig rendererConfig = [_renderer createRendererConfig];
677700
FlutterEngineResult result = _embedderAPI.Initialize(
678701
FLUTTER_ENGINE_VERSION, &rendererConfig, &flutterArguments, (__bridge void*)(self), &_engine);

shell/platform/embedder/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ template("embedder_source_set") {
110110
"//flutter/lib/ui",
111111
"//flutter/runtime:libdart",
112112
"//flutter/shell/common",
113+
"//flutter/shell/common/shorebird",
113114
"//flutter/skia",
114115
"//flutter/third_party/tonic",
115116
]

shell/platform/embedder/embedder.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extern const intptr_t kPlatformStrongDillSize;
5050
#include "flutter/fml/paths.h"
5151
#include "flutter/fml/trace_event.h"
5252
#include "flutter/shell/common/rasterizer.h"
53+
#include "flutter/shell/common/shorebird/shorebird.h"
5354
#include "flutter/shell/common/switches.h"
5455
#include "flutter/shell/platform/embedder/embedder.h"
5556
#include "flutter/shell/platform/embedder/embedder_engine.h"
@@ -2166,6 +2167,15 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
21662167
"Could not infer the Flutter project to run from given arguments.");
21672168
}
21682169

2170+
// Begin shorebird
2171+
if (args->shorebird_args.shorebird_yaml_contents) {
2172+
settings.application_library_path.push_back(args->shorebird_args.app_path);
2173+
flutter::ConfigureShorebird(args->shorebird_args, settings);
2174+
} else {
2175+
FML_LOG(INFO) << "[shorebird] No shorebird YAML contents provided.";
2176+
}
2177+
// End shorebird
2178+
21692179
// Create the engine but don't launch the shell or run the root isolate.
21702180
auto embedder_engine = std::make_unique<flutter::EmbedderEngine>(
21712181
std::move(thread_host), //

0 commit comments

Comments
 (0)