From 8c3ee81d6e8864e889eeb6e0a46178782120dd66 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Fri, 1 Nov 2019 11:45:19 -0700 Subject: [PATCH] Use compiler flag -fvisibility=hidden Summary: Using compiler flag -fvisibility=hidden and explicitly setting visibility to default to public methods #Changelog: [Internal] [Yoga] Use compiler flag -fvisibility=hidden for reducing yoga binary size Reviewed By: astreet Differential Revision: D18029030 fbshipit-source-id: 545e73f9c25f3108fc9d9bb7f08c157dbc8da005 --- CMakeLists.txt | 7 + java/BUCK | 1 + java/CMakeLists.txt | 1 + java/jni/corefunctions.cpp | 3 +- .../main/cpp/include/yoga/testutil/testutil.h | 2 +- tools/build_defs/oss/yoga_defs.bzl | 1 + util/SingleWriterValueList.h | 12 +- yoga/CompactValue.h | 4 +- yoga/YGConfig.h | 2 +- yoga/YGMacros.h | 8 + yoga/YGNode.cpp | 4 +- yoga/YGNode.h | 2 +- yoga/YGStyle.h | 6 +- yoga/YGValue.h | 6 +- yoga/Yoga.cpp | 318 +++++++++++------- yoga/event/event.h | 2 +- yoga/log.cpp | 2 +- 17 files changed, 241 insertions(+), 140 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0d50865..d2e8c12c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,13 @@ cmake_minimum_required(VERSION 3.4.1) set(CMAKE_VERBOSE_MAKEFILE on) +add_compile_options( + -fno-omit-frame-pointer + -fexceptions + -fvisibility=hidden + -Wall + -std=c++11) + file(GLOB_RECURSE yogacore_SRC yoga/*.cpp) add_library(yogacore STATIC ${yogacore_SRC}) diff --git a/java/BUCK b/java/BUCK index 5b335bad..6faa4d8b 100644 --- a/java/BUCK +++ b/java/BUCK @@ -25,6 +25,7 @@ yoga_cxx_library( compiler_flags = [ "-fno-omit-frame-pointer", "-fexceptions", + "-fvisibility=hidden", "-fPIC", "-Wall", "-Werror", diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt index d3f4eda2..7d61bce7 100644 --- a/java/CMakeLists.txt +++ b/java/CMakeLists.txt @@ -24,6 +24,7 @@ add_subdirectory(${yogacore_DIR} ${yogacore_build_DIR}) add_compile_options( -fno-omit-frame-pointer -fexceptions + -fvisibility=hidden -Wall -std=c++11) diff --git a/java/jni/corefunctions.cpp b/java/jni/corefunctions.cpp index 6a250b1d..04435724 100644 --- a/java/jni/corefunctions.cpp +++ b/java/jni/corefunctions.cpp @@ -42,7 +42,8 @@ jint ensureInitialized(JNIEnv** env, JavaVM* vm) { return JNI_VERSION_1_6; } -JNIEnv* getCurrentEnv() { +// TODO why we need JNIEXPORT for getCurrentEnv ? +JNIEXPORT JNIEnv* getCurrentEnv() { JNIEnv* env; jint ret = globalVm->GetEnv((void**) &env, JNI_VERSION_1_6); if (ret != JNI_OK) { diff --git a/testutil/src/main/cpp/include/yoga/testutil/testutil.h b/testutil/src/main/cpp/include/yoga/testutil/testutil.h index e3a320c9..7c9f6288 100644 --- a/testutil/src/main/cpp/include/yoga/testutil/testutil.h +++ b/testutil/src/main/cpp/include/yoga/testutil/testutil.h @@ -15,7 +15,7 @@ namespace facebook { namespace yoga { namespace test { -struct TestUtil { +struct YOGA_EXPORT TestUtil { static void startCountingNodes(); static int nodeCount(); static int stopCountingNodes(); diff --git a/tools/build_defs/oss/yoga_defs.bzl b/tools/build_defs/oss/yoga_defs.bzl index ff303746..a1ca965f 100644 --- a/tools/build_defs/oss/yoga_defs.bzl +++ b/tools/build_defs/oss/yoga_defs.bzl @@ -53,6 +53,7 @@ CXX_LIBRARY_WHITELIST = [ BASE_COMPILER_FLAGS = [ "-fno-omit-frame-pointer", "-fexceptions", + "-fvisibility=hidden", "-Wall", "-Werror", "-O2", diff --git a/util/SingleWriterValueList.h b/util/SingleWriterValueList.h index 26b7e88f..b0854f85 100644 --- a/util/SingleWriterValueList.h +++ b/util/SingleWriterValueList.h @@ -12,12 +12,20 @@ #include #include +#ifndef YOGA_EXPORT +#ifdef _MSC_VER +#define YOGA_EXPORT +#else +#define YOGA_EXPORT __attribute__((visibility("default"))) +#endif +#endif + namespace facebook { namespace yoga { namespace detail { -class FreeList { +class YOGA_EXPORT FreeList { std::stack free_; void* getRaw(); @@ -72,7 +80,7 @@ public: /// std::accumulate(counters.begin(), counters.end(), 0); /// template -class SingleWriterValueList { +class YOGA_EXPORT SingleWriterValueList { std::forward_list values_{}; std::mutex acquireMutex_{}; detail::FreeList freeValuesList_{}; diff --git a/yoga/CompactValue.h b/yoga/CompactValue.h index 646c8785..be933a16 100644 --- a/yoga/CompactValue.h +++ b/yoga/CompactValue.h @@ -8,7 +8,7 @@ #pragma once #include "YGValue.h" - +#include "YGMacros.h" #include #include #include @@ -40,7 +40,7 @@ namespace detail { // 0x40000000 0x7f7fffff // - Zero is supported, negative zero is not // - values outside of the representable range are clamped -class CompactValue { +class YOGA_EXPORT CompactValue { friend constexpr bool operator==(CompactValue, CompactValue) noexcept; public: diff --git a/yoga/YGConfig.h b/yoga/YGConfig.h index 1b2d2b46..e87d6758 100644 --- a/yoga/YGConfig.h +++ b/yoga/YGConfig.h @@ -9,7 +9,7 @@ #include "Yoga-internal.h" #include "Yoga.h" -struct YGConfig { +struct YOGA_EXPORT YGConfig { using LogWithContextFn = int (*)( YGConfigRef config, YGNodeRef node, diff --git a/yoga/YGMacros.h b/yoga/YGMacros.h index 85881ea5..c6917f1b 100644 --- a/yoga/YGMacros.h +++ b/yoga/YGMacros.h @@ -21,6 +21,14 @@ #define WIN_EXPORT #endif +#ifndef YOGA_EXPORT +#ifdef _MSC_VER +#define YOGA_EXPORT +#else +#define YOGA_EXPORT __attribute__((visibility("default"))) +#endif +#endif + #ifdef NS_ENUM // Cannot use NSInteger as NSInteger has a different size than int (which is the // default type of a enum). Therefor when linking the Yoga C library into obj-c diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 9296811a..1d49b007 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -188,7 +188,7 @@ void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) { setMeasureFunc(m); } -void YGNode::setMeasureFunc(MeasureWithContextFn measureFunc) { +YOGA_EXPORT void YGNode::setMeasureFunc(MeasureWithContextFn measureFunc) { flags_.at() = true; decltype(YGNode::measure_) m; m.withContext = measureFunc; @@ -378,7 +378,7 @@ YGDirection YGNode::resolveDirection(const YGDirection ownerDirection) { } } -void YGNode::clearChildren() { +YOGA_EXPORT void YGNode::clearChildren() { children_.clear(); children_.shrink_to_fit(); } diff --git a/yoga/YGNode.h b/yoga/YGNode.h index 32c7770b..2967a1e2 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -18,7 +18,7 @@ YGConfigRef YGConfigGetDefault(); -struct YGNode { +struct YOGA_EXPORT YGNode { using MeasureWithContextFn = YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*); using BaselineWithContextFn = float (*)(YGNode*, float, float, void*); diff --git a/yoga/YGStyle.h b/yoga/YGStyle.h index 5914328f..b066b346 100644 --- a/yoga/YGStyle.h +++ b/yoga/YGStyle.h @@ -17,7 +17,7 @@ #include "Yoga-internal.h" #include "Yoga.h" -class YGStyle { +class YOGA_EXPORT YGStyle { template using Values = facebook::yoga::detail::Values()>; @@ -197,7 +197,7 @@ public: Ref aspectRatio() { return {*this}; } }; -bool operator==(const YGStyle& lhs, const YGStyle& rhs); -inline bool operator!=(const YGStyle& lhs, const YGStyle& rhs) { +YOGA_EXPORT bool operator==(const YGStyle& lhs, const YGStyle& rhs); +YOGA_EXPORT inline bool operator!=(const YGStyle& lhs, const YGStyle& rhs) { return !(lhs == rhs); } diff --git a/yoga/YGValue.h b/yoga/YGValue.h index 8502da77..aaa10c3f 100644 --- a/yoga/YGValue.h +++ b/yoga/YGValue.h @@ -26,9 +26,9 @@ typedef struct YGValue { YGUnit unit; } YGValue; -extern const YGValue YGValueAuto; -extern const YGValue YGValueUndefined; -extern const YGValue YGValueZero; +YOGA_EXPORT extern const YGValue YGValueAuto; +YOGA_EXPORT extern const YGValue YGValueUndefined; +YOGA_EXPORT extern const YGValue YGValueZero; YG_EXTERN_C_END diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index e0a06b43..5ace8f87 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -106,7 +106,7 @@ static int YGDefaultLog( #undef YG_UNUSED #endif -bool YGFloatIsUndefined(const float value) { +YOGA_EXPORT bool YGFloatIsUndefined(const float value) { return facebook::yoga::isUndefined(value); } @@ -140,77 +140,84 @@ detail::CompactValue YGComputedEdgeValue( return defaultValue; } -void* YGNodeGetContext(YGNodeRef node) { +YOGA_EXPORT void* YGNodeGetContext(YGNodeRef node) { return node->getContext(); } -void YGNodeSetContext(YGNodeRef node, void* context) { +YOGA_EXPORT void YGNodeSetContext(YGNodeRef node, void* context) { return node->setContext(context); } -bool YGNodeHasMeasureFunc(YGNodeRef node) { +YOGA_EXPORT bool YGNodeHasMeasureFunc(YGNodeRef node) { return node->hasMeasureFunc(); } -void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc) { +YOGA_EXPORT void YGNodeSetMeasureFunc( + YGNodeRef node, + YGMeasureFunc measureFunc) { node->setMeasureFunc(measureFunc); } -bool YGNodeHasBaselineFunc(YGNodeRef node) { +YOGA_EXPORT bool YGNodeHasBaselineFunc(YGNodeRef node) { return node->hasBaselineFunc(); } -void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc) { +YOGA_EXPORT void YGNodeSetBaselineFunc( + YGNodeRef node, + YGBaselineFunc baselineFunc) { node->setBaselineFunc(baselineFunc); } -YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node) { +YOGA_EXPORT YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node) { return node->getDirtied(); } -void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc) { +YOGA_EXPORT void YGNodeSetDirtiedFunc( + YGNodeRef node, + YGDirtiedFunc dirtiedFunc) { node->setDirtiedFunc(dirtiedFunc); } -void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) { +YOGA_EXPORT void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) { node->setPrintFunc(printFunc); } -bool YGNodeGetHasNewLayout(YGNodeRef node) { +YOGA_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node) { return node->getHasNewLayout(); } -void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) { +YOGA_EXPORT void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled) { config->printTree = enabled; } -void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) { +YOGA_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout) { node->setHasNewLayout(hasNewLayout); } -YGNodeType YGNodeGetNodeType(YGNodeRef node) { +YOGA_EXPORT YGNodeType YGNodeGetNodeType(YGNodeRef node) { return node->getNodeType(); } -void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) { +YOGA_EXPORT void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType) { return node->setNodeType(nodeType); } -bool YGNodeIsDirty(YGNodeRef node) { +YOGA_EXPORT bool YGNodeIsDirty(YGNodeRef node) { return node->isDirty(); } -bool YGNodeLayoutGetDidUseLegacyFlag(const YGNodeRef node) { +YOGA_EXPORT bool YGNodeLayoutGetDidUseLegacyFlag(const YGNodeRef node) { return node->didUseLegacyFlag(); } -void YGNodeMarkDirtyAndPropogateToDescendants(const YGNodeRef node) { +YOGA_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants( + const YGNodeRef node) { return node->markDirtyAndPropogateDownwards(); } int32_t gConfigInstanceCount = 0; -WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { +YOGA_EXPORT WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { const YGNodeRef node = new YGNode{config}; YGAssertWithConfig( config, node != nullptr, "Could not allocate memory for node"); @@ -219,16 +226,16 @@ WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { return node; } -YGConfigRef YGConfigGetDefault() { +YOGA_EXPORT YGConfigRef YGConfigGetDefault() { static YGConfigRef defaultConfig = YGConfigNew(); return defaultConfig; } -YGNodeRef YGNodeNew(void) { +YOGA_EXPORT YGNodeRef YGNodeNew(void) { return YGNodeNewWithConfig(YGConfigGetDefault()); } -YGNodeRef YGNodeClone(YGNodeRef oldNode) { +YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNode) { YGNodeRef node = new YGNode(*oldNode); YGAssertWithConfig( oldNode->getConfig(), @@ -268,7 +275,7 @@ static YGNodeRef YGNodeDeepClone(YGNodeRef oldNode) { return node; } -void YGNodeFree(const YGNodeRef node) { +YOGA_EXPORT void YGNodeFree(const YGNodeRef node) { if (YGNodeRef owner = node->getOwner()) { owner->removeChild(node); node->setOwner(nullptr); @@ -296,7 +303,7 @@ static void YGConfigFreeRecursive(const YGNodeRef root) { } } -void YGNodeFreeRecursiveWithCleanupFunc( +YOGA_EXPORT void YGNodeFreeRecursiveWithCleanupFunc( const YGNodeRef root, YGNodeCleanupFunc cleanup) { uint32_t skipped = 0; @@ -316,11 +323,11 @@ void YGNodeFreeRecursiveWithCleanupFunc( YGNodeFree(root); } -void YGNodeFreeRecursive(const YGNodeRef root) { +YOGA_EXPORT void YGNodeFreeRecursive(const YGNodeRef root) { return YGNodeFreeRecursiveWithCleanupFunc(root, nullptr); } -void YGNodeReset(YGNodeRef node) { +YOGA_EXPORT void YGNodeReset(YGNodeRef node) { node->reset(); } @@ -328,7 +335,7 @@ int32_t YGConfigGetInstanceCount(void) { return gConfigInstanceCount; } -YGConfigRef YGConfigNew(void) { +YOGA_EXPORT YGConfigRef YGConfigNew(void) { #ifdef ANDROID const YGConfigRef config = new YGConfig(YGAndroidLog); #else @@ -338,7 +345,7 @@ YGConfigRef YGConfigNew(void) { return config; } -void YGConfigFree(const YGConfigRef config) { +YOGA_EXPORT void YGConfigFree(const YGConfigRef config) { delete config; gConfigInstanceCount--; } @@ -347,18 +354,20 @@ void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src) { memcpy(dest, src, sizeof(YGConfig)); } -void YGNodeSetIsReferenceBaseline(YGNodeRef node, bool isReferenceBaseline) { +YOGA_EXPORT void YGNodeSetIsReferenceBaseline( + YGNodeRef node, + bool isReferenceBaseline) { if (node->isReferenceBaseline() != isReferenceBaseline) { node->setIsReferenceBaseline(isReferenceBaseline); node->markDirtyAndPropogate(); } } -bool YGNodeIsReferenceBaseline(YGNodeRef node) { +YOGA_EXPORT bool YGNodeIsReferenceBaseline(YGNodeRef node) { return node->isReferenceBaseline(); } -void YGNodeInsertChild( +YOGA_EXPORT void YGNodeInsertChild( const YGNodeRef owner, const YGNodeRef child, const uint32_t index) { @@ -377,7 +386,9 @@ void YGNodeInsertChild( owner->markDirtyAndPropogate(); } -void YGNodeRemoveChild(const YGNodeRef owner, const YGNodeRef excludedChild) { +YOGA_EXPORT void YGNodeRemoveChild( + const YGNodeRef owner, + const YGNodeRef excludedChild) { if (YGNodeGetChildCount(owner) == 0) { // This is an empty set. Nothing to remove. return; @@ -396,7 +407,7 @@ void YGNodeRemoveChild(const YGNodeRef owner, const YGNodeRef excludedChild) { } } -void YGNodeRemoveAllChildren(const YGNodeRef owner) { +YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef owner) { const uint32_t childCount = YGNodeGetChildCount(owner); if (childCount == 0) { // This is an empty set already. Nothing to do. @@ -456,7 +467,7 @@ static void YGNodeSetChildrenInternal( } } -void YGNodeSetChildren( +YOGA_EXPORT void YGNodeSetChildren( const YGNodeRef owner, const YGNodeRef c[], const uint32_t count) { @@ -464,32 +475,33 @@ void YGNodeSetChildren( YGNodeSetChildrenInternal(owner, children); } -void YGNodeSetChildren( +YOGA_EXPORT void YGNodeSetChildren( YGNodeRef const owner, const std::vector& children) { YGNodeSetChildrenInternal(owner, children); } -YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index) { +YOGA_EXPORT YGNodeRef +YGNodeGetChild(const YGNodeRef node, const uint32_t index) { if (index < node->getChildren().size()) { return node->getChild(index); } return nullptr; } -uint32_t YGNodeGetChildCount(const YGNodeRef node) { +YOGA_EXPORT uint32_t YGNodeGetChildCount(const YGNodeRef node) { return static_cast(node->getChildren().size()); } -YGNodeRef YGNodeGetOwner(const YGNodeRef node) { +YOGA_EXPORT YGNodeRef YGNodeGetOwner(const YGNodeRef node) { return node->getOwner(); } -YGNodeRef YGNodeGetParent(const YGNodeRef node) { +YOGA_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node) { return node->getOwner(); } -void YGNodeMarkDirty(const YGNodeRef node) { +YOGA_EXPORT void YGNodeMarkDirty(const YGNodeRef node) { YGAssertWithNode( node, node->hasMeasureFunc(), @@ -499,20 +511,22 @@ void YGNodeMarkDirty(const YGNodeRef node) { node->markDirtyAndPropogate(); } -void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) { +YOGA_EXPORT void YGNodeCopyStyle( + const YGNodeRef dstNode, + const YGNodeRef srcNode) { if (!(dstNode->getStyle() == srcNode->getStyle())) { dstNode->setStyle(srcNode->getStyle()); dstNode->markDirtyAndPropogate(); } } -float YGNodeStyleGetFlexGrow(const YGNodeConstRef node) { +YOGA_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeConstRef node) { return node->getStyle().flexGrow().isUndefined() ? kDefaultFlexGrow : node->getStyle().flexGrow().unwrap(); } -float YGNodeStyleGetFlexShrink(const YGNodeConstRef node) { +YOGA_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeConstRef node) { return node->getStyle().flexShrink().isUndefined() ? (node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink) @@ -565,113 +579,131 @@ void updateIndexedStyleProp( // decltype, MSVC will prefer the non-const version. #define MSVC_HINT(PROP) decltype(YGStyle{}.PROP()) -void YGNodeStyleSetDirection(const YGNodeRef node, const YGDirection value) { +YOGA_EXPORT void YGNodeStyleSetDirection( + const YGNodeRef node, + const YGDirection value) { updateStyle(node, &YGStyle::direction, value); } -YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { +YOGA_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) { return node->getStyle().direction(); } -void YGNodeStyleSetFlexDirection( +YOGA_EXPORT void YGNodeStyleSetFlexDirection( const YGNodeRef node, const YGFlexDirection flexDirection) { updateStyle( node, &YGStyle::flexDirection, flexDirection); } -YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeConstRef node) { +YOGA_EXPORT YGFlexDirection +YGNodeStyleGetFlexDirection(const YGNodeConstRef node) { return node->getStyle().flexDirection(); } -void YGNodeStyleSetJustifyContent( +YOGA_EXPORT void YGNodeStyleSetJustifyContent( const YGNodeRef node, const YGJustify justifyContent) { updateStyle( node, &YGStyle::justifyContent, justifyContent); } -YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) { +YOGA_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) { return node->getStyle().justifyContent(); } -void YGNodeStyleSetAlignContent( +YOGA_EXPORT void YGNodeStyleSetAlignContent( const YGNodeRef node, const YGAlign alignContent) { updateStyle( node, &YGStyle::alignContent, alignContent); } -YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) { +YOGA_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) { return node->getStyle().alignContent(); } -void YGNodeStyleSetAlignItems(const YGNodeRef node, const YGAlign alignItems) { +YOGA_EXPORT void YGNodeStyleSetAlignItems( + const YGNodeRef node, + const YGAlign alignItems) { updateStyle(node, &YGStyle::alignItems, alignItems); } -YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) { +YOGA_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) { return node->getStyle().alignItems(); } -void YGNodeStyleSetAlignSelf(const YGNodeRef node, const YGAlign alignSelf) { +YOGA_EXPORT void YGNodeStyleSetAlignSelf( + const YGNodeRef node, + const YGAlign alignSelf) { updateStyle(node, &YGStyle::alignSelf, alignSelf); } -YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) { +YOGA_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) { return node->getStyle().alignSelf(); } -void YGNodeStyleSetPositionType( +YOGA_EXPORT void YGNodeStyleSetPositionType( const YGNodeRef node, const YGPositionType positionType) { updateStyle( node, &YGStyle::positionType, positionType); } -YGPositionType YGNodeStyleGetPositionType(const YGNodeConstRef node) { +YOGA_EXPORT YGPositionType +YGNodeStyleGetPositionType(const YGNodeConstRef node) { return node->getStyle().positionType(); } -void YGNodeStyleSetFlexWrap(const YGNodeRef node, const YGWrap flexWrap) { +YOGA_EXPORT void YGNodeStyleSetFlexWrap( + const YGNodeRef node, + const YGWrap flexWrap) { updateStyle(node, &YGStyle::flexWrap, flexWrap); } -YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) { +YOGA_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) { return node->getStyle().flexWrap(); } -void YGNodeStyleSetOverflow(const YGNodeRef node, const YGOverflow overflow) { +YOGA_EXPORT void YGNodeStyleSetOverflow( + const YGNodeRef node, + const YGOverflow overflow) { updateStyle(node, &YGStyle::overflow, overflow); } -YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { +YOGA_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) { return node->getStyle().overflow(); } -void YGNodeStyleSetDisplay(const YGNodeRef node, const YGDisplay display) { +YOGA_EXPORT void YGNodeStyleSetDisplay( + const YGNodeRef node, + const YGDisplay display) { updateStyle(node, &YGStyle::display, display); } -YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) { +YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) { return node->getStyle().display(); } // TODO(T26792433): Change the API to accept YGFloatOptional. -void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { +YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { updateStyle(node, &YGStyle::flex, YGFloatOptional{flex}); } // TODO(T26792433): Change the API to accept YGFloatOptional. -float YGNodeStyleGetFlex(const YGNodeConstRef node) { +YOGA_EXPORT float YGNodeStyleGetFlex(const YGNodeConstRef node) { return node->getStyle().flex().isUndefined() ? YGUndefined : node->getStyle().flex().unwrap(); } // TODO(T26792433): Change the API to accept YGFloatOptional. -void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) { +YOGA_EXPORT void YGNodeStyleSetFlexGrow( + const YGNodeRef node, + const float flexGrow) { updateStyle( node, &YGStyle::flexGrow, YGFloatOptional{flexGrow}); } // TODO(T26792433): Change the API to accept YGFloatOptional. -void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) { +YOGA_EXPORT void YGNodeStyleSetFlexShrink( + const YGNodeRef node, + const float flexShrink) { updateStyle( node, &YGStyle::flexShrink, YGFloatOptional{flexShrink}); } -YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { +YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { YGValue flexBasis = node->getStyle().flexBasis(); if (flexBasis.unit == YGUnitUndefined || flexBasis.unit == YGUnitAuto) { // TODO(T26792433): Get rid off the use of YGUndefined at client side @@ -680,71 +712,91 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { return flexBasis; } -void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) { +YOGA_EXPORT void YGNodeStyleSetFlexBasis( + const YGNodeRef node, + const float flexBasis) { auto value = detail::CompactValue::ofMaybe(flexBasis); updateStyle(node, &YGStyle::flexBasis, value); } -void YGNodeStyleSetFlexBasisPercent( +YOGA_EXPORT void YGNodeStyleSetFlexBasisPercent( const YGNodeRef node, const float flexBasisPercent) { auto value = detail::CompactValue::ofMaybe(flexBasisPercent); updateStyle(node, &YGStyle::flexBasis, value); } -void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { +YOGA_EXPORT void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { updateStyle( node, &YGStyle::flexBasis, detail::CompactValue::ofAuto()); } -void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) { +YOGA_EXPORT void YGNodeStyleSetPosition( + YGNodeRef node, + YGEdge edge, + float points) { auto value = detail::CompactValue::ofMaybe(points); updateIndexedStyleProp( node, &YGStyle::position, edge, value); } -void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) { +YOGA_EXPORT void YGNodeStyleSetPositionPercent( + YGNodeRef node, + YGEdge edge, + float percent) { auto value = detail::CompactValue::ofMaybe(percent); updateIndexedStyleProp( node, &YGStyle::position, edge, value); } -YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { +YOGA_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { return node->getStyle().position()[edge]; } -void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) { +YOGA_EXPORT void YGNodeStyleSetMargin( + YGNodeRef node, + YGEdge edge, + float points) { auto value = detail::CompactValue::ofMaybe(points); updateIndexedStyleProp( node, &YGStyle::margin, edge, value); } -void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) { +YOGA_EXPORT void YGNodeStyleSetMarginPercent( + YGNodeRef node, + YGEdge edge, + float percent) { auto value = detail::CompactValue::ofMaybe(percent); updateIndexedStyleProp( node, &YGStyle::margin, edge, value); } -void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { +YOGA_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { updateIndexedStyleProp( node, &YGStyle::margin, edge, detail::CompactValue::ofAuto()); } -YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { +YOGA_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { return node->getStyle().margin()[edge]; } -void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) { +YOGA_EXPORT void YGNodeStyleSetPadding( + YGNodeRef node, + YGEdge edge, + float points) { auto value = detail::CompactValue::ofMaybe(points); updateIndexedStyleProp( node, &YGStyle::padding, edge, value); } -void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) { +YOGA_EXPORT void YGNodeStyleSetPaddingPercent( + YGNodeRef node, + YGEdge edge, + float percent) { auto value = detail::CompactValue::ofMaybe(percent); updateIndexedStyleProp( node, &YGStyle::padding, edge, value); } -YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) { +YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) { return node->getStyle().padding()[edge]; } // TODO(T26792433): Change the API to accept YGFloatOptional. -void YGNodeStyleSetBorder( +YOGA_EXPORT void YGNodeStyleSetBorder( const YGNodeRef node, const YGEdge edge, const float border) { @@ -753,7 +805,9 @@ void YGNodeStyleSetBorder( node, &YGStyle::border, edge, value); } -float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) { +YOGA_EXPORT float YGNodeStyleGetBorder( + const YGNodeConstRef node, + const YGEdge edge) { auto border = node->getStyle().border()[edge]; if (border.isUndefined() || border.isAuto()) { // TODO(T26792433): Rather than returning YGUndefined, change the api to @@ -767,126 +821,141 @@ float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) { // Yoga specific properties, not compatible with flexbox specification // TODO(T26792433): Change the API to accept YGFloatOptional. -float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { +YOGA_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { const YGFloatOptional op = node->getStyle().aspectRatio(); return op.isUndefined() ? YGUndefined : op.unwrap(); } // TODO(T26792433): Change the API to accept YGFloatOptional. -void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) { +YOGA_EXPORT void YGNodeStyleSetAspectRatio( + const YGNodeRef node, + const float aspectRatio) { updateStyle( node, &YGStyle::aspectRatio, YGFloatOptional{aspectRatio}); } -void YGNodeStyleSetWidth(YGNodeRef node, float points) { +YOGA_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float points) { auto value = detail::CompactValue::ofMaybe(points); updateIndexedStyleProp( node, &YGStyle::dimensions, YGDimensionWidth, value); } -void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { +YOGA_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { auto value = detail::CompactValue::ofMaybe(percent); updateIndexedStyleProp( node, &YGStyle::dimensions, YGDimensionWidth, value); } -void YGNodeStyleSetWidthAuto(YGNodeRef node) { +YOGA_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node) { updateIndexedStyleProp( node, &YGStyle::dimensions, YGDimensionWidth, detail::CompactValue::ofAuto()); } -YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { +YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { return node->getStyle().dimensions()[YGDimensionWidth]; } -void YGNodeStyleSetHeight(YGNodeRef node, float points) { +YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float points) { auto value = detail::CompactValue::ofMaybe(points); updateIndexedStyleProp( node, &YGStyle::dimensions, YGDimensionHeight, value); } -void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { +YOGA_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { auto value = detail::CompactValue::ofMaybe(percent); updateIndexedStyleProp( node, &YGStyle::dimensions, YGDimensionHeight, value); } -void YGNodeStyleSetHeightAuto(YGNodeRef node) { +YOGA_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node) { updateIndexedStyleProp( node, &YGStyle::dimensions, YGDimensionHeight, detail::CompactValue::ofAuto()); } -YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { +YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { return node->getStyle().dimensions()[YGDimensionHeight]; } -void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) { +YOGA_EXPORT void YGNodeStyleSetMinWidth( + const YGNodeRef node, + const float minWidth) { auto value = detail::CompactValue::ofMaybe(minWidth); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionWidth, value); } -void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) { +YOGA_EXPORT void YGNodeStyleSetMinWidthPercent( + const YGNodeRef node, + const float minWidth) { auto value = detail::CompactValue::ofMaybe(minWidth); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionWidth, value); } -YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { +YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { return node->getStyle().minDimensions()[YGDimensionWidth]; }; -void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) { +YOGA_EXPORT void YGNodeStyleSetMinHeight( + const YGNodeRef node, + const float minHeight) { auto value = detail::CompactValue::ofMaybe(minHeight); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionHeight, value); } -void YGNodeStyleSetMinHeightPercent( +YOGA_EXPORT void YGNodeStyleSetMinHeightPercent( const YGNodeRef node, const float minHeight) { auto value = detail::CompactValue::ofMaybe(minHeight); updateIndexedStyleProp( node, &YGStyle::minDimensions, YGDimensionHeight, value); } -YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { +YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { return node->getStyle().minDimensions()[YGDimensionHeight]; }; -void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) { +YOGA_EXPORT void YGNodeStyleSetMaxWidth( + const YGNodeRef node, + const float maxWidth) { auto value = detail::CompactValue::ofMaybe(maxWidth); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionWidth, value); } -void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) { +YOGA_EXPORT void YGNodeStyleSetMaxWidthPercent( + const YGNodeRef node, + const float maxWidth) { auto value = detail::CompactValue::ofMaybe(maxWidth); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionWidth, value); } -YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { +YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { return node->getStyle().maxDimensions()[YGDimensionWidth]; }; -void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) { +YOGA_EXPORT void YGNodeStyleSetMaxHeight( + const YGNodeRef node, + const float maxHeight) { auto value = detail::CompactValue::ofMaybe(maxHeight); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionHeight, value); } -void YGNodeStyleSetMaxHeightPercent( +YOGA_EXPORT void YGNodeStyleSetMaxHeightPercent( const YGNodeRef node, const float maxHeight) { auto value = detail::CompactValue::ofMaybe(maxHeight); updateIndexedStyleProp( node, &YGStyle::maxDimensions, YGDimensionHeight, value); } -YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) { +YOGA_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) { return node->getStyle().maxDimensions()[YGDimensionHeight]; }; -#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ - type YGNodeLayoutGet##name(const YGNodeRef node) { \ - return node->getLayout().instanceName; \ +#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \ + YOGA_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node) { \ + return node->getLayout().instanceName; \ } #define YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(type, name, instanceName) \ - type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge) { \ + YOGA_EXPORT type YGNodeLayoutGet##name( \ + const YGNodeRef node, const YGEdge edge) { \ YGAssertWithNode( \ node, \ edge <= YGEdgeEnd, \ @@ -924,7 +993,8 @@ YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Margin, margin); YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Border, border); YG_NODE_LAYOUT_RESOLVED_PROPERTY_IMPL(float, Padding, padding); -bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(const YGNodeRef node) { +YOGA_EXPORT bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout( + const YGNodeRef node) { return node->getLayout().doesLegacyStretchFlagAffectsLayout(); } @@ -956,7 +1026,9 @@ static void YGNodePrintInternal( Log::log(node, YGLogLevelDebug, nullptr, str.c_str()); } -void YGNodePrint(const YGNodeRef node, const YGPrintOptions options) { +YOGA_EXPORT void YGNodePrint( + const YGNodeRef node, + const YGPrintOptions options) { YGNodePrintInternal(node, options); } #endif @@ -3970,7 +4042,7 @@ bool YGLayoutNodeInternal( return (needToVisitNode || cachedResults == nullptr); } -void YGConfigSetPointScaleFactor( +YOGA_EXPORT void YGConfigSetPointScaleFactor( const YGConfigRef config, const float pixelsInPoint) { YGAssertWithConfig( @@ -4067,7 +4139,7 @@ static void unsetUseLegacyFlagRecursively(YGNodeRef node) { } } -void YGNodeCalculateLayoutWithContext( +YOGA_EXPORT void YGNodeCalculateLayoutWithContext( const YGNodeRef node, const float ownerWidth, const float ownerHeight, @@ -4219,7 +4291,7 @@ void YGNodeCalculateLayoutWithContext( } } -void YGNodeCalculateLayout( +YOGA_EXPORT void YGNodeCalculateLayout( const YGNodeRef node, const float ownerWidth, const float ownerHeight, @@ -4228,7 +4300,7 @@ void YGNodeCalculateLayout( node, ownerWidth, ownerHeight, ownerDirection, nullptr); } -void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) { +YOGA_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) { if (logger != nullptr) { config->setLogger(logger); } else { @@ -4240,7 +4312,7 @@ void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) { } } -void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( +YOGA_EXPORT void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( const YGConfigRef config, const bool shouldDiffLayout) { config->shouldDiffLayoutWithoutLegacyStretchBehaviour = shouldDiffLayout; @@ -4270,7 +4342,7 @@ void YGAssertWithConfig( } } -void YGConfigSetExperimentalFeatureEnabled( +YOGA_EXPORT void YGConfigSetExperimentalFeatureEnabled( const YGConfigRef config, const YGExperimentalFeature feature, const bool enabled) { @@ -4283,11 +4355,13 @@ inline bool YGConfigIsExperimentalFeatureEnabled( return config->experimentalFeatures[feature]; } -void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) { +YOGA_EXPORT void YGConfigSetUseWebDefaults( + const YGConfigRef config, + const bool enabled) { config->useWebDefaults = enabled; } -void YGConfigSetUseLegacyStretchBehaviour( +YOGA_EXPORT void YGConfigSetUseLegacyStretchBehaviour( const YGConfigRef config, const bool useLegacyStretchBehaviour) { config->useLegacyStretchBehaviour = useLegacyStretchBehaviour; @@ -4297,15 +4371,15 @@ bool YGConfigGetUseWebDefaults(const YGConfigRef config) { return config->useWebDefaults; } -void YGConfigSetContext(const YGConfigRef config, void* context) { +YOGA_EXPORT void YGConfigSetContext(const YGConfigRef config, void* context) { config->context = context; } -void* YGConfigGetContext(const YGConfigRef config) { +YOGA_EXPORT void* YGConfigGetContext(const YGConfigRef config) { return config->context; } -void YGConfigSetCloneNodeFunc( +YOGA_EXPORT void YGConfigSetCloneNodeFunc( const YGConfigRef config, const YGCloneNodeFunc callback) { config->setCloneNodeCallback(callback); diff --git a/yoga/event/event.h b/yoga/event/event.h index f96b1165..309dacb5 100644 --- a/yoga/event/event.h +++ b/yoga/event/event.h @@ -50,7 +50,7 @@ struct LayoutData { const char* LayoutPassReasonToString(const LayoutPassReason value); -struct Event { +struct YOGA_EXPORT Event { enum Type { NodeAllocation, NodeDeallocation, diff --git a/yoga/log.cpp b/yoga/log.cpp index 20139776..fe6fbbc6 100644 --- a/yoga/log.cpp +++ b/yoga/log.cpp @@ -33,7 +33,7 @@ void vlog( } } // namespace -void Log::log( +YOGA_EXPORT void Log::log( YGNode* node, YGLogLevel level, void* context,