[gjs: 1/2] meson, autotools: Hide non-exported symbols by default



commit 743f4da9dec46bc7df947fe85111a2786f82ef6f
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Sep 23 14:03:34 2019 +0200

    meson, autotools: Hide non-exported symbols by default
    
    Move jsapi generic symbols to a private static library and hide all the
    symbols by default, except the ones marked with GJS_EXPORT that is now
    setting the default visibility.
    Use then this static library to link dependent tools with (using the
    libgjs_dep definition in meson, instead of manually set the link_with).
    
    In order not to get C++ symbols exported we still need to use a map
    file to whitelist the gjs_ prefixed symbols.
    
    Fixes https://gitlab.gnome.org/GNOME/gjs/issues/194

 Makefile-test.am |  3 ++-
 Makefile.am      | 25 +++++++++++++++++++++++--
 gjs-srcs.mk      | 21 ++++++++++++---------
 gjs/macros.h     |  2 +-
 libgjs.map       |  5 -----
 libgjs.symbols   |  1 -
 meson.build      | 57 ++++++++++++++++++++++++++++++++++----------------------
 7 files changed, 73 insertions(+), 41 deletions(-)
---
diff --git a/Makefile-test.am b/Makefile-test.am
index be955493..89cb4d5b 100644
--- a/Makefile-test.am
+++ b/Makefile-test.am
@@ -61,6 +61,7 @@ gjs_tests_gtester_CPPFLAGS =                  \
 
 gjs_tests_gtester_LDADD =      \
        libgjs.la               \
+       libgjs-jsapi.la         \
        $(GJS_LIBS)
 
 gjs_tests_gtester_SOURCES =                            \
@@ -86,7 +87,7 @@ minijasmine_CPPFLAGS =                                \
        -DPKGLIBDIR=\"$(pkglibdir)\"            \
        $(NULL)
 
-minijasmine_LDADD = $(GJS_LIBS) libgjs.la
+minijasmine_LDADD = $(GJS_LIBS) libgjs.la libgjs-jsapi.la
 
 ### TEST GIRS ##########################################################
 
diff --git a/Makefile.am b/Makefile.am
index 9a5a9c97..1a682179 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -57,22 +57,42 @@ gjs_directory_defines =                             \
        -DPKGLIBDIR=\"$(pkglibdir)\"
 
 ########################################################################
+noinst_LTLIBRARIES = libgjs-jsapi.la
+
+libgjs_jsapi_la_CPPFLAGS =     \
+       $(AM_CPPFLAGS)          \
+       $(GJS_CFLAGS)           \
+       $(gjs_directory_defines)\
+       -I$(top_srcdir)/gi      \
+       -DGJS_COMPILATION
+libgjs_jsapi_la_LDFLAGS =      \
+       $(AM_LDFLAGS)           \
+       $(NO_UNDEFINED_FLAG)    \
+       $(NULL)
+libgjs_jsapi_la_LIBADD =       \
+       $(GJS_LIBS)             \
+       $(NULL)
+
+libgjs_jsapi_la_SOURCES = $(gjs_jsapi_srcs)
+
 lib_LTLIBRARIES += libgjs.la
 
 libgjs_la_CPPFLAGS =           \
        $(AM_CPPFLAGS)          \
        $(GJS_CFLAGS)   \
+       -fvisibility=hidden     \
        $(gjs_directory_defines)\
        -I$(top_srcdir)/gi      \
        -DGJS_COMPILATION
 libgjs_la_LDFLAGS =                    \
        $(AM_LDFLAGS)                   \
-       -export-symbols-regex "^[^_]"   \
+       -export-symbols-regex "^gjs_.*" \
        -version-info 0:0:0             \
        $(NO_UNDEFINED_FLAG)            \
        $(NULL)
 libgjs_la_LIBADD =             \
        $(GJS_LIBS)             \
+       libgjs-jsapi.la         \
        $(READLINE_LIBS)        \
        $(NULL)
 
@@ -167,7 +187,8 @@ gjs_console_CPPFLAGS =              \
        $(NULL)
 gjs_console_LDADD =            \
        $(GJS_CONSOLE_LIBS)     \
