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

Commit 7e0f2a0

Browse files
Windows build (#94)
* chore: squash all our changes to a single commit See shorebird/dev-3.24.5 for prior commit history. * fix: remove flutter/fml/size include * fix: use shorebird buildroot * fix: generate analyze snapshot for arm builds * formatting * fix: update how we generate analyze_snapshot (#92) * fix: update how we generate analyze_snapshot * formatting * build windows * Windows Support * Format * Make patching work * Formatting * Formatting * Formatting * Improve windows * Formatting * Formatting * Formatting * Revert unneeded changes * Revert changes * Bump updater rev * Remove prints * Cleanup * fix deps * Use correct local appdata path * Formatting * consolidate fetching build number and release version * format * remove unnecessary pointer * Introduce ReleaseVersion struct * formatting * Formatting * More formatting * Comments * Formatting * More comments * Formatting * Remove print statements * Remove comments * Use in-out param for ConfigureShorebird * formatting * fix deps * Remove extra include of updater.lib * Cleanup * cleanup * Formatting * Use ERROR_SUCCESS * Do not use Error Success * Add comment * GetLocalAppDataPath feedback * Refactor --------- Co-authored-by: Felix Angelov <felix@shorebird.dev>
1 parent 9510a20 commit 7e0f2a0

File tree

10 files changed

+278
-9
lines changed

10 files changed

+278
-9
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ vars = {
1818
"dart_sdk_revision": "4f9b5084a041a0e7cc26295da1da9109df43ac4c",
1919
"dart_sdk_git": "git@github.com:shorebirdtech/dart-sdk.git",
2020
"updater_git": "https://github.com/shorebirdtech/updater.git",
21-
"updater_rev": "54e1e2ce2f82e5fe004bd0730c00d4310ab637dc",
21+
"updater_rev": "71b5ed65fab03fcf241edf0c74d027de9998da51",
2222

2323
# WARNING: DO NOT EDIT canvaskit_cipd_instance MANUALLY
2424
# See `lib/web_ui/README.md` for how to roll CanvasKit to a new version.

common/config.gni

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ if (slimpeller) {
7373
feature_defines_list += [ "SLIMPELLER=1" ]
7474
}
7575

76+
if (is_ios || is_mac || is_android || is_win) {
77+
feature_defines_list += [ "SHOREBIRD_PLATFORM_SUPPORTED=1" ]
78+
}
79+
7680
if (is_ios || is_mac) {
7781
flutter_cflags_objc = [
7882
"-Werror=overriding-method-mismatch",

shell/common/shell.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ Shell::Shell(DartVMRef vm,
444444
weak_factory_gpu_(nullptr),
445445
weak_factory_(this) {
446446
// FIXME: This is probably the wrong place to hook into.
447-
#if FML_OS_ANDROID || FML_OS_IOS || FML_OS_MACOSX
447+
#if SHOREBIRD_PLATFORM_SUPPORTED
448448
if (!vm_) {
449449
shorebird_report_launch_failure();
450450
} else {

shell/common/shorebird/BUILD.gn

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ source_set("shorebird") {
3131
]
3232

3333
include_dirs = [ "//flutter/updater" ]
34+
35+
if (host_os == "win" && target_os == "win") {
36+
if (target_cpu == "x64") {
37+
libs = [
38+
"userenv.lib",
39+
"//third_party/updater/target/x86_64-pc-windows-msvc/release/updater.lib",
40+
]
41+
}
42+
}
3443
}
3544

3645
if (enable_unittests) {

shell/common/shorebird/shorebird.cc

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "flutter/shell/common/shorebird/snapshots_data_handle.h"
2222
#include "flutter/shell/common/switches.h"
2323
#include "fml/logging.h"
24+
#include "shell/platform/embedder/embedder.h"
2425
#include "third_party/dart/runtime/include/dart_tools_api.h"
2526

2627
#include "third_party/updater/library/include/updater.h"
@@ -79,8 +80,100 @@ FileCallbacks ShorebirdFileCallbacks() {
7980
};
8081
}
8182

83+
// FIXME: consolidate this with the other ConfigureShorebird
84+
bool ConfigureShorebird(const ShorebirdConfigArgs& args,
85+
std::string& patch_path) {
86+
patch_path = args.release_app_library_path;
87+
auto shorebird_updater_dir_name = "shorebird_updater";
88+
89+
auto code_cache_dir = fml::paths::JoinPaths(
90+
{std::move(args.code_cache_path), shorebird_updater_dir_name});
91+
auto app_storage_dir = fml::paths::JoinPaths(
92+
{std::move(args.app_storage_path), shorebird_updater_dir_name});
93+
94+
fml::CreateDirectory(fml::paths::GetCachesDirectory(),
95+
{shorebird_updater_dir_name},
96+
fml::FilePermission::kReadWrite);
97+
98+
bool init_result;
99+
// Using a block to make AppParameters lifetime explicit.
100+
{
101+
AppParameters app_parameters;
102+
// Combine version and version_code into a single string.
103+
// We could also pass these separately through to the updater if needed.
104+
auto release_version =
105+
args.release_version.version + "+" + args.release_version.build_number;
106+
app_parameters.release_version = release_version.c_str();
107+
app_parameters.code_cache_dir = code_cache_dir.c_str();
108+
app_parameters.app_storage_dir = app_storage_dir.c_str();
109+
110+
// https://stackoverflow.com/questions/26032039/convert-vectorstring-into-char-c
111+
std::vector<const char*> c_paths{};
112+
c_paths.push_back(args.release_app_library_path.c_str());
113+
// Do not modify application_library_path or c_strings will invalidate.
114+
115+
app_parameters.original_libapp_paths = c_paths.data();
116+
app_parameters.original_libapp_paths_size = c_paths.size();
117+
118+
// shorebird_init copies from app_parameters and shorebirdYaml.
119+
init_result = shorebird_init(&app_parameters, ShorebirdFileCallbacks(),
120+
args.shorebird_yaml.c_str());
121+
}
122+
123+
// We've decided not to support synchronous updates on launch for now.
124+
// It's a terrible user experience (having the app hang on launch) and
125+
// instead we will provide examples of how to build a custom update UI
126+
// within Dart, including updating as part of login, etc.
127+
// https://github.com/shorebirdtech/shorebird/issues/950
128+
129+
// We only set the base snapshot on iOS for now.
130+
// TODO: this won't compile as we don't have a settings object here.
131+
// #if FML_OS_IOS || FML_OS_MACOSX
132+
// SetBaseSnapshot(settings);
133+
// #endif
134+
135+
FML_LOG(INFO) << "Checking for active patch";
136+
char* c_active_path = shorebird_next_boot_patch_path();
137+
if (c_active_path != NULL) {
138+
patch_path = c_active_path;
139+
shorebird_free_string(c_active_path);
140+
FML_LOG(INFO) << "Shorebird updater: patch path: " << patch_path;
141+
} else {
142+
FML_LOG(INFO) << "Shorebird updater: no active patch.";
143+
}
144+
145+
// We are careful only to report a launch start in the case where it's the
146+
// first time we've configured shorebird this process. Otherwise we could end
147+
// up in a case where we report a launch start, but never a completion (e.g.
148+
// from package:flutter_work_manager which sometimes creates a FlutterEngine
149+
// (and thus configures shorebird) but never runs it. The proper fix for this
150+
// is probably to move the launch_start() call to be later in the lifecycle
151+
// (when the snapshot is loaded and run, rather than when FlutterEngine is
152+
// initialized). This "hack" will still have a problem where FlutterEngine is
153+
// initialized but never run before the app is quit, could still cause us to
154+
// suddenly mark-bad a patch that was never actually attempted to launch.
155+
if (!init_result) {
156+
return false;
157+
}
158+
159+
// Once start_update_thread is called, the next_boot_patch* functions may
160+
// change their return values if the shorebird_report_launch_failed
161+
// function is called.
162+
shorebird_report_launch_start();
163+
164+
if (shorebird_should_auto_update()) {
165+
FML_LOG(INFO) << "Starting Shorebird update";
166+
shorebird_start_update_thread();
167+
} else {
168+
FML_LOG(INFO)
169+
<< "Shorebird auto_update disabled, not checking for updates.";
170+
}
171+
172+
return true;
173+
}
174+
82175
void ConfigureShorebird(const ShorebirdFlutterProjectArgs& args,
83-
flutter::Settings& settings) {
176+
Settings& settings) {
84177
// cache_path is used for both code_cache and app_storage, as we don't persist
85178
// any data between releases. args.app_path is appended to
86179
// the settings.application_library_path vector at this function's call site.

shell/common/shorebird/shorebird.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,39 @@
66

77
namespace flutter {
88

9+
struct ReleaseVersion {
10+
std::string version;
11+
std::string build_number;
12+
};
13+
14+
struct ShorebirdConfigArgs {
15+
std::string code_cache_path;
16+
std::string app_storage_path;
17+
std::string release_app_library_path;
18+
std::string shorebird_yaml;
19+
ReleaseVersion release_version;
20+
21+
ShorebirdConfigArgs(std::string code_cache_path,
22+
std::string app_storage_path,
23+
std::string release_app_library_path,
24+
std::string shorebird_yaml,
25+
ReleaseVersion release_version)
26+
: code_cache_path(code_cache_path),
27+
app_storage_path(app_storage_path),
28+
release_app_library_path(release_app_library_path),
29+
shorebird_yaml(shorebird_yaml),
30+
release_version(release_version) {}
31+
};
32+
33+
bool ConfigureShorebird(const ShorebirdConfigArgs& args,
34+
std::string& patch_path);
35+
936
void ConfigureShorebird(const ShorebirdFlutterProjectArgs& args,
10-
flutter::Settings& settings);
37+
Settings& settings);
1138

1239
void ConfigureShorebird(std::string code_cache_path,
1340
std::string app_storage_path,
14-
flutter::Settings& settings,
41+
Settings& settings,
1542
const std::string& shorebird_yaml,
1643
const std::string& version,
1744
const std::string& version_code);

shell/platform/embedder/embedder.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,13 +2306,16 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
23062306
"Could not infer the Flutter project to run from given arguments.");
23072307
}
23082308

2309+
// FIXME: This is probably the wrong place to call ConfigureShorebird, as
2310+
// some platforms (i.e., Windows) need to to swap out the app path before
2311+
// this point.
23092312
// Begin shorebird
2313+
#if FML_OS_MACOSX
23102314
if (args->shorebird_args.shorebird_yaml_contents) {
23112315
settings.application_library_path.push_back(args->shorebird_args.app_path);
23122316
flutter::ConfigureShorebird(args->shorebird_args, settings);
2313-
} else {
2314-
FML_LOG(INFO) << "[shorebird] No shorebird YAML contents provided.";
23152317
}
2318+
#endif
23162319
// End shorebird
23172320

23182321
// Create the engine but don't launch the shell or run the root isolate.

shell/platform/windows/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ source_set("flutter_windows_source") {
156156
":flutter_windows_headers",
157157
"//flutter/fml:fml",
158158
"//flutter/impeller/renderer/backend/gles",
159+
"//flutter/shell/common/shorebird:shorebird",
159160
"//flutter/shell/platform/common:common_cpp",
160161
"//flutter/shell/platform/common:common_cpp_input",
161162
"//flutter/shell/platform/common:common_cpp_switches",
@@ -169,6 +170,7 @@ source_set("flutter_windows_source") {
169170
"//flutter/third_party/angle:libEGL_static",
170171
"//flutter/third_party/angle:libGLESv2_static",
171172
"//flutter/third_party/rapidjson",
173+
"//flutter/third_party/tonic",
172174
]
173175
}
174176

shell/platform/windows/flutter_project_bundle.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class FlutterProjectBundle {
4444
// Sets engine switches.
4545
void SetSwitches(const std::vector<std::string>& switches);
4646

47+
void SetAotLibraryPath(const std::filesystem::path& aot_library_path) {
48+
aot_library_path_ = aot_library_path;
49+
}
50+
4751
// Attempts to load AOT data for this bundle. The returned data must be
4852
// retained until any engine instance it is passed to has been shut down.
4953
//

0 commit comments

Comments
 (0)