Skip to content

Commit 1ec3054

Browse files
committed
feat: improve shared library build to export only public symbols
1 parent e8ad529 commit 1ec3054

File tree

9 files changed

+51
-8
lines changed

9 files changed

+51
-8
lines changed

scripts/exports.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
# Print exported symbols for a DLL on Windows
3+
# from: https://nullprogram.com/blog/2021/05/31/
4+
set -e
5+
printf 'LIBRARY %s\nEXPORTS\n' "$1"
6+
objdump -p "$1" | awk '/^$/{t=0} {if(t)print$NF} /^\[O/{t=1}'
7+

src/defs.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,23 @@
1111
# define __END_DECLS /* empty */
1212
#endif
1313

14+
#if defined(_WIN32) || defined(__CYGWIN__)
15+
# define _grtk_export __declspec(dllexport)
16+
# define _grtk_import __declspec(dllimport)
17+
#elif defined(__GNUC__) && (__GNUC__ >= 4)
18+
# define _grtk_export __attribute__((__visibility__("default")))
19+
# define _grtk_import
20+
#else
21+
# define _grtk_export
22+
# define _grtk_import
23+
#endif
24+
25+
#ifdef GRAPH_TK_COMPILATION
26+
# define _grtk_api _grtk_export
27+
#else
28+
# define _grtk_api _grtk_import
29+
#endif
30+
31+
#define grtk_public _grtk_api extern
32+
1433
#endif

src/lua-draw.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern "C" {
2929
#include "lua-compat.h"
3030
#include "lua-draw.h"
3131
#include "lua-graph.h"
32+
#include "lua-graph-priv.h"
3233
#include "text-shape.h"
3334
#include "lua-cpp-utils.h"
3435
#include "gs-types.h"

src/lua-graph-priv.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef LUA_GRAPH_PRIV_H
2+
#define LUA_GRAPH_PRIV_H
3+
4+
#include <pthread.h>
5+
6+
#include "defs.h"
7+
8+
__BEGIN_DECLS
9+
10+
extern pthread_mutex_t agg_mutex[1];
11+
12+
#define AGG_LOCK() pthread_mutex_lock (agg_mutex);
13+
#define AGG_UNLOCK() pthread_mutex_unlock (agg_mutex);
14+
15+
__END_DECLS
16+
17+
#endif
18+

src/lua-graph.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ extern "C" {
2323
#include <lauxlib.h>
2424
}
2525

26+
#define GRAPH_TK_COMPILATION
2627
#include "lua-graph.h"
28+
#include "lua-graph-priv.h"
2729
#include "fonts.h"
2830
#include "window_registry.h"
2931
#include "lua-draw.h"

src/lua-graph.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
#ifndef LUA_GRAPH_H
22
#define LUA_GRAPH_H
33

4-
#include <pthread.h>
5-
64
#include "defs.h"
75

86
__BEGIN_DECLS
97

108
#include <lua.h>
119

12-
extern int luaopen_graphcore (lua_State *L);
13-
14-
extern pthread_mutex_t agg_mutex[1];
15-
16-
#define AGG_LOCK() pthread_mutex_lock (agg_mutex);
17-
#define AGG_UNLOCK() pthread_mutex_unlock (agg_mutex);
10+
grtk_public int luaopen_graphcore (lua_State *L);
1811

1912
__END_DECLS
2013

src/lua-plot.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern "C" {
2828
#include "lua-plot-cpp.h"
2929
#include "window_hooks.h"
3030
#include "lua-graph.h"
31+
#include "lua-graph-priv.h"
3132
#include "lua-cpp-utils.h"
3233
#include "bitmap-plot.h"
3334
#include "gs-types.h"

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ libgraph = shared_library('graphcore',
6363
c_args : graph_toolkit_c_args,
6464
cpp_args : graph_toolkit_c_args,
6565
link_args : graph_toolkit_link_args,
66+
gnu_symbol_visibility : 'hidden',
6667
name_prefix : '',
6768
install_dir : 'lib/lua/5.4',
6869
install : true,

src/window.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern "C" {
66

77
#include "lua-compat.h"
88
#include "lua-defs.h"
9+
#include "lua-graph-priv.h"
910
#include "window-cpp.h"
1011
#include "window_registry.h"
1112
#include "lua-cpp-utils.h"

0 commit comments

Comments
 (0)