Skip to content

Move the C++ embedder code to a client wrapper #272

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

Merged
merged 5 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 21 additions & 4 deletions build/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.

default_static_configs = [ "//build:defaults" ]

default_dynamic_configs = [
"//build:defaults",
"//build:shared_library_defaults",
]

set_defaults("executable") {
configs = [ "//build:defaults" ]
configs = default_static_configs
}
set_defaults("static_library") {
configs = [ "//build:defaults" ]
configs = default_static_configs
}
set_defaults("source_set") {
configs = default_static_configs
}
set_defaults("shared_library") {
configs = [ "//build:defaults", "//build:shared_library_defaults" ]
configs = default_dynamic_configs
}
set_defaults("published_shared_library") {
configs = [ "//build:defaults", "//build:shared_library_defaults" ]
configs = default_dynamic_configs
}

if (host_os == "linux") {
Expand All @@ -40,3 +50,10 @@ if (host_os == "linux") {
is_mac = false
is_win = true
}

declare_args() {
# Whether to use the GLFW embedding implementation. Currently overriding this
# would not work since each platform only has one working implementation,
# but in the future GLFW may be one of multiple supported implementations.
use_glfw = is_linux || is_win
}
13 changes: 12 additions & 1 deletion example/linux_fde/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ BIN_OUT=$(OUT_DIR)/flutter_embedder_example
ICU_DATA_OUT=$(OUT_DATA_DIR)/$(ICU_DATA_NAME)
ALL_LIBS_OUT=$(foreach lib,$(ALL_LIBS),$(OUT_LIB_DIR)/$(notdir $(lib)))

# Add relevant code from the wrapper library, which is intended to be statically
# built into the client.
WRAPPER_ROOT = $(GN_OUT_DIR)/fde_cpp_wrapper
WRAPPER_SOURCES = \
$(WRAPPER_ROOT)/flutter_window_controller.cc \
$(WRAPPER_ROOT)/plugin_handler.cc \
$(WRAPPER_ROOT)/engine_method_result.cc
SOURCES += $(WRAPPER_SOURCES)
INCLUDE_DIRS += $(WRAPPER_ROOT)/include


# Build settings
CXX=g++ -std=c++14
CXXFLAGS.release=-DNDEBUG
Expand All @@ -104,7 +115,7 @@ $(BIN_OUT): $(SOURCES) $(ALL_LIBS_OUT)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(SOURCES) $(LDFLAGS) -o $@

.PHONY: gnbuild
gnbuild: $(GN_OUT_DIR)
gnbuild $(WRAPPER_SOURCES): $(GN_OUT_DIR)
$(NINJA_BIN) -C $(GN_OUT_DIR) $(FLUTTER_EMBEDDER_LIB_NAME) $(PLUGIN_NAMES)

$(GN_OUT_DIR):
Expand Down
11 changes: 8 additions & 3 deletions example/windows_fde/GLFW Example.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Dynamic Library|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\</OutDir>
<IntDir>$(SolutionDir)bin\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>$(ProjectDir)..\..\library\windows\dependencies\;$(ProjectDir)..\..\;$(IncludePath);$(ProjectDir)..\..\library\windows\;$(ProjectDir)..\..\library\include\</IncludePath>
<IncludePath>$(ProjectDir)..\..\library\windows\dependencies\;$(ProjectDir)..\..\;$(IncludePath);$(ProjectDir)..\..\library\windows\;$(ProjectDir)..\..\library\include\;$(ProjectDir)..\..\library\common\client_wrapper\include\</IncludePath>
<LibraryPath>$(ProjectDir)..\..\library\windows\dependencies\GLFW\;$(SolutionDir)bin\$(Platform)\$(Configuration)\GLFW Library\;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Dynamic Library|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\</OutDir>
<IntDir>$(SolutionDir)bin\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<IncludePath>$(ProjectDir)..\..\library\windows\dependencies\;$(ProjectDir)..\..\library\include\;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)..\..\library\windows\dependencies\;$(ProjectDir)..\..\;$(IncludePath);$(ProjectDir)..\..\library\windows\;$(ProjectDir)..\..\library\include\;$(ProjectDir)..\..\library\common\client_wrapper\include\</IncludePath>
<LibraryPath>$(ProjectDir)..\..\library\windows\dependencies\GLFW\;$(SolutionDir)bin\$(Platform)\$(Configuration)\GLFW Library\;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Dynamic Library|x64'">
Expand All @@ -62,6 +62,7 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);USE_FDE_TREE_PATHS</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>flutter_embedder.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down Expand Up @@ -91,6 +92,7 @@
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);USE_FDE_TREE_PATHS</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
Expand All @@ -113,6 +115,9 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\library\common\client_wrapper\src\engine_method_result.cc" />
<ClCompile Include="..\..\library\common\client_wrapper\src\glfw\flutter_window_controller.cc" />
<ClCompile Include="..\..\library\common\client_wrapper\src\plugin_handler.cc" />
<ClCompile Include="flutter_embedder_example.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -126,4 +131,4 @@
<PropertyGroup>
<LocalDebuggerWorkingDirectory>$(SolutionDir)</LocalDebuggerWorkingDirectory>
</PropertyGroup>
</Project>
</Project>
60 changes: 39 additions & 21 deletions example/windows_fde/GLFW Example.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="flutter_embedder_example.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Source Files\Client Wrapper">
<UniqueIdentifier>{2761a4b5-57b2-4d50-a677-d20ddc17a7f1}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="flutter_embedder_example.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\library\common\client_wrapper\src\engine_method_result.cc">
<Filter>Source Files\Client Wrapper</Filter>
</ClCompile>
<ClCompile Include="..\..\library\common\client_wrapper\src\glfw\flutter_window_controller.cc">
<Filter>Source Files\Client Wrapper</Filter>
</ClCompile>
<ClCompile Include="..\..\library\common\client_wrapper\src\json_message_codec.cc">
<Filter>Source Files\Client Wrapper</Filter>
</ClCompile>
<ClCompile Include="..\..\library\common\client_wrapper\src\json_method_codec.cc">
<Filter>Source Files\Client Wrapper</Filter>
</ClCompile>
<ClCompile Include="..\..\library\common\client_wrapper\src\plugin_handler.cc">
<Filter>Source Files\Client Wrapper</Filter>
</ClCompile>
</ItemGroup>
</Project>
47 changes: 14 additions & 33 deletions library/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,14 @@ import("//build/flutter.gni")
import("//build/packaging.gni")
import("//library/engine.gni")

