Skip to content

Commit

Permalink
Make all headers public and add #ifdef __cplusplus (#1150)
Browse files Browse the repository at this point in the history
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 #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

X-link: facebook/yoga#1150

Reviewed By: dmitryrykun

Differential Revision: D36966687

Pulled By: cortinico

fbshipit-source-id: a34a54d56df43ab4934715070bab8e790b9abd39
  • Loading branch information
janicduplessis authored and facebook-github-bot committed Jun 7, 2022
1 parent 9ef3045 commit 43f831b
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ReactCommon/yoga/yoga/BitUtils.h
Expand Up @@ -7,6 +7,8 @@

#pragma once

#ifdef __cplusplus

#include <cstdio>
#include <cstdint>
#include "YGEnums.h"
Expand Down Expand Up @@ -65,3 +67,5 @@ inline void setBooleanData(uint8_t& flags, size_t index, bool value) {
} // namespace detail
} // namespace yoga
} // namespace facebook

#endif
4 changes: 4 additions & 0 deletions ReactCommon/yoga/yoga/CompactValue.h
Expand Up @@ -7,6 +7,8 @@

#pragma once

#ifdef __cplusplus

#include "YGValue.h"
#include "YGMacros.h"
#include <cmath>
Expand Down Expand Up @@ -182,3 +184,5 @@ constexpr bool operator!=(CompactValue a, CompactValue b) noexcept {
} // namespace detail
} // namespace yoga
} // namespace facebook

#endif
5 changes: 5 additions & 0 deletions ReactCommon/yoga/yoga/Utils.h
Expand Up @@ -6,6 +6,9 @@
*/

#pragma once

#ifdef __cplusplus

#include "YGNode.h"
#include "Yoga-internal.h"
#include "CompactValue.h"
Expand Down Expand Up @@ -145,3 +148,5 @@ inline YGFloatOptional YGResolveValueMargin(
}

void throwLogicalErrorWithMessage(const char* message);

#endif
5 changes: 5 additions & 0 deletions ReactCommon/yoga/yoga/YGConfig.h
Expand Up @@ -6,6 +6,9 @@
*/

#pragma once

#ifdef __cplusplus

#include "Yoga-internal.h"
#include "Yoga.h"

Expand Down Expand Up @@ -74,3 +77,5 @@ struct YOGA_EXPORT YGConfig {
setCloneNodeCallback(YGCloneNodeFunc{nullptr});
}
};

#endif
4 changes: 4 additions & 0 deletions ReactCommon/yoga/yoga/YGFloatOptional.h
Expand Up @@ -7,6 +7,8 @@

#pragma once

#ifdef __cplusplus

#include <cmath>
#include <limits>
#include "Yoga-internal.h"
Expand Down Expand Up @@ -68,3 +70,5 @@ inline bool operator>=(YGFloatOptional lhs, YGFloatOptional rhs) {
inline bool operator<=(YGFloatOptional lhs, YGFloatOptional rhs) {
return lhs < rhs || lhs == rhs;
}

#endif
5 changes: 5 additions & 0 deletions ReactCommon/yoga/yoga/YGLayout.h
Expand Up @@ -6,6 +6,9 @@
*/

#pragma once

#ifdef __cplusplus

#include "BitUtils.h"
#include "YGFloatOptional.h"
#include "Yoga-internal.h"
Expand Down Expand Up @@ -85,3 +88,5 @@ struct YGLayout {
bool operator==(YGLayout layout) const;
bool operator!=(YGLayout layout) const { return !(*this == layout); }
};

#endif
7 changes: 7 additions & 0 deletions ReactCommon/yoga/yoga/YGNodePrint.h
Expand Up @@ -6,7 +6,11 @@
*/

#ifdef DEBUG

#pragma once

#ifdef __cplusplus

#include <string>

#include "Yoga.h"
Expand All @@ -22,4 +26,7 @@ void YGNodeToString(

} // namespace yoga
} // namespace facebook

#endif

#endif
5 changes: 5 additions & 0 deletions ReactCommon/yoga/yoga/Yoga-internal.h
Expand Up @@ -6,6 +6,9 @@
*/

#pragma once

#ifdef __cplusplus

#include <algorithm>
#include <array>
#include <cmath>
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions ReactCommon/yoga/yoga/log.h
Expand Up @@ -7,6 +7,8 @@

#pragma once

#ifdef __cplusplus

#include "YGEnums.h"

struct YGNode;
Expand Down Expand Up @@ -36,3 +38,5 @@ struct Log {
} // namespace detail
} // namespace yoga
} // namespace facebook

#endif

0 comments on commit 43f831b

Please sign in to comment.