Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows build #94

Merged
merged 53 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
233c644
chore: squash all our changes to a single commit
felangel Aug 6, 2024
dce8560
fix: remove flutter/fml/size include
felangel Dec 12, 2024
c646971
fix: use shorebird buildroot
felangel Dec 12, 2024
2c8e287
fix: generate analyze snapshot for arm builds
bryanoltman Dec 13, 2024
be0ad73
formatting
bryanoltman Dec 13, 2024
59571a1
fix: update how we generate analyze_snapshot (#92)
bryanoltman Dec 13, 2024
ca1298f
Merge branch 'shorebird/dev' of github.com:shorebirdtech/engine into …
bryanoltman Dec 17, 2024
4187543
build windows
bryanoltman Dec 17, 2024
a3eb71f
Windows Support
bryanoltman Dec 18, 2024
ae45482
Format
bryanoltman Dec 18, 2024
4c1e068
Make patching work
bryanoltman Dec 19, 2024
1b834b3
Formatting
bryanoltman Dec 19, 2024
f871d4f
Formatting
bryanoltman Dec 19, 2024
a63c7b3
Formatting
bryanoltman Dec 19, 2024
8bf5e5b
Improve windows
bryanoltman Dec 20, 2024
530a002
Formatting
bryanoltman Dec 20, 2024
104a1d5
Formatting
bryanoltman Dec 20, 2024
0b3a19b
Formatting
bryanoltman Dec 20, 2024
d49b2ae
Revert unneeded changes
bryanoltman Dec 20, 2024
68d7a29
Revert changes
bryanoltman Dec 20, 2024
c12edfe
Bump updater rev
bryanoltman Dec 20, 2024
aeaea17
Remove prints
bryanoltman Dec 20, 2024
91640d2
Cleanup
bryanoltman Dec 30, 2024
5969746
Merge branch 'shorebird/dev' into bo/windows-build
bryanoltman Dec 30, 2024
8593e7e
fix deps
bryanoltman Dec 30, 2024
d4a61af
Use correct local appdata path
bryanoltman Dec 30, 2024
a3313bd
Formatting
bryanoltman Dec 30, 2024
4e4ac41
consolidate fetching build number and release version
bryanoltman Dec 30, 2024
b93aeb1
format
bryanoltman Dec 30, 2024
5852885
remove unnecessary pointer
bryanoltman Jan 3, 2025
48e61d8
Introduce ReleaseVersion struct
bryanoltman Jan 3, 2025
6f1a6b5
formatting
bryanoltman Jan 3, 2025
a9e4fb2
Formatting
bryanoltman Jan 3, 2025
28b07d7
More formatting
bryanoltman Jan 3, 2025
ef0091d
Comments
bryanoltman Jan 3, 2025
4f2351a
Formatting
bryanoltman Jan 3, 2025
ec8c644
More comments
bryanoltman Jan 3, 2025
c0e4596
Formatting
bryanoltman Jan 3, 2025
ee1410e
Remove print statements
bryanoltman Jan 3, 2025
753d3f9
Remove comments
bryanoltman Jan 3, 2025
181035c
Use in-out param for ConfigureShorebird
bryanoltman Jan 3, 2025
a9a1cce
formatting
bryanoltman Jan 3, 2025
6bcd83e
fix deps
bryanoltman Jan 3, 2025
1c622d2
Remove extra include of updater.lib
bryanoltman Jan 3, 2025
a699821
Cleanup
bryanoltman Jan 3, 2025
2bf9b7c
Merge branch 'bo/windows-build' of github.com:shorebirdtech/engine in…
bryanoltman Jan 3, 2025
32bd681
cleanup
bryanoltman Jan 3, 2025
6e09a4a
Formatting
bryanoltman Jan 3, 2025
f98353f
Use ERROR_SUCCESS
bryanoltman Jan 3, 2025
99a17ed
Do not use Error Success
bryanoltman Jan 3, 2025
2595ff1
Add comment
bryanoltman Jan 3, 2025
4c34dd7
GetLocalAppDataPath feedback
bryanoltman Jan 3, 2025
636fd08
Refactor
bryanoltman Jan 3, 2025
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": "4f9b5084a041a0e7cc26295da1da9109df43ac4c",
"dart_sdk_git": "[email protected]:shorebirdtech/dart-sdk.git",
"updater_git": "https://github.com/shorebirdtech/updater.git",
"updater_rev": "54e1e2ce2f82e5fe004bd0730c00d4310ab637dc",
"updater_rev": "71b5ed65fab03fcf241edf0c74d027de9998da51",

# 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 @@ -73,6 +73,10 @@ if (slimpeller) {
feature_defines_list += [ "SLIMPELLER=1" ]
}

