Skip to content

Commit 175bfb4

Browse files
Add visibility/export annotations
Adds export macros, and annotations for all symbols that should be public. Switches the default for shared library builds on Linux to visibility=hidden so that missing annotations will be caught on both platforms, rather than just Windows. Fixes issue google#208
1 parent 123fea2 commit 175bfb4

File tree

22 files changed

+122
-32
lines changed

22 files changed

+122
-32
lines changed

build/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ config("shared_library_defaults") {
3838
cflags = [
3939
"-shared",
4040
"-fPIC",
41+
# Default to hidden for consistency with Windows builds.
42+
"-fvisibility=hidden",
4143
]
4244
}
4345
}

library/BUILD.gn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ published_shared_library("flutter_embedder") {
4747
public += [
4848
"include/flutter_desktop_embedding/binary_messenger.h",
4949
"include/flutter_desktop_embedding/engine_method_result.h",
50+
"include/flutter_desktop_embedding/fde_export.h",
5051
"include/flutter_desktop_embedding/json_method_codec.h",
5152
"include/flutter_desktop_embedding/method_call.h",
5253
"include/flutter_desktop_embedding/method_channel.h",
@@ -60,6 +61,10 @@ published_shared_library("flutter_embedder") {
6061
":fetch_flutter_engine",
6162
]
6263

64+
defines = [
65+
"FLUTTER_DESKTOP_EMBEDDING_IMPL",
66+
]
67+
6368
public_header_subdir = "flutter_desktop_embedding"
6469

6570
public_configs = [

library/include/flutter_desktop_embedding/binary_messenger.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <functional>
1818
#include <string>
1919

20+
#include "fde_export.h"
21+
2022
// TODO: Consider adding absl as a dependency and using absl::Span for all of
2123
// the message/message_size pairs.
2224
namespace flutter_desktop_embedding {
@@ -36,7 +38,7 @@ typedef std::function<void(const uint8_t *message, const size_t message_size,
3638

3739
// A protocol for a class that handles communication of binary data on named
3840
// channels to and from the Flutter engine.
39-
class BinaryMessenger {
41+
class FDE_EXPORT BinaryMessenger {
4042
public:
4143
// Sends a binary message to the Flutter side on the specified channel,
4244
// expecting no reply.

library/include/flutter_desktop_embedding/engine_method_result.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <vector>
2020

2121
#include "binary_messenger.h"
22+
#include "fde_export.h"
2223
#include "method_codec.h"
2324
#include "method_result.h"
2425

@@ -28,7 +29,7 @@ namespace internal {
2829
// Manages the one-time sending of response data. This is an internal helper
2930
// class for EngineMethodResult, separated out since the implementation doesn't
3031
// vary based on the template type.
31-
class ReplyManager {
32+
class FDE_EXPORT ReplyManager {
3233
public:
3334
ReplyManager(BinaryReply reply_handler_);
3435
~ReplyManager();
@@ -50,7 +51,7 @@ class ReplyManager {
5051
// Implemention of MethodResult that sends a response to the Flutter engine
5152
// exactly once, encoded using a given codec.
5253
template <typename T>
53-
class EngineMethodResult : public MethodResult<T> {
54+
class FDE_EXPORT EngineMethodResult : public MethodResult<T> {
5455
public:
5556
// Creates a result object that will send results to |reply_handler|, encoded
5657
// using |codec|. The |codec| pointer must remain valid for as long as this
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#ifndef LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_FDE_EXPORT_H_
15+
#define LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_FDE_EXPORT_H_
16+
17+
#ifdef FLUTTER_DESKTOP_EMBEDDING_IMPL
18+
// Add visibiilty/export annotations when building the library.
19+
20+
#ifdef _WIN32
21+
#define FDE_EXPORT __declspec(dllexport)
22+
#else
23+
#define FDE_EXPORT __attribute__((visibility("default")))
24+
#endif
25+
26+
#else
27+
28+
// Add import annotations when consuming the library.
29+
#ifdef _WIN32
30+
#define FDE_EXPORT __declspec(dllimport)
31+
#else
32+
#define FDE_EXPORT
33+
#endif
34+
35+
#endif
36+
37+
#endif // LIBRARY_INCLUDE_FLUTTER_DESKTOP_EMBEDDING_FDE_EXPORT_H_

library/include/flutter_desktop_embedding/glfw/embedder.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
#include <GLFW/glfw3.h>
2828

2929
#ifdef USE_FLATTENED_INCLUDES
30+
#include "fde_export.h"
3031
#include "plugin_registrar.h"
3132
#else
33+
#include "../fde_export.h"
3234
#include "../plugin_registrar.h"
3335
#endif
3436

@@ -37,12 +39,12 @@ namespace flutter_desktop_embedding {
3739
// Calls glfwInit()
3840
//
3941
// glfwInit() must be called in the same library as glfwCreateWindow()
40-
bool FlutterInit();
42+
FDE_EXPORT bool FlutterInit();
4143

4244
// Calls glfwTerminate()
4345
//
4446
// glfwTerminate() must be called in the same library as glfwCreateWindow()
45-
void FlutterTerminate();
47+
FDE_EXPORT void FlutterTerminate();
4648

4749
// Creates a GLFW Window running a Flutter Application.
4850
//
@@ -54,12 +56,11 @@ void FlutterTerminate();
5456
//
5557
// Returns a null pointer in the event of an error. The caller owns the pointer
5658
// when it is non-null.
57-
GLFWwindow *CreateFlutterWindow(size_t initial_width, size_t initial_height,
58-
const std::string &main_path,
59-
const std::string &assets_path,
60-
const std::string &packages_path,
61-
const std::string &icu_data_path,
62-
const std::vector<std::string> &arguments);
59+
FDE_EXPORT GLFWwindow *CreateFlutterWindow(
60+
size_t initial_width, size_t initial_height, const std::string &main_path,
61+
const std::string &assets_path, const std::string &packages_path,
62+
const std::string &icu_data_path,
63+
const std::vector<std::string> &arguments);
6364

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

9091
// Loops on flutter window events until termination.
9192
//
@@ -94,7 +95,7 @@ PluginRegistrar *GetRegistrarForPlugin(GLFWwindow *flutter_window,
9495
//
9596
// After this function the user must eventually call FlutterTerminate() if doing
9697
// cleanup.
97-
void FlutterWindowLoop(GLFWwindow *flutter_window);
98+
FDE_EXPORT void FlutterWindowLoop(GLFWwindow *flutter_window);
9899

99100
} // namespace flutter_desktop_embedding
100101

library/include/flutter_desktop_embedding/json_method_codec.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
#include <json/json.h>
1818

19+
#include "fde_export.h"
1920
#include "method_call.h"
2021
#include "method_codec.h"
2122

2223
namespace flutter_desktop_embedding {
2324

2425
// An implementation of MethodCodec that uses JSON strings as the serialization.
25-
class JsonMethodCodec : public MethodCodec<Json::Value> {
26+
class FDE_EXPORT JsonMethodCodec : public MethodCodec<Json::Value> {
2627
public:
2728
// Returns the shared instance of the codec.
2829
static const JsonMethodCodec &GetInstance();

library/include/flutter_desktop_embedding/method_call.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
#include <memory>
1818
#include <string>
1919

20+
#include "fde_export.h"
21+
2022
namespace flutter_desktop_embedding {
2123

2224
// An object encapsulating a method call from Flutter whose arguments are of
2325
// type T.
2426
template <typename T>
25-
class MethodCall {
27+
class FDE_EXPORT MethodCall {
2628
public:
2729
// Creates a MethodCall with the given name and arguments.
2830
explicit MethodCall(const std::string &method_name,

library/include/flutter_desktop_embedding/method_channel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "binary_messenger.h"
2121
#include "engine_method_result.h"
22+
#include "fde_export.h"
2223
#include "method_call.h"
2324
#include "method_codec.h"
2425
#include "method_result.h"
@@ -36,7 +37,7 @@ using MethodCallHandler = std::function<void(
3637
// A channel for communicating with the Flutter engine using invocation of
3738
// asynchronous methods.
3839
template <typename T>
39-
class MethodChannel {
40+
class FDE_EXPORT MethodChannel {
4041
public:
4142
// Creates an instance that sends and receives method calls on the channel
4243
// named |name|, encoded with |codec| and dispatched via |messenger|.

library/include/flutter_desktop_embedding/method_codec.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
#include <string>
1919
#include <vector>
2020

21+
#include "fde_export.h"
2122
#include "method_call.h"
2223

2324
namespace flutter_desktop_embedding {
2425

2526
// Translates between a binary message and higher-level method call and
2627
// response/error objects.
2728
template <typename T>
28-
class MethodCodec {
29+
class FDE_EXPORT MethodCodec {
2930
public:
3031
MethodCodec() = default;
3132
virtual ~MethodCodec() = default;

library/include/flutter_desktop_embedding/method_result.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
#include <string>
1818

19+
#include "fde_export.h"
20+
1921
namespace flutter_desktop_embedding {
2022

2123
// Encapsulates a result sent back to the Flutter engine in response to a
2224
// MethodCall. Only one method should be called on any given instance.
2325
template <typename T>
24-
class MethodResult {
26+
class FDE_EXPORT MethodResult {
2527
public:
2628
MethodResult() = default;
2729
virtual ~MethodResult() = default;

library/include/flutter_desktop_embedding/plugin_registrar.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <memory>
1818

1919
#include "binary_messenger.h"
20+
#include "fde_export.h"
2021

2122
namespace flutter_desktop_embedding {
2223

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

@@ -53,7 +54,7 @@ class PluginRegistrar {
5354
};
5455

5556
// A plugin that can be registered for ownership by a PluginRegistrar.
56-
class Plugin {
57+
class FDE_EXPORT Plugin {
5758
public:
5859
virtual ~Plugin() {}
5960
};

library/linux/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ ENGINE_UPDATER=$(TOOLS_DIR)/update_flutter_engine
2222
FLUTTER_DIR=$(shell "$(TOOLS_DIR)/flutter_location")
2323
LIBRARY_OUT=libflutter_embedder.so
2424
CXX=g++ -std=c++14
25-
CXXFLAGS= -Wall -Werror -shared -fPIC \
25+
CXXFLAGS= -Wall -Werror -shared -fPIC -fvisibility=hidden \
2626
-I$(PROJECT_ROOT) \
2727
-I$(PROJECT_ROOT)/library/include \
2828
-I$(FLUTTER_ENGINE_HEADER_DIR) \
29+
-DFLUTTER_DESKTOP_EMBEDDING_IMPL \
2930
$(shell pkg-config --cflags gtk+-3.0 epoxy x11 jsoncpp)
3031
LDFLAGS= -L$(CURDIR) \
3132
$(shell pkg-config --libs gtk+-3.0 epoxy x11 jsoncpp) \

plugins/color_panel/BUILD.gn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ published_shared_library("color_panel") {
3030
]
3131
}
3232

33-
defines = ["USE_FLATTENED_INCLUDES"]
33+
defines = [
34+
"COLOR_PANEL_PLUGIN_IMPL",
35+
"USE_FLATTENED_INCLUDES",
36+
]
3437

3538
deps = [
3639
"//library:flutter_embedder",

plugins/color_panel/linux/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ EMBEDDER_LIB_FILE=$(EMBEDDER_LIBRARY_OUT_DIR)/lib$(EMBEDDER_LIB_NAME).so
2424
COMMON_DIR=$(CURDIR)/../common
2525

2626
CXX=g++ -std=c++14
27-
CXXFLAGS= -Wall -Werror -shared -fPIC \
27+
CXXFLAGS= -Wall -Werror -shared -fPIC -fvisibility=hidden \
2828
-I$(PROJECT_ROOT) \
2929
-I$(EMBEDDER_LIBRARY_HEADER_DIR) \
30+
-DCOLOR_PANEL_PLUGIN_IMPL \
3031
$(shell pkg-config --cflags gtk+-3.0 jsoncpp)
3132
LDFLAGS= -L$(EMBEDDER_LIBRARY_OUT_DIR) \
3233
$(shell pkg-config --libs gtk+-3.0 jsoncpp) \

plugins/color_panel/linux/include/color_panel/color_panel_plugin.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@
2121
#include <flutter_desktop_embedding/method_channel.h>
2222
#include <flutter_desktop_embedding/plugin_registrar.h>
2323

24+
#ifdef COLOR_PANEL_PLUGIN_IMPL
25+
#define COLOR_PANEL_PLUGIN_EXPORT __attribute__((visibility("default")))
26+
#else
27+
#define COLOR_PANEL_PLUGIN_EXPORT
28+
#endif
29+
2430
namespace plugins_color_panel {
2531

2632
// A plugin for communicating with a native color picker panel.
27-
class ColorPanelPlugin : public flutter_desktop_embedding::Plugin {
33+
class COLOR_PANEL_PLUGIN_EXPORT ColorPanelPlugin
34+
: public flutter_desktop_embedding::Plugin {
2835
public:
2936
static void RegisterWithRegistrar(
3037
flutter_desktop_embedding::PluginRegistrar *registrar);

plugins/file_chooser/BUILD.gn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ published_shared_library("file_chooser") {
3030
]
3131
}
3232

33-
defines = ["USE_FLATTENED_INCLUDES"]
33+
defines = [
34+
"FILE_CHOOSER_PLUGIN_IMPL",
35+
"USE_FLATTENED_INCLUDES",
36+
]
3437

3538
deps = [
3639
"//library:flutter_embedder",

plugins/file_chooser/linux/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ EMBEDDER_LIB_FILE=$(EMBEDDER_LIBRARY_OUT_DIR)/lib$(EMBEDDER_LIB_NAME).so
2424
COMMON_DIR=$(CURDIR)/../common
2525

2626
CXX=g++ -std=c++14
27-
CXXFLAGS= -Wall -Werror -shared -fPIC \
27+
CXXFLAGS= -Wall -Werror -shared -fPIC -fvisibility=hidden \
2828
-I$(PROJECT_ROOT) \
2929
-I$(EMBEDDER_LIBRARY_HEADER_DIR) \
30+
-DFILE_CHOOSER_PLUGIN_IMPL \
3031
$(shell pkg-config --cflags gtk+-3.0 jsoncpp)
3132
LDFLAGS= -L$(EMBEDDER_LIBRARY_OUT_DIR) \
3233
$(shell pkg-config --libs gtk+-3.0 jsoncpp) \

plugins/file_chooser/linux/include/file_chooser/file_chooser_plugin.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@
2121
#include <flutter_desktop_embedding/method_channel.h>
2222
#include <flutter_desktop_embedding/plugin_registrar.h>
2323

24+
#ifdef FILE_CHOOSER_PLUGIN_IMPL
25+
#define FILE_CHOOSER_PLUGIN_EXPORT __attribute__((visibility("default")))
26+
#else
27+
#define FILE_CHOOSER_PLUGIN_EXPORT
28+
#endif
29+
2430
namespace plugins_file_chooser {
2531

2632
// Implements a file chooser plugin.
27-
class FileChooserPlugin : public flutter_desktop_embedding::Plugin {
33+
class FILE_CHOOSER_PLUGIN_EXPORT FileChooserPlugin
34+
: public flutter_desktop_embedding::Plugin {
2835
public:
2936
static void RegisterWithRegistrar(
3037
flutter_desktop_embedding::PluginRegistrar *registrar);

0 commit comments

Comments
 (0)