Skip to content

Commit

Permalink
Try to fix MSVC Buck Build (#37242)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #37242

X-link: facebook/yoga#1278

facebook/yoga#1269 broke building Yoga Buck targets with MSVC. The build logs suggest this is because headers may be double included from `exported_headers` and `headers`, causing redefinition. We are not saved on the MSVC build by `#pragma once` since headers are imported from different paths (but the Clang build seems okay with this).

This diff attempts to isolate headers so that nothing may be double exported. This is done in a little bit of a tricky way, since Starlark doesn't seem to support globs in the form of `{a,b}`, and Yoga's directory structure does not separate public and private headers cleanly (we should fix this, but it needs to be changed in multiple build systems at once which I want to do not in this change).

We also get a side effect that every file which isn't a public header needs to use the namespaced form to refer to a public header, even if in the same directory. Though this is going to be needed anyway if we end up wanting to move the public headers to a new directory.

Reviewed By: yungsters

Differential Revision: D45552325

fbshipit-source-id: e35afac1ff001057715e2039473be89c7ecb0bc8
  • Loading branch information
NickGerleman authored and facebook-github-bot committed May 4, 2023
1 parent 523c77d commit 2bf0d1c
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 37 deletions.
3 changes: 2 additions & 1 deletion packages/react-native/ReactCommon/yoga/yoga/BitUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#include <bitset>
#include <cstdio>
#include <cstdint>
#include "YGEnums.h"

#include <yoga/YGEnums.h>

namespace facebook {
namespace yoga {
Expand Down
12 changes: 7 additions & 5 deletions packages/react-native/ReactCommon/yoga/yoga/CompactValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

#pragma once

#include <cmath>
#include <cstdint>
#include <limits>

#include <yoga/YGMacros.h>
#include <yoga/YGValue.h>

#if defined(__has_include) && __has_include(<version>)
// needed to be able to evaluate defined(__cpp_lib_bit_cast)
#include <version>
Expand All @@ -20,11 +27,6 @@
#else
#include <cstring>
#endif
#include "YGValue.h"
#include "YGMacros.h"
#include <cmath>
#include <cstdint>
#include <limits>

static_assert(
std::numeric_limits<float>::is_iec559,
Expand Down
5 changes: 3 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/YGConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

#pragma once

#include "Yoga-internal.h"
#include "Yoga.h"
#include <yoga/Yoga.h>

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

namespace facebook {
namespace yoga {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// @generated by enums.py

#include "YGEnums.h"
#include <yoga/YGEnums.h>

const char* YGAlignToString(const YGAlign value) {
switch (value) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/yoga/yoga/YGEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// @generated by enums.py

#pragma once
#include "YGMacros.h"
#include <yoga/YGMacros.h>

// clang-format off

Expand Down
7 changes: 5 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/YGNodePrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
*/

#ifdef DEBUG
#include "YGNodePrint.h"

#include <stdarg.h>
#include "YGEnums.h"

#include <yoga/YGEnums.h>

#include "YGNodePrint.h"
#include "YGNode.h"
#include "Yoga-internal.h"
#include "Utils.h"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/yoga/yoga/YGNodePrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <string>

#include "Yoga.h"
#include <yoga/Yoga.h>

namespace facebook {
namespace yoga {
Expand Down
5 changes: 3 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/YGStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include <array>
#include <cstdint>
#include <type_traits>

#include <yoga/Yoga.h>

#include "CompactValue.h"
#include "YGEnums.h"
#include "YGFloatOptional.h"
#include "Yoga-internal.h"
#include "Yoga.h"
#include "BitUtils.h"

class YOGA_EXPORT YGStyle {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/yoga/yoga/YGValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

#include "YGValue.h"
#include <yoga/YGValue.h>

const YGValue YGValueZero = {0, YGUnitPoint};
const YGValue YGValueUndefined = {YGUndefined, YGUnitUndefined};
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/YGValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#pragma once

#include "YGEnums.h"
#include "YGMacros.h"
#include <yoga/YGEnums.h>
#include <yoga/YGMacros.h>

YG_EXTERN_C_BEGIN

Expand Down
4 changes: 3 additions & 1 deletion packages/react-native/ReactCommon/yoga/yoga/Yoga-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include <array>
#include <cmath>
#include <vector>

#include <yoga/Yoga.h>

#include "CompactValue.h"
#include "Yoga.h"

using YGVector = std::vector<YGNodeRef>;

Expand Down
16 changes: 4 additions & 12 deletions packages/react-native/ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,20 @@
* LICENSE file in the root directory of this source tree.
*/

#include "Yoga.h"
#include "log.h"
#include <float.h>
#include <string.h>
#include <algorithm>
#include <atomic>
#include <memory>

#include <yoga/Yoga.h>

#include "log.h"
#include "Utils.h"
#include "YGNode.h"
#include "YGNodePrint.h"
#include "Yoga-internal.h"
#include "event/event.h"
#ifdef _MSC_VER
#include <float.h>

/* define fmaxf if < VC12 */
#if _MSC_VER < 1800
__forceinline const float fmaxf(const float a, const float b) {
return (a > b) ? a : b;
}
#endif
#endif

using namespace facebook::yoga;
using detail::Log;
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/ReactCommon/yoga/yoga/Yoga.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include <stdbool.h>
#endif

#include "YGEnums.h"
#include "YGMacros.h"
#include "YGValue.h"
#include <yoga/YGEnums.h>
#include <yoga/YGMacros.h>
#include <yoga/YGValue.h>

YG_EXTERN_C_BEGIN

Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

#include "log.h"
#include <yoga/Yoga.h>

#include "Yoga.h"
#include "log.h"
#include "YGConfig.h"
#include "YGNode.h"

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/yoga/yoga/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include "YGEnums.h"
#include <yoga/YGEnums.h>

struct YGNode;
struct YGConfig;
Expand Down

0 comments on commit 2bf0d1c

Please sign in to comment.