if (is_ios || is_mac || is_android || is_win) {
feature_defines_list += [ "SHOREBIRD_PLATFORM_SUPPORTED=1" ]
}

if (is_ios || is_mac) {
flutter_cflags_objc = [
"-Werror=overriding-method-mismatch",
Expand Down
2 changes: 1 addition & 1 deletion shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ Shell::Shell(DartVMRef vm,
weak_factory_gpu_(nullptr),
weak_factory_(this) {
// FIXME: This is probably the wrong place to hook into.
#if FML_OS_ANDROID || FML_OS_IOS || FML_OS_MACOSX
#if SHOREBIRD_PLATFORM_SUPPORTED
if (!vm_) {
shorebird_report_launch_failure();
} else {
Expand Down
9 changes: 9 additions & 0 deletions shell/common/shorebird/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ source_set("shorebird") {
]

include_dirs = [ "//flutter/updater" ]

if (host_os == "win" && target_os == "win") {
if (target_cpu == "x64") {
libs = [
"userenv.lib",
bryanoltman marked this conversation as resolved.
Show resolved Hide resolved
"//third_party/updater/target/x86_64-pc-windows-msvc/release/updater.lib",
]
}
}
}

if (enable_unittests) {
Expand Down
95 changes: 94 additions & 1 deletion shell/common/shorebird/shorebird.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "flutter/shell/common/shorebird/snapshots_data_handle.h"
#include "flutter/shell/common/switches.h"
#include "fml/logging.h"
#include "shell/platform/embedder/embedder.h"
#include "third_party/dart/runtime/include/dart_tools_api.h"

#include "third_party/updater/library/include/updater.h"
Expand Down Expand Up @@ -79,8 +80,100 @@ FileCallbacks ShorebirdFileCallbacks() {
};
}

// FIXME: consolidate this with the other ConfigureShorebird
bool ConfigureShorebird(const ShorebirdConfigArgs& args,
std::string& patch_path) {
patch_path = args.release_app_library_path;
auto shorebird_updater_dir_name = "shorebird_updater";

auto code_cache_dir = fml::paths::JoinPaths(
{std::move(args.code_cache_path), shorebird_updater_dir_name});
auto app_storage_dir = fml::paths::JoinPaths(
{std::move(args.app_storage_path), shorebird_updater_dir_name});

fml::CreateDirectory(fml::paths::GetCachesDirectory(),
{shorebird_updater_dir_name},
fml::FilePermission::kReadWrite);

bool init_result;
// Using a block to make AppParameters lifetime explicit.
{
AppParameters app_parameters;
// Combine version and version_code into a single string.
// We could also pass these separately through to the updater if needed.
auto release_version =
args.release_version.version + "+" + args.release_version.build_number;
app_parameters.release_version = release_version.c_str();
app_parameters.code_cache_dir = code_cache_dir.c_str();
app_parameters.app_storage_dir = app_storage_dir.c_str();

// https://stackoverflow.com/questions/26032039/convert-vectorstring-into-char-c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do this in the Android codepath too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this function and the other ConfigureShorebird need to be consolidated. Doing that as a followup PR, as it affects the macOS bits

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant specifically the "turn a vector into vector<char*>

std::vector<const char*> c_paths{};
c_paths.push_back(args.release_app_library_path.c_str());
// Do not modify application_library_path or c_strings will invalidate.

app_parameters.original_libapp_paths = c_paths.data();
app_parameters.original_libapp_paths_size = c_paths.size();

// shorebird_init copies from app_parameters and shorebirdYaml.
init_result = shorebird_init(&app_parameters, ShorebirdFileCallbacks(),
args.shorebird_yaml.c_str());
}

// We've decided not to support synchronous updates on launch for now.
// It's a terrible user experience (having the app hang on launch) and
// instead we will provide examples of how to build a custom update UI
// 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) {
patch_path = c_active_path;
shorebird_free_string(c_active_path);
FML_LOG(INFO) << "Shorebird updater: patch path: " << patch_path;
} else {
FML_LOG(INFO) << "Shorebird updater: no active patch.";
}

// We are careful only to report a launch start in the case where it's the
// first time we've configured shorebird this process. Otherwise we could end
// up in a case where we report a launch start, but never a completion (e.g.
// from package:flutter_work_manager which sometimes creates a FlutterEngine
// (and thus configures shorebird) but never runs it. The proper fix for this
// is probably to move the launch_start() call to be later in the lifecycle
// (when the snapshot is loaded and run, rather than when FlutterEngine is
// initialized). This "hack" will still have a problem where FlutterEngine is
// initialized but never run before the app is quit, could still cause us to
// suddenly mark-bad a patch that was never actually attempted to launch.
if (!init_result) {
return false;
}

// Once start_update_thread is called, the next_boot_patch* functions may
// change their return values if the shorebird_report_launch_failed
// function is called.
shorebird_report_launch_start();

if (shorebird_should_auto_update()) {
FML_LOG(INFO) << "Starting Shorebird update";
shorebird_start_update_thread();
} else {
FML_LOG(INFO)
<< "Shorebird auto_update disabled, not checking for updates.";
}

return true;
}

void ConfigureShorebird(const ShorebirdFlutterProjectArgs& args,
flutter::Settings& settings) {
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.
Expand Down
31 changes: 29 additions & 2 deletions shell/common/shorebird/shorebird.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,39 @@

namespace flutter {

struct ReleaseVersion {
std::string version;
std::string build_number;
};

struct ShorebirdConfigArgs {
std::string code_cache_path;
std::string app_storage_path;
std::string release_app_library_path;
std::string shorebird_yaml;
ReleaseVersion release_version;

ShorebirdConfigArgs(std::string code_cache_path,
std::string app_storage_path,
std::string release_app_library_path,
std::string shorebird_yaml,
ReleaseVersion release_version)
: code_cache_path(code_cache_path),
app_storage_path(app_storage_path),
release_app_library_path(release_app_library_path),
shorebird_yaml(shorebird_yaml),
release_version(release_version) {}
};

bool ConfigureShorebird(const ShorebirdConfigArgs& args,
std::string& patch_path);

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

void ConfigureShorebird(std::string code_cache_path,
std::string app_storage_path,
flutter::Settings& settings,
Settings& settings,
const std::string& shorebird_yaml,
const std::string& version,
const std::string& version_code);
Expand Down
7 changes: 5 additions & 2 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2306,13 +2306,16 @@ 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
bryanoltman marked this conversation as resolved.
Show resolved Hide resolved
if (args->shorebird_args.shorebird_yaml_contents) {
settings.application_library_path.push_back(args->shorebird_args.app_path);
flutter::ConfigureShorebird(args->shorebird_args, settings);
} else {
FML_LOG(INFO) << "[shorebird] No shorebird YAML contents provided.";
}
#endif
// End shorebird

// Create the engine but don't launch the shell or run the root isolate.
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/windows/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ source_set("flutter_windows_source") {
":flutter_windows_headers",
"//flutter/fml:fml",
"//flutter/impeller/renderer/backend/gles",
"//flutter/shell/common/shorebird:shorebird",
"//flutter/shell/platform/common:common_cpp",
"//flutter/shell/platform/common:common_cpp_input",
"//flutter/shell/platform/common:common_cpp_switches",
Expand All @@ -169,6 +170,7 @@ source_set("flutter_windows_source") {
"//flutter/third_party/angle:libEGL_static",
"//flutter/third_party/angle:libGLESv2_static",
"//flutter/third_party/rapidjson",
"//flutter/third_party/tonic",
]
}

Expand Down
4 changes: 4 additions & 0 deletions shell/platform/windows/flutter_project_bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class FlutterProjectBundle {
// Sets engine switches.
void SetSwitches(const std::vector<std::string>& switches);

void SetAotLibraryPath(const std::filesystem::path& aot_library_path) {
aot_library_path_ = aot_library_path;
}

// Attempts to load AOT data for this bundle. The returned data must be
// retained until any engine instance it is passed to has been shut down.
//
Expand Down
Loading