Skip to content

Commit 3b9f3d4

Browse files
committed
Updated linux binaries & Built vslaunch script in dart
1 parent 3704f94 commit 3b9f3d4

22 files changed

+217
-155
lines changed
File renamed without changes.

linux/CMakeLists.txt

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set(BINARY_NAME "flutter_uis")
55

66
cmake_policy(SET CMP0063 NEW)
77

8-
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
8+
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
99

1010
# Configure build options.
1111
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
@@ -28,14 +28,19 @@ set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
2828
# Flutter library and tool build rules.
2929
add_subdirectory(${FLUTTER_MANAGED_DIR})
3030

31+
# System-level dependencies.
32+
find_package(PkgConfig REQUIRED)
33+
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
34+
3135
# Application build
3236
add_executable(${BINARY_NAME}
3337
"main.cc"
34-
"window_configuration.cc"
38+
"my_application.cc"
3539
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
3640
)
3741
apply_standard_settings(${BINARY_NAME})
38-
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
42+
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
43+
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
3944
add_dependencies(${BINARY_NAME} flutter_assemble)
4045

4146
# Generated plugin build rules, which manage building the plugins and adding
@@ -46,32 +51,45 @@ include(flutter/generated_plugins.cmake)
4651
# === Installation ===
4752
# By default, "installing" just makes a relocatable bundle in the build
4853
# directory.
54+
set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
4955
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
50-
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/bundle" CACHE PATH "..." FORCE)
56+
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
5157
endif()
5258

59+
# Start with a clean build bundle directory every time.
60+
install(CODE "
61+
file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
62+
" COMPONENT Runtime)
63+
5364
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
5465
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
5566

5667
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
5768
COMPONENT Runtime)
5869

59-
file(GLOB FLUTTER_PLUGIN_DIRS "${PROJECT_BINARY_DIR}/plugins/*")
60-
61-
INSTALL(CODE "
62-
include(BundleUtilities)
63-
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${BINARY_NAME}\" \"\"
64-
\"${FLUTTER_PLUGIN_DIRS};${FLUTTER_LIBRARY_DIR}\")
65-
" COMPONENT Runtime)
70+
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
71+
COMPONENT Runtime)
6672

67-
INSTALL(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
73+
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
6874
COMPONENT Runtime)
6975

