Skip to content

Use visibility/export annotations for C++ code #216

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 2 commits into from
Jan 8, 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
2 changes: 2 additions & 0 deletions build/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ config("shared_library_defaults") {
cflags = [
"-shared",
"-fPIC",
# Default to hidden for consistency with Windows builds.
"-fvisibility=hidden",
]
}
}
5 changes: 5 additions & 0 deletions library/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ published_shared_library("flutter_embedder") {
public += [
"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_method_codec.h",
"include/flutter_desktop_embedding/method_call.h",
"include/flutter_desktop_embedding/method_channel.h",
Expand All @@ -60,6 +61,10 @@ published_shared_library("flutter_embedder") {
":fetch_flutter_engine",
]

defines = [
"FLUTTER_DESKTOP_EMBEDDING_IMPL",
]

public_header_subdir = "flutter_desktop_embedding"

public_configs = [
Expand Down
4 changes: 3 additions & 1 deletion library/include/flutter_desktop_embedding/binary_messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <functional>
#include <string>

#include "fde_export.h"

// TODO: Consider adding absl as a dependency and using absl::Span for all of
// the message/message_size pairs.
namespace flutter_desktop_embedding {
Expand All @@ -36,7 +38,7 @@ typedef std::function<void(const uint8_t *message, const size_t message_size,

// A protocol for a class that handles communication of binary data on named
// channels to and from the Flutter engine.
class BinaryMessenger {
class FDE_EXPORT BinaryMessenger {
public:
// Sends a binary message to the Flutter side on the specified channel,
// expecting no reply.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <vector>

#include "binary_messenger.h"
#include "fde_export.h"
#include "method_codec.h"
#include "method_result.h"

Expand All @@ -28,7 +29,7 @@ namespace internal {
// Manages the one-time sending of response data. This is an internal helper
// class for EngineMethodResult, separated out since the implementation doesn't
// vary based on the template type.
class ReplyManager {
class FDE_EXPORT ReplyManager {
public:
ReplyManager(BinaryReply reply_handler_);
~ReplyManager();
Expand All @@ -50,7 +51,7 @@ class ReplyManager {
// Implemention of MethodResult that sends a response to the Flutter engine
// exactly once, encoded using a given codec.
template <typename T>
class EngineMethodResult : public MethodResult<T> {
class FDE_EXPORT EngineMethodResult : public MethodResult<T> {
public:
// Creates a result object that will send results to |reply_handler|, encoded
// using |codec|. The |codec| pointer must remain valid for as long as this
Expand Down
37 changes: 37 additions & 0 deletions library/include/flutter_desktop_embedding/fde_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.
#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_FDE_EXPORT_H_
#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_FDE_EXPORT_H_

#ifdef FLUTTER_DESKTOP_EMBEDDING_IMPL
// Add visibiilty/export annotations when building the library.

#ifdef _WIN32
#define FDE_EXPORT __declspec(dllexport)
#else
#define FDE_EXPORT __attribute__((visibility("default")))
#endif

#else

// Add import annotations when consuming the library.
#ifdef _WIN32
#define FDE_EXPORT __declspec(dllimport)
#else
#define FDE_EXPORT
#endif

#endif

#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_FDE_EXPORT_H_
25 changes: 13 additions & 12 deletions library/include/flutter_desktop_embedding/glfw/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
#include <GLFW/glfw3.h>

#ifdef USE_FLATTENED_INCLUDES
#include "fde_export.h"
#include "plugin_registrar.h"
#else
#include "../fde_export.h"
#include "../plugin_registrar.h"
#endif

Expand All @@ -37,12 +39,12 @@ namespace flutter_desktop_embedding {
// Calls glfwInit()
//
// glfwInit() must be called in the same library as glfwCreateWindow()
bool FlutterInit();
FDE_EXPORT bool FlutterInit();

// Calls glfwTerminate()
//
// glfwTerminate() must be called in the same library as glfwCreateWindow()
void FlutterTerminate();
FDE_EXPORT void FlutterTerminate();

// Creates a GLFW Window running a Flutter Application.
//
Expand All @@ -54,12 +56,11 @@ void FlutterTerminate();
//
// Returns a null pointer in the event of an error. The caller owns the pointer
// when it is non-null.
GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height,
const std::string &main_path,
const std::string &assets_path,
const std::string &packages_path,
const std::string &icu_data_path,
const std::vector<std::string> &arguments);
FDE_EXPORT GLFWwindow *CreateFlutterWindow(
size_t initial_width, size_t initial_height, const std::string &main_path,
const std::string &assets_path, const std::string &packages_path,
const std::string &icu_data_path,
const std::vector<std::string> &arguments);

// Creates a GLFW Window running a Flutter Application in snapshot mode.
//
Expand All @@ -74,7 +75,7 @@ GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height,
//
// Returns a null pointer in the event of an error. The caller owns the pointer
// when it is non-null.
GLFWwindow *CreateFlutterWindowInSnapshotMode(
FDE_EXPORT GLFWwindow *CreateFlutterWindowInSnapshotMode(
size_t initial_width, size_t initial_height, const std::string &assets_path,
const std::string &icu_data_path,
const std::vector<std::string> &arguments);
Expand All @@ -84,8 +85,8 @@ GLFWwindow *CreateFlutterWindowInSnapshotMode(
//
// The name must be unique across the application, so the recommended approach
// is to use the fully namespace-qualified name of the plugin class.
PluginRegistrar *GetRegistrarForPlugin(GLFWwindow *flutter_window,
const std::string &plugin_name);
FDE_EXPORT PluginRegistrar *GetRegistrarForPlugin(
GLFWwindow *flutter_window, const std::string &plugin_name);

// Loops on flutter window events until termination.
//
Expand All @@ -94,7 +95,7 @@ PluginRegistrar *GetRegistrarForPlugin(GLFWwindow *flutter_window,
//
// After this function the user must eventually call FlutterTerminate() if doing
// cleanup.
void FlutterWindowLoop(GLFWwindow *flutter_window);
FDE_EXPORT void FlutterWindowLoop(GLFWwindow *flutter_window);

} // namespace flutter_desktop_embedding

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

#include <json/json.h>

#include "fde_export.h"
#include "method_call.h"
#include "method_codec.h"

namespace flutter_desktop_embedding {

// An implementation of MethodCodec that uses JSON strings as the serialization.
class JsonMethodCodec : public MethodCodec<Json::Value> {
class FDE_EXPORT JsonMethodCodec : public MethodCodec<Json::Value> {
public:
// Returns the shared instance of the codec.
static const JsonMethodCodec &GetInstance();
Expand Down
4 changes: 3 additions & 1 deletion library/include/flutter_desktop_embedding/method_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#include <memory>
#include <string>

#include "fde_export.h"

namespace flutter_desktop_embedding {

// An object encapsulating a method call from Flutter whose arguments are of
// type T.
template <typename T>
class MethodCall {
class FDE_EXPORT MethodCall {
public:
// Creates a MethodCall with the given name and arguments.
explicit MethodCall(const std::string &method_name,
Expand Down
3 changes: 2 additions & 1 deletion library/include/flutter_desktop_embedding/method_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "binary_messenger.h"
#include "engine_method_result.h"
#include "fde_export.h"
#include "method_call.h"
#include "method_codec.h"
#include "method_result.h"
Expand All @@ -36,7 +37,7 @@ using MethodCallHandler = std::function<void(
// A channel for communicating with the Flutter engine using invocation of
// asynchronous methods.
template <typename T>
class MethodChannel {
class FDE_EXPORT MethodChannel {
public:
// Creates an instance that sends and receives method calls on the channel
// named |name|, encoded with |codec| and dispatched via |messenger|.
Expand Down
3 changes: 2 additions & 1 deletion library/include/flutter_desktop_embedding/method_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
#include <string>
#include <vector>

#include "fde_export.h"
#include "method_call.h"

namespace flutter_desktop_embedding {

// Translates between a binary message and higher-level method call and
// response/error objects.
template <typename T>
class MethodCodec {
class FDE_EXPORT MethodCodec {
public:
MethodCodec() = default;
virtual ~MethodCodec() = default;
Expand Down
4 changes: 3 additions & 1 deletion library/include/flutter_desktop_embedding/method_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

#include <string>

#include "fde_export.h"

namespace flutter_desktop_embedding {

// Encapsulates a result sent back to the Flutter engine in response to a
// MethodCall. Only one method should be called on any given instance.
template <typename T>
class MethodResult {
class FDE_EXPORT MethodResult {
public:
MethodResult() = default;
virtual ~MethodResult() = default;
Expand Down
5 changes: 3 additions & 2 deletions library/include/flutter_desktop_embedding/plugin_registrar.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <memory>

#include "binary_messenger.h"
#include "fde_export.h"

namespace flutter_desktop_embedding {

Expand All @@ -27,7 +28,7 @@ class Plugin;
// Currently this class has very limited functionality, but is expected to
// expand over time to more closely match the functionality of
// the Flutter mobile plugin APIs' plugin registrars.
class PluginRegistrar {
class FDE_EXPORT PluginRegistrar {
public:
virtual ~PluginRegistrar() {}

Expand All @@ -53,7 +54,7 @@ class PluginRegistrar {
};

// A plugin that can be registered for ownership by a PluginRegistrar.
class Plugin {
class FDE_EXPORT Plugin {
public:
virtual ~Plugin() {}
};
Expand Down
3 changes: 2 additions & 1 deletion library/linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ ENGINE_UPDATER=$(TOOLS_DIR)/update_flutter_engine
FLUTTER_DIR=$(shell "$(TOOLS_DIR)/flutter_location")
LIBRARY_OUT=libflutter_embedder.so
CXX=g++ -std=c++14
CXXFLAGS= -Wall -Werror -shared -fPIC \
CXXFLAGS= -Wall -Werror -shared -fPIC -fvisibility=hidden \
-I$(PROJECT_ROOT) \
-I$(PROJECT_ROOT)/library/include \
-I$(FLUTTER_ENGINE_HEADER_DIR) \
-DFLUTTER_DESKTOP_EMBEDDING_IMPL \
$(shell pkg-config --cflags gtk+-3.0 epoxy x11 jsoncpp)
LDFLAGS= -L$(CURDIR) \
$(shell pkg-config --libs gtk+-3.0 epoxy x11 jsoncpp) \
Expand Down
11 changes: 6 additions & 5 deletions library/windows/GLFW Library.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PreprocessorDefinitions>_WINDLL;FLUTTER_DESKTOP_EMBEDDING_IMPL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>flutter_engine.dll.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies);json_vc71_libmtd.lib</AdditionalDependencies>
</Link>
<Link>
<ModuleDefinitionFile>exports.def</ModuleDefinitionFile>
<ModuleDefinitionFile>
</ModuleDefinitionFile>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<ImportLibrary>$(OutDir)$(TargetName).lib</ImportLibrary>
<ProgramDatabaseFile>$(OutDir)$(TargetName).pdb</ProgramDatabaseFile>
Expand Down Expand Up @@ -109,12 +111,14 @@
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PreprocessorDefinitions>_WINDLL;FLUTTER_DESKTOP_EMBEDDING_IMPL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>flutter_engine.dll.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies);json_vc71_libmt.lib</AdditionalDependencies>
<ModuleDefinitionFile>exports.def</ModuleDefinitionFile>
<ModuleDefinitionFile>
</ModuleDefinitionFile>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<ImportLibrary>$(OutDir)$(TargetName).lib</ImportLibrary>
<ProgramDatabaseFile>$(OutDir)$(TargetName).pdb</ProgramDatabaseFile>
Expand Down Expand Up @@ -154,9 +158,6 @@
<ItemGroup>
<ClInclude Include="..\include\flutter_desktop_embedding\windows\embedder.h" />
</ItemGroup>
<ItemGroup>
<None Include="exports.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
5 changes: 0 additions & 5 deletions library/windows/GLFW Library.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="exports.def">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\flutter_desktop_embedding\windows\embedder.h">
<Filter>Header Files</Filter>
Expand Down
22 changes: 0 additions & 22 deletions library/windows/exports.def

This file was deleted.

5 changes: 4 additions & 1 deletion plugins/color_panel/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ published_shared_library("color_panel") {
]
}

defines = ["USE_FLATTENED_INCLUDES"]
defines = [
"COLOR_PANEL_PLUGIN_IMPL",
"USE_FLATTENED_INCLUDES",
]

deps = [
"//library:flutter_embedder",
Expand Down
Loading