From bfcd15e4a91e3ee83e289c9001ab624b4ba68891 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Tue, 7 Jun 2022 07:42:49 -0700 Subject: [PATCH] Make all headers public and add #ifdef __cplusplus (#1150) Summary: This change is mostly needed to support the new react-native architecture with Swift. Some private yoga headers end up being included in the swift build and result in compilation failure since swift cannot compile c++ modules. See https://github.com/facebook/react-native/pull/33381. The most reliable fix is to include all headers as public headers, and add `#ifdef __cplusplus` to those that include c++. This is already what we do for other headers, this applies this to all headers. Tested in the YogaKitSample, and also in a react-native app. Changelog: [iOS] [Changed] - Make all Yoga headers public and add #ifdef __cplusplus Pull Request resolved: https://github.com/facebook/yoga/pull/1150 Reviewed By: dmitryrykun Differential Revision: D36966687 Pulled By: cortinico fbshipit-source-id: a34a54d56df43ab4934715070bab8e790b9abd39 --- Yoga.podspec | 5 +++-- yoga/BitUtils.h | 4 ++++ yoga/CompactValue.h | 4 ++++ yoga/Utils.h | 5 +++++ yoga/YGConfig.h | 5 +++++ yoga/YGFloatOptional.h | 4 ++++ yoga/YGLayout.h | 5 +++++ yoga/YGNodePrint.h | 7 +++++++ yoga/Yoga-internal.h | 5 +++++ yoga/log.h | 4 ++++ 10 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Yoga.podspec b/Yoga.podspec index 2b09977daa..077f6ccd60 100644 --- a/Yoga.podspec +++ b/Yoga.podspec @@ -1,8 +1,9 @@ -# Copyright (c) Facebook, Inc. and its affiliates. +# Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. + Pod::Spec.new do |spec| spec.name = 'Yoga' spec.version = '1.14.0' @@ -33,6 +34,6 @@ Pod::Spec.new do |spec| '-fPIC' ] spec.source_files = 'yoga/**/*.{c,h,cpp}' - spec.public_header_files = 'yoga/{Yoga,YGEnums,YGMacros,YGNode,YGStyle,YGValue}.h' + spec.public_header_files = 'yoga/*.h' end diff --git a/yoga/BitUtils.h b/yoga/BitUtils.h index b17751ad33..a60ea7609c 100644 --- a/yoga/BitUtils.h +++ b/yoga/BitUtils.h @@ -7,6 +7,8 @@ #pragma once +#ifdef __cplusplus + #include #include #include "YGEnums.h" @@ -65,3 +67,5 @@ inline void setBooleanData(uint8_t& flags, size_t index, bool value) { } // namespace detail } // namespace yoga } // namespace facebook + +#endif diff --git a/yoga/CompactValue.h b/yoga/CompactValue.h index 6879ca146f..1f03cf721a 100644 --- a/yoga/CompactValue.h +++ b/yoga/CompactValue.h @@ -7,6 +7,8 @@ #pragma once +#ifdef __cplusplus + #include "YGValue.h" #include "YGMacros.h" #include @@ -182,3 +184,5 @@ constexpr bool operator!=(CompactValue a, CompactValue b) noexcept { } // namespace detail } // namespace yoga } // namespace facebook + +#endif diff --git a/yoga/Utils.h b/yoga/Utils.h index d21e8ecb32..8588ecc594 100644 --- a/yoga/Utils.h +++ b/yoga/Utils.h @@ -6,6 +6,9 @@ */ #pragma once + +#ifdef __cplusplus + #include "YGNode.h" #include "Yoga-internal.h" #include "CompactValue.h" @@ -145,3 +148,5 @@ inline YGFloatOptional YGResolveValueMargin( } void throwLogicalErrorWithMessage(const char* message); + +#endif diff --git a/yoga/YGConfig.h b/yoga/YGConfig.h index 607408ace4..e15cc12253 100644 --- a/yoga/YGConfig.h +++ b/yoga/YGConfig.h @@ -6,6 +6,9 @@ */ #pragma once + +#ifdef __cplusplus + #include "Yoga-internal.h" #include "Yoga.h" @@ -74,3 +77,5 @@ struct YOGA_EXPORT YGConfig { setCloneNodeCallback(YGCloneNodeFunc{nullptr}); } }; + +#endif diff --git a/yoga/YGFloatOptional.h b/yoga/YGFloatOptional.h index 4aa9e76e29..6af7bbafbf 100644 --- a/yoga/YGFloatOptional.h +++ b/yoga/YGFloatOptional.h @@ -7,6 +7,8 @@ #pragma once +#ifdef __cplusplus + #include #include #include "Yoga-internal.h" @@ -68,3 +70,5 @@ inline bool operator>=(YGFloatOptional lhs, YGFloatOptional rhs) { inline bool operator<=(YGFloatOptional lhs, YGFloatOptional rhs) { return lhs < rhs || lhs == rhs; } + +#endif diff --git a/yoga/YGLayout.h b/yoga/YGLayout.h index 6c23934207..e3a4a1943b 100644 --- a/yoga/YGLayout.h +++ b/yoga/YGLayout.h @@ -6,6 +6,9 @@ */ #pragma once + +#ifdef __cplusplus + #include "BitUtils.h" #include "YGFloatOptional.h" #include "Yoga-internal.h" @@ -85,3 +88,5 @@ struct YGLayout { bool operator==(YGLayout layout) const; bool operator!=(YGLayout layout) const { return !(*this == layout); } }; + +#endif diff --git a/yoga/YGNodePrint.h b/yoga/YGNodePrint.h index 0e25b9728b..83b3f860e4 100644 --- a/yoga/YGNodePrint.h +++ b/yoga/YGNodePrint.h @@ -6,7 +6,11 @@ */ #ifdef DEBUG + #pragma once + +#ifdef __cplusplus + #include #include "Yoga.h" @@ -22,4 +26,7 @@ void YGNodeToString( } // namespace yoga } // namespace facebook + +#endif + #endif diff --git a/yoga/Yoga-internal.h b/yoga/Yoga-internal.h index 08f9da171c..492543ef1d 100644 --- a/yoga/Yoga-internal.h +++ b/yoga/Yoga-internal.h @@ -6,6 +6,9 @@ */ #pragma once + +#ifdef __cplusplus + #include #include #include @@ -148,3 +151,5 @@ static const float kDefaultFlexShrink = 0.0f; static const float kWebDefaultFlexShrink = 1.0f; extern bool YGFloatsEqual(const float a, const float b); + +#endif diff --git a/yoga/log.h b/yoga/log.h index 1d270e82e4..b9bfea4f39 100644 --- a/yoga/log.h +++ b/yoga/log.h @@ -7,6 +7,8 @@ #pragma once +#ifdef __cplusplus + #include "YGEnums.h" struct YGNode; @@ -36,3 +38,5 @@ struct Log { } // namespace detail } // namespace yoga } // namespace facebook + +#endif