76+
if(PLUGIN_BUNDLED_LIBRARIES)
77+
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
78+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
79+
COMPONENT Runtime)
80+
endif()
81+
7082
# Fully re-copy the assets directory on each build to avoid having stale files
7183
# from a previous install.
7284
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
73-
INSTALL(CODE "
85+
install(CODE "
7486
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
7587
" COMPONENT Runtime)
76-
INSTALL(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
88+
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
7789
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
90+
91+
# Install the AOT library on non-Debug builds only.
92+
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
93+
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
94+
COMPONENT Runtime)
95+
endif()

linux/flutter/.template_version

Lines changed: 0 additions & 1 deletion
This file was deleted.

linux/flutter/CMakeLists.txt

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
77

88
# TODO: Move the rest of this into files in ephemeral. See
99
# https://github.com/flutter/flutter/issues/57146.
10-
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper_glfw")
1110

1211
# Serves the same purpose as list(TRANSFORM ... PREPEND ...),
1312
# which isn't available in 3.10.
@@ -20,79 +19,61 @@ function(list_prepend LIST_NAME PREFIX)
2019
endfunction()
2120

2221
# === Flutter Library ===
23-
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_glfw.so")
22+
# System-level dependencies.
23+
find_package(PkgConfig REQUIRED)
24+
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
25+
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
26+
pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
27+
28+
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
2429

2530
# Published to parent scope for install step.
26-
set(FLUTTER_LIBRARY_DIR "${EPHEMERAL_DIR}" PARENT_SCOPE)
31+
set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
2732
set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
2833
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
34+
set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
2935

3036
list(APPEND FLUTTER_LIBRARY_HEADERS
31-
"flutter_export.h"
32-
"flutter_glfw.h"
33-
"flutter_messenger.h"
34-
"flutter_plugin_registrar.h"
37+
"fl_basic_message_channel.h"
38+
"fl_binary_codec.h"
39+
"fl_binary_messenger.h"
40+
"fl_dart_project.h"
41+
"fl_engine.h"
42+
"fl_json_message_codec.h"
43+
"fl_json_method_codec.h"
44+
"fl_message_codec.h"
45+
"fl_method_call.h"
46+
"fl_method_channel.h"
47+
"fl_method_codec.h"
48+
"fl_method_response.h"
49+
"fl_plugin_registrar.h"
50+
"fl_plugin_registry.h"
51+
"fl_standard_message_codec.h"
52+
"fl_standard_method_codec.h"
53+
"fl_string_codec.h"
54+
"fl_value.h"
55+
"fl_view.h"
56+
"flutter_linux.h"
3557
)
36-
list_prepend(FLUTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/")
58+
list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
3759
add_library(flutter INTERFACE)
3860
target_include_directories(flutter INTERFACE
3961
"${EPHEMERAL_DIR}"
4062
)
4163
target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
42-
add_dependencies(flutter flutter_assemble)
43-
44-
# === Wrapper ===
45-
list(APPEND CPP_WRAPPER_SOURCES_CORE
46-
"engine_method_result.cc"
47-
"standard_codec.cc"
48-
)
49-
list_prepend(CPP_WRAPPER_SOURCES_CORE "${WRAPPER_ROOT}/")
50-
list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
51-
"plugin_registrar.cc"
52-
)
53-
list_prepend(CPP_WRAPPER_SOURCES_PLUGIN "${WRAPPER_ROOT}/")
54-
list(APPEND CPP_WRAPPER_SOURCES_APP
55-
"flutter_engine.cc"
56-
"flutter_window_controller.cc"
57-
)
58-
list_prepend(CPP_WRAPPER_SOURCES_APP "${WRAPPER_ROOT}/")
59-
60-
# Wrapper sources needed for a plugin.
61-
add_library(flutter_wrapper_plugin STATIC
62-
${CPP_WRAPPER_SOURCES_CORE}
63-
${CPP_WRAPPER_SOURCES_PLUGIN}
64-
)
65-
apply_standard_settings(flutter_wrapper_plugin)
66-
set_target_properties(flutter_wrapper_plugin PROPERTIES
67-
POSITION_INDEPENDENT_CODE ON)
68-
set_target_properties(flutter_wrapper_plugin PROPERTIES
69-
CXX_VISIBILITY_PRESET hidden)
70-
target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
71-
target_include_directories(flutter_wrapper_plugin PUBLIC
72-
"${WRAPPER_ROOT}/include"
73-
)
74-
add_dependencies(flutter_wrapper_plugin flutter_assemble)
75-
76-
# Wrapper sources needed for the runner.
77-
add_library(flutter_wrapper_app STATIC
78-
${CPP_WRAPPER_SOURCES_CORE}
79-
${CPP_WRAPPER_SOURCES_APP}
80-
)
81-
apply_standard_settings(flutter_wrapper_app)
82-
target_link_libraries(flutter_wrapper_app PUBLIC flutter)
83-
target_include_directories(flutter_wrapper_app PUBLIC
84-
"${WRAPPER_ROOT}/include"
64+
target_link_libraries(flutter INTERFACE
65+
PkgConfig::GTK
66+
PkgConfig::GLIB
67+
PkgConfig::GIO
8568
)
86-
add_dependencies(flutter_wrapper_app flutter_assemble)
69+
add_dependencies(flutter flutter_assemble)
8770

8871
# === Flutter tool backend ===
8972
# _phony_ is a non-existent file to force this command to run every time,
9073
# since currently there's no way to get a full input/output list from the
9174
# flutter tool.
9275
add_custom_command(
9376
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
94-
${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
95-
${CPP_WRAPPER_SOURCES_APP}
9677
${CMAKE_CURRENT_BINARY_DIR}/_phony_
9778
COMMAND ${CMAKE_COMMAND} -E env
9879
${FLUTTER_TOOL_ENVIRONMENT}
@@ -102,7 +83,4 @@ add_custom_command(
10283
add_custom_target(flutter_assemble DEPENDS
10384
"${FLUTTER_LIBRARY}"
10485
${FLUTTER_LIBRARY_HEADERS}
105-
${CPP_WRAPPER_SOURCES_CORE}
106-
${CPP_WRAPPER_SOURCES_PLUGIN}
107-
${CPP_WRAPPER_SOURCES_APP}
10886
)

linux/main.cc

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,6 @@
1-
#include <flutter/flutter_engine.h>
2-
#include <flutter/flutter_window_controller.h>
3-
#include <linux/limits.h>
4-
#include <unistd.h>
1+
#include "my_application.h"
52

6-
#include <cstdlib>
7-
#include <iostream>
8-
#include <memory>
9-
#include <vector>
10-
11-
#include "flutter/generated_plugin_registrant.h"
12-
#include "window_configuration.h"
13-
14-
namespace {
15-
16-
// Runs the application in headless mode, without a window.
17-
void RunHeadless(const std::string& icu_data_path,
18-
const std::string& assets_path,
19-
const std::vector<std::string>& arguments) {
20-
flutter::FlutterEngine engine;
21-
engine.Start(icu_data_path, assets_path, arguments);
22-
RegisterPlugins(&engine);
23-
while (true) {
24-
engine.RunEventLoopWithTimeout();
25-
}
26-
}
27-
28-
} // namespace
29-
30-
int main(int argc, char **argv) {
31-
std::string data_directory = "data";
32-
std::string assets_path = data_directory + "/flutter_assets";
33-
std::string icu_data_path = data_directory + "/icudtl.dat";
34-
35-
// Arguments for the Flutter Engine.
36-
std::vector<std::string> arguments;
37-
38-
flutter::FlutterWindowController flutter_controller(icu_data_path);
39-
flutter::WindowProperties window_properties = {};
40-
window_properties.title = kFlutterWindowTitle;
41-
window_properties.width = kFlutterWindowWidth;
42-
window_properties.height = kFlutterWindowHeight;
43-
44-
// Start the engine.
45-
if (!flutter_controller.CreateWindow(window_properties, assets_path,
46-
arguments)) {
47-
if (getenv("DISPLAY") == nullptr) {
48-
std::cout << "No DISPLAY; falling back to headless mode." << std::endl;
49-
RunHeadless(icu_data_path, assets_path, arguments);
50-
return EXIT_SUCCESS;
51-
}
52-
return EXIT_FAILURE;
53-
}
54-
RegisterPlugins(&flutter_controller);
55-
56-
// Run until the window is closed.
57-
while (flutter_controller.RunEventLoopWithTimeout()) {
58-
}
59-
return EXIT_SUCCESS;
3+
int main(int argc, char** argv) {
4+
g_autoptr(MyApplication) app = my_application_new();
5+
return g_application_run(G_APPLICATION(app), argc, argv);
606
}

linux/my_application.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "my_application.h"
2+
3+
#include <flutter_linux/flutter_linux.h>
4+
5+
#include "flutter/generated_plugin_registrant.h"
6+
7+
struct _MyApplication {
8+
GtkApplication parent_instance;
9+
};
10+
11+
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
12+
13+
// Implements GApplication::activate.
14+
static void my_application_activate(GApplication* application) {
15+
GtkWindow* window =
16+
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
17+
GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
18+
gtk_widget_show(GTK_WIDGET(header_bar));
19+
gtk_header_bar_set_title(header_bar, "flutter_uis");
20+
gtk_header_bar_set_show_close_button(header_bar, TRUE);
21+
gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
22+
gtk_window_set_default_size(window, 1280, 720);
23+
gtk_widget_show(GTK_WIDGET(window));
24+
25+
g_autoptr(FlDartProject) project = fl_dart_project_new();
26+
27+
FlView* view = fl_view_new(project);
28+
gtk_widget_show(GTK_WIDGET(view));
29+
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
30+
31+
fl_register_plugins(FL_PLUGIN_REGISTRY(view));
32+
33+
gtk_widget_grab_focus(GTK_WIDGET(view));
34+
}
35+
36+
static void my_application_class_init(MyApplicationClass* klass) {
37+
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
38+
}
39+
40+
static void my_application_init(MyApplication* self) {}
41+
42+
MyApplication* my_application_new() {
43+
return MY_APPLICATION(g_object_new(my_application_get_type(), nullptr));
44+
}

linux/my_application.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef FLUTTER_MY_APPLICATION_H_
2+
#define FLUTTER_MY_APPLICATION_H_
3+
4+
#include <gtk/gtk.h>
5+
6+
G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
7+
GtkApplication)
8+
9+
/**
10+
* my_application_new:
11+
*
12+
* Creates a new Flutter-based application.
13+
*
14+
* Returns: a new #MyApplication.
15+
*/
16+
MyApplication* my_application_new();
17+
18+
#endif // FLUTTER_MY_APPLICATION_H_

linux/window_configuration.cc

Lines changed: 0 additions & 5 deletions
This file was deleted.

linux/window_configuration.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

scripts/rt

Whitespace-only changes.

scripts/utils.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,20 @@ String normalize(String path) {
66
}
77
return path;
88
}
9+
10+
dynamic mkDir(String path, {bool logs = false}) {
11+
try {
12+
final file = Directory(path);
13+
final check = file.existsSync();
14+
if (logs) {
15+
print('path: $path');
16+
print('check: $check');
17+
}
18+
if (!check) {
19+
return file.createSync();
20+
}
21+
return check;
22+
} catch (e) {
23+
throw e;
24+
}
25+
}

0 commit comments

Comments
 (0)