diff --git a/experimental/desktop_photo_search/linux/.gitignore b/experimental/desktop_photo_search/linux/.gitignore new file mode 100644 index 000000000..d3896c984 --- /dev/null +++ b/experimental/desktop_photo_search/linux/.gitignore @@ -0,0 +1 @@ +flutter/ephemeral diff --git a/experimental/desktop_photo_search/linux/CMakeLists.txt b/experimental/desktop_photo_search/linux/CMakeLists.txt new file mode 100644 index 000000000..fb69732f6 --- /dev/null +++ b/experimental/desktop_photo_search/linux/CMakeLists.txt @@ -0,0 +1,96 @@ +cmake_minimum_required(VERSION 3.10) +project(runner LANGUAGES CXX) + +set(BINARY_NAME "desktop_photo_search") + +cmake_policy(SET CMP0063 NEW) + +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Configure build options. +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") +endif() + +# Compilation settings that should be applied to most targets. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_14) + target_compile_options(${TARGET} PRIVATE -Wall -Werror) + target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") +endfunction() + +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") + +# Flutter library and tool build rules. +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) + +# Application build +add_executable(${BINARY_NAME} + "main.cc" + "my_application.cc" + "window_configuration.cc" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" +) +apply_standard_settings(${BINARY_NAME}) +target_link_libraries(${BINARY_NAME} PRIVATE flutter) +target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) +add_dependencies(${BINARY_NAME} flutter_assemble) + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# By default, "installing" just makes a relocatable bundle in the build +# directory. +set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +# Start with a clean build bundle directory every time. +install(CODE " + file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") + " COMPONENT Runtime) + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") + install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() diff --git a/experimental/desktop_photo_search/linux/flutter/.template_version b/experimental/desktop_photo_search/linux/flutter/.template_version new file mode 100644 index 000000000..b8626c4cf --- /dev/null +++ b/experimental/desktop_photo_search/linux/flutter/.template_version @@ -0,0 +1 @@ +4 diff --git a/experimental/desktop_photo_search/linux/flutter/CMakeLists.txt b/experimental/desktop_photo_search/linux/flutter/CMakeLists.txt new file mode 100644 index 000000000..17576f6ab --- /dev/null +++ b/experimental/desktop_photo_search/linux/flutter/CMakeLists.txt @@ -0,0 +1,86 @@ +cmake_minimum_required(VERSION 3.10) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. + +# Serves the same purpose as list(TRANSFORM ... PREPEND ...), +# which isn't available in 3.10. +function(list_prepend LIST_NAME PREFIX) + set(NEW_LIST "") + foreach(element ${${LIST_NAME}}) + list(APPEND NEW_LIST "${PREFIX}${element}") + endforeach(element) + set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) +endfunction() + +# === Flutter Library === +# System-level dependencies. +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) +pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) +pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) + +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "fl_basic_message_channel.h" + "fl_binary_codec.h" + "fl_binary_messenger.h" + "fl_dart_project.h" + "fl_engine.h" + "fl_json_message_codec.h" + "fl_json_method_codec.h" + "fl_message_codec.h" + "fl_method_call.h" + "fl_method_channel.h" + "fl_method_codec.h" + "fl_method_response.h" + "fl_plugin_registrar.h" + "fl_plugin_registry.h" + "fl_standard_message_codec.h" + "fl_standard_method_codec.h" + "fl_string_codec.h" + "fl_value.h" + "fl_view.h" + "flutter_linux.h" +) +list_prepend(FLUTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") +target_link_libraries(flutter INTERFACE + PkgConfig::GTK + PkgConfig::GLIB + PkgConfig::GIO +) +add_dependencies(flutter flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CMAKE_CURRENT_BINARY_DIR}/_phony_ + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" + linux-x64 ${CMAKE_BUILD_TYPE} +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} +) diff --git a/experimental/desktop_photo_search/linux/flutter/generated_plugin_registrant.cc b/experimental/desktop_photo_search/linux/flutter/generated_plugin_registrant.cc new file mode 100644 index 000000000..8e0daa87f --- /dev/null +++ b/experimental/desktop_photo_search/linux/flutter/generated_plugin_registrant.cc @@ -0,0 +1,17 @@ +// +// Generated file. Do not edit. +// + +#include "generated_plugin_registrant.h" + +#include +#include + +void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) file_chooser_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "FileChooserPlugin"); + file_chooser_plugin_register_with_registrar(file_chooser_registrar); + g_autoptr(FlPluginRegistrar) menubar_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "MenubarPlugin"); + menubar_plugin_register_with_registrar(menubar_registrar); +} diff --git a/experimental/desktop_photo_search/linux/flutter/generated_plugin_registrant.h b/experimental/desktop_photo_search/linux/flutter/generated_plugin_registrant.h new file mode 100644 index 000000000..9bf747894 --- /dev/null +++ b/experimental/desktop_photo_search/linux/flutter/generated_plugin_registrant.h @@ -0,0 +1,13 @@ +// +// Generated file. Do not edit. +// + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void fl_register_plugins(FlPluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/experimental/desktop_photo_search/linux/flutter/generated_plugins.cmake b/experimental/desktop_photo_search/linux/flutter/generated_plugins.cmake new file mode 100644 index 000000000..3ccf17e51 --- /dev/null +++ b/experimental/desktop_photo_search/linux/flutter/generated_plugins.cmake @@ -0,0 +1,17 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST + file_chooser + menubar +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) diff --git a/experimental/desktop_photo_search/linux/main.cc b/experimental/desktop_photo_search/linux/main.cc new file mode 100644 index 000000000..e7c5c5437 --- /dev/null +++ b/experimental/desktop_photo_search/linux/main.cc @@ -0,0 +1,6 @@ +#include "my_application.h" + +int main(int argc, char** argv) { + g_autoptr(MyApplication) app = my_application_new(); + return g_application_run(G_APPLICATION(app), argc, argv); +} diff --git a/experimental/desktop_photo_search/linux/my_application.cc b/experimental/desktop_photo_search/linux/my_application.cc new file mode 100644 index 000000000..be5b5ff70 --- /dev/null +++ b/experimental/desktop_photo_search/linux/my_application.cc @@ -0,0 +1,46 @@ +#include "my_application.h" + +#include + +#include "flutter/generated_plugin_registrant.h" +#include "window_configuration.h" + +struct _MyApplication { + GtkApplication parent_instance; +}; + +G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) + +// Implements GApplication::activate. +static void my_application_activate(GApplication* application) { + GtkWindow* window = + GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); + GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); + gtk_widget_show(GTK_WIDGET(header_bar)); + gtk_header_bar_set_title(header_bar, kFlutterWindowTitle); + gtk_header_bar_set_show_close_button(header_bar, TRUE); + gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); + gtk_window_set_default_size(window, kFlutterWindowWidth, + kFlutterWindowHeight); + gtk_widget_show(GTK_WIDGET(window)); + + g_autoptr(FlDartProject) project = fl_dart_project_new(); + + FlView* view = fl_view_new(project); + gtk_widget_show(GTK_WIDGET(view)); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); + + fl_register_plugins(FL_PLUGIN_REGISTRY(view)); + + gtk_widget_grab_focus(GTK_WIDGET(view)); +} + +static void my_application_class_init(MyApplicationClass* klass) { + G_APPLICATION_CLASS(klass)->activate = my_application_activate; +} + +static void my_application_init(MyApplication* self) {} + +MyApplication* my_application_new() { + return MY_APPLICATION(g_object_new(my_application_get_type(), nullptr)); +} diff --git a/experimental/desktop_photo_search/linux/my_application.h b/experimental/desktop_photo_search/linux/my_application.h new file mode 100644 index 000000000..72271d5e4 --- /dev/null +++ b/experimental/desktop_photo_search/linux/my_application.h @@ -0,0 +1,18 @@ +#ifndef FLUTTER_MY_APPLICATION_H_ +#define FLUTTER_MY_APPLICATION_H_ + +#include + +G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, + GtkApplication) + +/** + * my_application_new: + * + * Creates a new Flutter-based application. + * + * Returns: a new #MyApplication. + */ +MyApplication* my_application_new(); + +#endif // FLUTTER_MY_APPLICATION_H_ diff --git a/experimental/desktop_photo_search/linux/window_configuration.cc b/experimental/desktop_photo_search/linux/window_configuration.cc new file mode 100644 index 000000000..e2e9cbcce --- /dev/null +++ b/experimental/desktop_photo_search/linux/window_configuration.cc @@ -0,0 +1,5 @@ +#include "window_configuration.h" + +const char *kFlutterWindowTitle = "desktop_photo_search"; +const unsigned int kFlutterWindowWidth = 1280; +const unsigned int kFlutterWindowHeight = 720; diff --git a/experimental/desktop_photo_search/linux/window_configuration.h b/experimental/desktop_photo_search/linux/window_configuration.h new file mode 100644 index 000000000..8592c5b70 --- /dev/null +++ b/experimental/desktop_photo_search/linux/window_configuration.h @@ -0,0 +1,15 @@ +#ifndef WINDOW_CONFIGURATION_ +#define WINDOW_CONFIGURATION_ + +// This is a temporary approach to isolate common customizations from main.cc, +// where the APIs are still in flux. This should simplify re-creating the +// runner while preserving local changes. +// +// Longer term there should be simpler configuration options for common +// customizations like this, without requiring native code changes. + +extern const char *kFlutterWindowTitle; +extern const unsigned int kFlutterWindowWidth; +extern const unsigned int kFlutterWindowHeight; + +#endif // WINDOW_CONFIGURATION_ diff --git a/experimental/desktop_photo_search/pubspec.lock b/experimental/desktop_photo_search/pubspec.lock index cc0be7bb4..43b040267 100644 --- a/experimental/desktop_photo_search/pubspec.lock +++ b/experimental/desktop_photo_search/pubspec.lock @@ -106,6 +106,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "7.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" charcode: dependency: transitive description: @@ -126,7 +133,7 @@ packages: name: cli_util url: "https://pub.dartlang.org" source: hosted - version: "0.1.4" + version: "0.2.0" clock: dependency: transitive description: @@ -147,7 +154,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.12" + version: "1.14.13" convert: dependency: transitive description: @@ -161,7 +168,7 @@ packages: name: coverage url: "https://pub.dartlang.org" source: hosted - version: "0.13.10" + version: "0.14.0" crypto: dependency: transitive description: @@ -202,10 +209,10 @@ packages: description: path: "plugins/file_chooser" ref: HEAD - resolved-ref: b9c7e27ba16f86ff3390cfb0e460802e9980399a + resolved-ref: b0794faf2c000576515aee56ca6bb5bee64cece4 url: "https://github.com/google/flutter-desktop-embedding.git" source: git - version: "0.1.0" + version: "0.2.0" fixnum: dependency: transitive description: @@ -255,7 +262,7 @@ packages: name: grinder url: "https://pub.dartlang.org" source: hosted - version: "0.8.4" + version: "0.8.5" html: dependency: transitive description: @@ -304,7 +311,7 @@ packages: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.1+1" + version: "0.6.2" json_annotation: dependency: transitive description: @@ -325,16 +332,16 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.8" menubar: dependency: "direct main" description: path: "plugins/menubar" ref: HEAD - resolved-ref: b9c7e27ba16f86ff3390cfb0e460802e9980399a + resolved-ref: b0794faf2c000576515aee56ca6bb5bee64cece4 url: "https://github.com/google/flutter-desktop-embedding.git" source: git - version: "0.0.1" + version: "0.1.0" meta: dependency: "direct main" description: @@ -349,13 +356,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.9.6+3" - multi_server_socket: - dependency: transitive - description: - name: multi_server_socket - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.2" nested: dependency: transitive description: @@ -383,7 +383,7 @@ packages: name: node_preamble url: "https://pub.dartlang.org" source: hosted - version: "1.4.10" + version: "1.4.12" package_config: dependency: transitive description: @@ -432,7 +432,7 @@ packages: name: provider url: "https://pub.dartlang.org" source: hosted - version: "4.1.2" + version: "4.1.3" pub_semver: dependency: transitive description: @@ -460,7 +460,7 @@ packages: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "0.7.5" + version: "0.7.7" shelf_packages_handler: dependency: transitive description: @@ -556,21 +556,21 @@ packages: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.14.6" + version: "1.15.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.16" + version: "0.2.17" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.3.6" + version: "0.3.8" timing: dependency: transitive description: @@ -591,7 +591,7 @@ packages: name: tuneup url: "https://pub.dartlang.org" source: hosted - version: "0.3.6+2" + version: "0.3.7" typed_data: dependency: transitive description: @@ -605,7 +605,7 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "5.4.10" + version: "5.4.11" url_launcher_macos: dependency: transitive description: @@ -633,7 +633,7 @@ packages: name: uuid url: "https://pub.dartlang.org" source: hosted - version: "2.0.4" + version: "2.1.0" vector_math: dependency: transitive description: @@ -647,7 +647,7 @@ packages: name: vm_service url: "https://pub.dartlang.org" source: hosted - version: "4.0.4" + version: "4.1.0" watcher: dependency: transitive description: @@ -677,5 +677,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.9.0-11.0.dev <3.0.0" + dart: ">=2.9.0-14.0.dev <3.0.0" flutter: ">=1.19.0-3.0.pre <2.0.0"