-       libgjs.la
+       libgjs.la               \
+       libgjs-jsapi.la
 gjs_console_LDFLAGS = $(AM_LDFLAGS) -rdynamic
 gjs_console_SOURCES = $(gjs_console_srcs)
 
diff --git a/gjs-srcs.mk b/gjs-srcs.mk
index 95022596..f02ad3a5 100644
--- a/gjs-srcs.mk
+++ b/gjs-srcs.mk
@@ -71,15 +71,6 @@ gjs_srcs =                           \
        gjs/global.h                    \
        gjs/importer.cpp                \
        gjs/importer.h                  \
-       gjs/jsapi-class.h               \
-       gjs/jsapi-dynamic-class.cpp     \
-       gjs/jsapi-util.cpp              \
-       gjs/jsapi-util.h                \
-       gjs/jsapi-util-args.h           \
-       gjs/jsapi-util-error.cpp        \
-       gjs/jsapi-util-root.h           \
-       gjs/jsapi-util-string.cpp       \
-       gjs/jsapi-wrapper.h             \
        gjs/mem.cpp                     \
        gjs/mem-private.h               \
        gjs/module.h                    \
@@ -91,6 +82,18 @@ gjs_srcs =                           \
        gjs/stack.cpp                   \
        modules/modules.cpp             \
        modules/modules.h               \
+       $(NULL)
+
+gjs_jsapi_srcs =                       \
+       gjs/jsapi-class.h               \
+       gjs/jsapi-dynamic-class.cpp     \
+       gjs/jsapi-util.cpp              \
+       gjs/jsapi-util.h                \
+       gjs/jsapi-util-args.h           \
+       gjs/jsapi-util-error.cpp        \
+       gjs/jsapi-util-root.h           \
+       gjs/jsapi-util-string.cpp       \
+       gjs/jsapi-wrapper.h             \
        util/log.cpp                    \
        util/log.h                      \
        util/misc.cpp                   \
diff --git a/gjs/macros.h b/gjs/macros.h
index 54383ce4..18b0b909 100644
--- a/gjs/macros.h
+++ b/gjs/macros.h
@@ -34,7 +34,7 @@
 # endif
 #    define siginfo_t void
 #else
