Skip to content

Commit

Permalink
Cleanup visibility macros (#39375)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/yoga#1372

Pull Request resolved: #39375

D18029030 added `-fvisibility-hidden`, and a corresponding `YOGA_EXPORT` macro for defining shared library visibility. This is used inline next to function and class definitions that should be exported out of the binary.

There was already a `WIN_EXPORT` macro doing the same thing when building a DLL, defined in the headers instead of CPP files, and it seems like sometimes folks forgot to add it to new public APIs after?

This reconciles the redundant macros into a single visibility macro, that we always place with declaration instead of definition. We also rename `YOGA_EXPORT` to `YG_EXPORT` to match the naming convention of other Yoga macros.

Reviewed By: rshest

Differential Revision: D49132643

fbshipit-source-id: cafa6de0c300788a72d9a446ce07c5ac89a20a8e
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 12, 2023
1 parent a4a8ab9 commit 3fbb788
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 370 deletions.
16 changes: 5 additions & 11 deletions packages/react-native/ReactCommon/yoga/yoga/YGMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@
#endif

#ifdef _WINDLL
#define WIN_EXPORT __declspec(dllexport)
#define YG_EXPORT __declspec(dllexport)
#elif !defined(_MSC_VER)
#define YG_EXPORT __attribute__((visibility("default")))
#else
#define WIN_EXPORT
#endif

#ifndef YOGA_EXPORT
#ifdef _MSC_VER
#define YOGA_EXPORT
#else
#define YOGA_EXPORT __attribute__((visibility("default")))
#endif
#define YG_EXPORT
#endif

#ifdef NS_ENUM
Expand Down Expand Up @@ -113,7 +107,7 @@ constexpr int n() {

#define YG_ENUM_DECL(NAME, ...) \
typedef YG_ENUM_BEGIN(NAME){__VA_ARGS__} YG_ENUM_END(NAME); \
WIN_EXPORT const char* NAME##ToString(NAME);
YG_EXPORT const char* NAME##ToString(NAME);

#ifdef __cplusplus
#define YG_ENUM_SEQ_DECL(NAME, ...) \
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/ReactCommon/yoga/yoga/YGValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ typedef struct YGValue {
YGUnit unit;
} YGValue;

YOGA_EXPORT extern const YGValue YGValueAuto;
YOGA_EXPORT extern const YGValue YGValueUndefined;
YOGA_EXPORT extern const YGValue YGValueZero;
YG_EXPORT extern const YGValue YGValueAuto;
YG_EXPORT extern const YGValue YGValueUndefined;
YG_EXPORT extern const YGValue YGValueZero;

YG_EXTERN_C_END

Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/Yoga-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

YG_EXTERN_C_BEGIN

void YGNodeCalculateLayoutWithContext(
YG_EXPORT void YGNodeCalculateLayoutWithContext(
YGNodeRef node,
float availableWidth,
float availableHeight,
Expand All @@ -24,6 +24,6 @@ void YGNodeCalculateLayoutWithContext(

// Deallocates a Yoga Node. Unlike YGNodeFree, does not remove the node from
// its parent or children.
void YGNodeDeallocate(YGNodeRef node);
YG_EXPORT void YGNodeDeallocate(YGNodeRef node);

YG_EXTERN_C_END
Loading

0 comments on commit 3fbb788

Please sign in to comment.