declare_args() {
# Whether to use the GLFW embedding implementation. Currently overriding this
# would not work since each platform only has one working implementation,
# but in the future GLFW may be one of multiple supported implementations.
use_glfw = is_linux || is_win
}

published_shared_library("flutter_embedder") {
# GLFW embedding implementation.
if (use_glfw) {
public = [
"include/flutter_desktop_embedding/glfw/embedder.h",
"include/flutter_desktop_embedding/glfw/flutter_window_controller.h",
"include/flutter_desktop_embedding_core/glfw/embedder.h",
]
sources = [
"common/glfw/embedder.cc",
"common/glfw/flutter_window_controller.cc",
"common/glfw/key_event_handler.cc",
"common/glfw/key_event_handler.h",
"common/glfw/keyboard_hook_handler.h",
Expand All @@ -41,42 +32,32 @@ published_shared_library("flutter_embedder") {
]
}

deps = [
":flutter_engine",
]

# Embedding-agnostic shared C++.
if (is_linux || is_win) {
sources += [
"common/engine_method_result.cc",
"common/internal/incoming_message_dispatcher.cc",
"common/internal/incoming_message_dispatcher.h",
"common/internal/plugin_handler.cc",
"common/internal/plugin_handler.h",
"common/internal/text_input_model.cc",
"common/internal/text_input_model.h",
"common/json_message_codec.cc",
"common/json_method_codec.cc",
]
public += [
"include/flutter_desktop_embedding/basic_message_channel.h",
"include/flutter_desktop_embedding/binary_messenger.h",
"include/flutter_desktop_embedding/engine_method_result.h",
"include/flutter_desktop_embedding/fde_export.h",
"include/flutter_desktop_embedding/json_message_codec.h",
"include/flutter_desktop_embedding/json_method_codec.h",
"include/flutter_desktop_embedding/message_codec.h",
"include/flutter_desktop_embedding/method_call.h",
"include/flutter_desktop_embedding/method_channel.h",
"include/flutter_desktop_embedding/method_codec.h",
"include/flutter_desktop_embedding/method_result.h",
"include/flutter_desktop_embedding/plugin_registrar.h",
public += [ "include/flutter_desktop_embedding_core/fde_export.h" ]

deps += [
"//library/common/client_wrapper:client_wrapper_internal",
"//library/common/client_wrapper:publish_wrapper",
]
}

deps = [
":flutter_engine",
defines = [
"FLUTTER_DESKTOP_EMBEDDING_IMPL",
"USE_FDE_TREE_PATHS",
]

defines = [ "FLUTTER_DESKTOP_EMBEDDING_IMPL" ]

public_header_subdir = "flutter_desktop_embedding"
public_header_subdir = "flutter_desktop_embedding_core"

public_configs = [ ":relative_public_headers" ]

Expand Down
128 changes: 128 additions & 0 deletions library/common/client_wrapper/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

_wrapper_includes = [
"include/flutter_desktop_embedding/basic_message_channel.h",
"include/flutter_desktop_embedding/binary_messenger.h",
"include/flutter_desktop_embedding/engine_method_result.h",
"include/flutter_desktop_embedding/json_message_codec.h",
"include/flutter_desktop_embedding/json_method_codec.h",
"include/flutter_desktop_embedding/message_codec.h",
"include/flutter_desktop_embedding/method_call.h",
"include/flutter_desktop_embedding/method_channel.h",
"include/flutter_desktop_embedding/method_codec.h",
"include/flutter_desktop_embedding/method_result.h",
"include/flutter_desktop_embedding/plugin_registrar.h",
]

# TODO: Re-evaluate this once more codecs are supported, since most libraries
# won't need all the codecs.
_wrapper_sources = [
"src/engine_method_result.cc",
"src/json_message_codec.cc",
"src/json_method_codec.cc",
"src/plugin_handler.cc",
"src/plugin_handler.h",
]

_wrapper_publish_dir = "$root_out_dir/fde_cpp_wrapper"

# Template for building the wrapper code in two different modes.
# This is needed because the implementation of the embedding library
# uses this code internally, in addition to it being published for
# client use, but the internal version needs to set the flag that
# controls the export macro.
template("client_wrapper") {
template_target_name = target_name

source_set(template_target_name) {
forward_variables_from(invoker, "*")
}

source_set("${template_target_name}_internal") {
forward_variables_from(invoker, "*")

defines += [ "FLUTTER_DESKTOP_EMBEDDING_IMPL" ]
}
}

# A static library version of the client wrapper, for use both within the
# framework implementation itself, as well as with the plugin builds.
client_wrapper("client_wrapper") {
sources = _wrapper_sources
public = _wrapper_includes

# Use shared library settings since this target will be folded into shared
# libraries.
configs = default_dynamic_configs

if (is_linux) {
configs += [ "//build/linux/config:jsoncpp" ]
}
if (is_win) {
deps = [
"//third_party/jsoncpp:jsoncpp",
]
}

public_configs = [ ":_relative_headers" ]

# Since these sources are for client use, they are written assuming they will
# consume the embedder as a framework.
include_dirs = [ "//library/include/" ]

# Explicitly disable flattened headers, since this is being built in-tree.
# TODO: Simplify down to one define once Windows is using GN.
defines = [
"USE_FLATTENED_INCLUDES=0",
"USE_FDE_TREE_PATHS",
]
}

# Since this code is intended to be used by clients in a source bundle, the
# include paths use library-relative header paths rather than project-relative.
config("_relative_headers") {
include_dirs = [ "include" ]
}

copy("_publish_includes") {
sources = _wrapper_includes
if (use_glfw) {
sources +=
[ "include/flutter_desktop_embedding/glfw/flutter_window_controller.h" ]
}
output_dir = "$_wrapper_publish_dir/include/flutter_desktop_embedding"
outputs = [
"$output_dir/{{source_file_part}}",
]
}

copy("_publish_sources") {
sources = _wrapper_sources + [ "README" ]

if (use_glfw) {
sources += [ "src/glfw/flutter_window_controller.cc" ]
}
output_dir = "$_wrapper_publish_dir"
outputs = [
"$output_dir/{{source_file_part}}",
]
}

group("publish_wrapper") {
deps = [
":_publish_includes",
":_publish_sources",
]
}
Loading