-# define GJS_EXPORT
+#    define GJS_EXPORT __attribute__((visibility("default")))
 #endif
 
 /**
diff --git a/libgjs.map b/libgjs.map
index 74b34ec1..cef1fea7 100644
--- a/libgjs.map
+++ b/libgjs.map
@@ -1,11 +1,6 @@
-# Remove when https://gitlab.gnome.org/GNOME/gjs/issues/194 is completed
 {
 global:
     gjs_*;
-    extern "C++" {
-        gjs_*;
-        GjsContextPrivate::from_object*;
-    };
 local:
     *;
 };
diff --git a/libgjs.symbols b/libgjs.symbols
index 5ebe9e4c..a78269ef 100644
--- a/libgjs.symbols
+++ b/libgjs.symbols
@@ -2,7 +2,6 @@
 # Linker scripts are not understood by the macOS linker, we need to use a
 # symbol export file instead.
 # With autotools, this was all done transparently by -export-symbols-regex.
-# Remove when https://gitlab.gnome.org/GNOME/gjs/issues/194 is completed
 _gjs_*
 __Z*[0-9]gjs_*
 __ZN*GjsContextPrivate*from_object*
diff --git a/meson.build b/meson.build
index 46a2eae0..d1553034 100644
--- a/meson.build
+++ b/meson.build
@@ -369,14 +369,6 @@ libgjs_sources = [
     'gjs/error-types.cpp',
     'gjs/global.cpp', 'gjs/global.h',
     'gjs/importer.cpp', 'gjs/importer.h',
-    'gjs/jsapi-class.h',
-    'gjs/jsapi-dynamic-class.cpp',
-    'gjs/jsapi-util.cpp', 'gjs/jsapi-util.h',
-    'gjs/jsapi-util-args.h',
-    'gjs/jsapi-util-error.cpp',
-    'gjs/jsapi-util-root.h',
-    'gjs/jsapi-util-string.cpp',
-    'gjs/jsapi-wrapper.h',
     'gjs/mem.cpp', 'gjs/mem-private.h',
     'gjs/module.cpp', 'gjs/module.h',
     'gjs/native.cpp', 'gjs/native.h',
@@ -385,8 +377,6 @@ libgjs_sources = [
     'modules/console.cpp', 'modules/console.h',
     'modules/modules.cpp', 'modules/modules.h',
     'modules/system.cpp', 'modules/system.h',
-    'util/log.cpp', 'util/log.h',
-    'util/misc.cpp', 'util/misc.h',
 ]
 
 # GjsPrivate introspection sources
@@ -395,6 +385,19 @@ libgjs_private_sources = [
     'libgjs-private/gjs-util.c', 'libgjs-private/gjs-util.h',
 ]
 
+libgjs_jsapi_sources = [
+    'gjs/jsapi-class.h',
+    'gjs/jsapi-dynamic-class.cpp',
+    'gjs/jsapi-util-args.h',
+    'gjs/jsapi-util-error.cpp',
+    'gjs/jsapi-util-root.h',
+    'gjs/jsapi-util-string.cpp',
+    'gjs/jsapi-util.cpp', 'gjs/jsapi-util.h',
+    'gjs/jsapi-wrapper.h',
+    'util/log.cpp', 'util/log.h',
+    'util/misc.cpp', 'util/misc.h',
+]
+
 module_cairo_srcs = [
     'modules/cairo-private.h',
     'modules/cairo-module.h',
@@ -437,15 +440,7 @@ if build_profiler
     libgjs_dependencies += profiler_deps
 endif
 
-symbol_map = files('libgjs.map')
-symbol_list = files('libgjs.symbols')
-link_args = cxx.get_supported_link_arguments([
-    '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(),
-        symbol_map[0]),
-    '-Wl,-exported_symbols_list,@0@/@1@'.format(meson.current_source_dir(),
-        symbol_list[0]),  # macOS linker
-])
-
+link_args = []
 if cxx.has_link_argument('-Wl,-no-undefined')
     link_args += '-Wl,-no-undefined'
 else
@@ -454,7 +449,7 @@ else
     link_args += cxx.get_supported_link_arguments('-Wl,-undefined,error')
 endif
 
-libgjs_cpp_args = ['-DGJS_COMPILATION']
+libgjs_cpp_args = ['-DGJS_COMPILATION'] + directory_defines
 
 # Check G-I and/or Meson on this one.
 libgjs_cpp_args += ['-DG_LOG_DOMAIN="Gjs"']
@@ -464,19 +459,37 @@ if host_machine.system() == 'windows'
     libgjs_cpp_args += ['-DWIN32', '-DXP_WIN']
 endif
 
+libgjs_jsapi = static_library(meson.project_name() + '-jsapi',
+    libgjs_jsapi_sources, probes_header, probes_objfile,
+    cpp_args: libgjs_cpp_args,
+    link_args: link_args,
+    dependencies: libgjs_dependencies,
+    install: false)
+
+symbol_map = files('libgjs.map')
+symbol_list = files('libgjs.symbols')
+link_args += cxx.get_supported_link_arguments([
+    '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(),
+        symbol_map[0]),
+    '-Wl,-exported_symbols_list,@0@/@1@'.format(meson.current_source_dir(),
+        symbol_list[0]),  # macOS linker
+])
+
 libgjs = shared_library(meson.project_name(),
     libgjs_sources, libgjs_private_sources, module_resource_srcs,
     probes_header, probes_objfile,
-    cpp_args: libgjs_cpp_args + directory_defines,
+    cpp_args: libgjs_cpp_args,
     link_args: link_args, link_depends: [symbol_map, symbol_list],
+    link_with: libgjs_jsapi,
     dependencies: libgjs_dependencies,
     version: '0.0.0', soversion: '0',
+    gnu_symbol_visibility: 'hidden',
     install: true)
 
 install_headers(gjs_public_headers, subdir: api_name / 'gjs')
 
 # Allow using libgjs as a subproject
-libgjs_dep = declare_dependency(link_with: libgjs,
+libgjs_dep = declare_dependency(link_with: [libgjs, libgjs_jsapi],
     dependencies: libgjs_dependencies, include_directories: top_include)
 
 ### Build GjsPrivate introspection library #####################################


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]