Skip to content

Commit

Permalink
as-macros-private.h: Define macros for visibility for clang-cl
Browse files Browse the repository at this point in the history
On clang-cl (i.e. Visual Studio-like meaning _MSC_VER is defined) builds,
symbols in shared builds have visibility to be hidden by default, and
decorating symbols with GCC's default visibility is not enough to export the
symbol.

Some private symbols must still be exported from the appstream DLL for the
tools and tests, so define versions of the visibility macros that are suitable
for use for clang-cl, and add another (private) macro that is used to export
symbols that do not fall into sections where we explicitly want visibility to
be hidden.

Consequently, use the macros in as-desktop-entry.h so that we don't fall into
the situation where clang-cl complains as we are attempting to do a
__declspec(dllexport) in a hidden visibility section.
  • Loading branch information
fanc999-1 committed Oct 24, 2023
1 parent 6e990b2 commit 6d97607
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/as-desktop-entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
#include "as-metadata.h"
#include "as-utils-private.h"

G_BEGIN_DECLS
#pragma GCC visibility push(hidden)
AS_BEGIN_PRIVATE_DECLS

typedef GPtrArray *(*AsTranslateDesktopTextFn) (const GKeyFile *de,
const gchar *text,
Expand All @@ -54,7 +53,6 @@ gboolean as_desktop_entry_parse_file (AsComponent *cpt,
gpointer user_data,
GError **error);

#pragma GCC visibility pop
G_END_DECLS
AS_END_PRIVATE_DECLS

#endif /* __AS_DESKTOP_ENTRY_H */
21 changes: 21 additions & 0 deletions src/as-macros-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@
#include "as-macros.h"

G_BEGIN_DECLS

#ifdef _MSC_VER

#define AS_BEGIN_PRIVATE_DECLS G_BEGIN_DECLS
#define AS_END_PRIVATE_DECLS G_END_DECLS

#ifdef AS_STATIC
#else
#define AS_INTERNAL_VISIBLE __declspec(dllexport)
#endif

#define AS_INTERNAL_API AS_INTERNAL_VISIBLE

#else

#pragma GCC visibility push(hidden)

#define AS_BEGIN_PRIVATE_DECLS \
Expand All @@ -35,6 +50,9 @@ G_BEGIN_DECLS
#define AS_END_PRIVATE_DECLS _Pragma ("GCC visibility pop") G_END_DECLS

#define AS_INTERNAL_VISIBLE __attribute__((visibility("default")))
#define AS_INTERNAL_API

#endif

/**
* as_str_equal0:
Expand Down Expand Up @@ -107,7 +125,10 @@ G_BEGIN_DECLS
} \
G_STMT_END

#ifndef _MSC_VER
#pragma GCC visibility pop
#endif

G_END_DECLS

#endif /* __AS_MACROS_PRIVATE_H */

0 comments on commit 6d97607

Please sign in to comment.