2467 Commits

Author SHA1 Message Date
Nick Gerleman
b12a6a340c Non-breaking const-correctness fixes (#1365)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1365

X-link: https://github.com/facebook/react-native/pull/39368

This changes public Yoga API to in more places accept const structures where before they required mutable ones.

`resolveRef` is added as a quick way to resolve overloaded opaque refs for different types which is a bit easier to read than static_casting, and which will propagate const-ness. We also add `YGConfigConstRef`, similar to `YGNodeConstRef`. I was a bit iffy on whether we should add something to make it easier to convert to private interface,  but this doesn't seem any easier to misuse than someone who looks at the internals to find the `static_cast`.

This tries to avoid more breaking changes yet, e.g. changing callbacks to require clients do not modify nodes when they are passed for logging. We also don't have const variants for returning child structures which would allow mutation of dependencies of the const object. These would need new names under the public API, since we do not have operator overloading in C.

Reviewed By: rshest

Differential Revision: D49130412

fbshipit-source-id: ee6b31b47f4622031c63dd52d8ac133d21bf29b7
2023-09-11 19:51:40 -07:00
Nick Gerleman
3cb29e60a8 Fix Running Java UTs with CXX Platform
Reviewed By: rshest

Differential Revision: D49131492

fbshipit-source-id: 80b2f108b2a5d80b92c1a11c573a61520b345ac2
2023-09-11 16:15:46 -07:00
Nick Gerleman
26d2a2682f yoga::bit_cast
Summary:
X-link: https://github.com/facebook/react-native/pull/39358

This adds a function polyfilling C++ 20's `std::bit_cast`, using `memcpy()` to be safe with strict aliasing rules.

This replaces the conditional code in CompactValue for type punning, an unsafe place in YGJNI where we do it unsafely, and is used in ValuePool. The polyfill can be switched to `std::bit_cast` whenever we adopt C++ 20.

Note that this doesn't actually call into `memcpy()`, as verified by Godbolt. Compilers are aware of the memcpy type punning pattern and optimize it, but it's ugly and confusing to folks who haven't seen it before.

Reviewed By: javache

Differential Revision: D49082997

fbshipit-source-id: b848775a68286bdb11b2a3a95bef8069364ac9b5
2023-09-08 13:03:48 -07:00
Nick Gerleman
f8e2bc0875 Add copyright header to ld version script (#1360)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1360

Fixes a ShipIt warning about this.

Reviewed By: yungsters

Differential Revision: D48992315

fbshipit-source-id: 20b6ba86abc27599e5f7dc12471344295151db66
2023-09-06 09:50:43 -07:00
Nick Gerleman
aee43a53bc Enable -Wconversion (#1359)
Summary:
X-link: https://github.com/facebook/react-native/pull/39291

Pull Request resolved: https://github.com/facebook/yoga/pull/1359

This enables clang warnings around potentially unsafe conversions, such as those with mismatched signedness, or ones which may lead to truncation.

This should catch issues in local development which create errors for MSVC (e.g. Dash), who's default `/W3` includes warnings akin to `-Wshorten-64-to-32`.

This full set of warnings here is a tad spammy, but probably more useful than not.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D48954777

fbshipit-source-id: 1ccc07b99d09d1c2d428158149698ffd04025605
2023-09-06 08:16:42 -07:00
Nick Gerleman
95a7b4497e Enable GitHub Actions Yarn Caching (#1332)
Summary:
We sometimes see workflows fail due to network flakiness, almost always being Windows agents doing a `yarn install`. This change enables storing and reusing Yarn's package cache, and makes `yarn install` more permissive when it does hit the network. https://stackoverflow.com/questions/51508364/yarn-there-appears-to-be-trouble-with-your-network-connection-retrying

Pull Request resolved: https://github.com/facebook/yoga/pull/1332

Test Plan: Workflows succeed, and we see cache being restored before yarn install step.

Reviewed By: lunaleaps

Differential Revision: D48967590

Pulled By: NickGerleman

fbshipit-source-id: 55ce6f05496f014512e0153b6646a7ca0ab964d9
2023-09-05 10:27:27 -07:00
Nick Gerleman
65ae809d5d C++ Cleanup 10/N: YGNodeCalculateLayout (#1352)
Summary:
X-link: https://github.com/facebook/react-native/pull/39195

Pull Request resolved: https://github.com/facebook/yoga/pull/1352

## This diff

This splits out all of the logic under `YGNodeCalculateLayout` to a couple of different files, does some mechanical renaming, and starts to split up the implementation a tiny bit. After this, core layout functions are all C++ convention and namespaced.

Each new file is marked as a move for the sake of blame history. It means Phabricator has a very inaccurate count of lines removed though.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48770478

fbshipit-source-id: 2a74b86441c3352de03ae193c98fc3a3573047ed
2023-09-05 05:24:54 -07:00
Nick Gerleman
7d8b9176fd C++ Cleanup 9/N: YGAssert (#1353)
Summary:
X-link: https://github.com/facebook/react-native/pull/39201

Pull Request resolved: https://github.com/facebook/yoga/pull/1353

## This diff

This moves and renames `YGAssert`, and removes it from the public API, since external users should not need to call into internal Yoga assert functions, and the current API prevents us from making this a macro later to include the condition in the message.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48769809

fbshipit-source-id: b5480ac54781bc01b00c158b07d2d751fac87d37
2023-09-04 11:20:17 -07:00
Nick Gerleman
7be985d97c C++ Cleanup 8/N: Yoga-internal (#1355)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1355

X-link: https://github.com/facebook/react-native/pull/39198

## This diff

This splits up `Yoga-internal.h` which has become a grab bag. The actual header is left, with the purpose of being a private C ABI for bindings, but everything else is moved to a place more appropriate or removed.

A few notes:
1. `yoga::isUndefined` is replaced with `std::isnan` to avoid a layer of indirection (we will never be able to change its representation anyway). Internal usages of `YGFloatIsUndefined` are also replaced with `std::isnan` since the previous being at a library boundary means I'm not sure it can be inlined/.
2. `leading`, `trailing` arrays are factored into proper functions
3. `Values` is replaced entirely with `std::array`, since most of it was unused.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48769241

fbshipit-source-id: 5b8e2192309539e7c133c3b3b29b445b59dd5835
2023-09-04 11:20:17 -07:00
Nick Gerleman
31b6c0ddc9 C++ Cleanup 7/N: BitUtils (#1351)
Summary:
X-link: https://github.com/facebook/react-native/pull/39223

X-link: https://github.com/facebook/react-native/pull/39200

Pull Request resolved: https://github.com/facebook/yoga/pull/1351

## This diff

This splits up `BitUtils.h`, does some minor renaming, and namespace consistency fixes.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

bypass-github-export-checks

Reviewed By: shwanton

Differential Revision: D48847255

fbshipit-source-id: 4b9722303372f43e936118f8187c0127bceeb1d4
2023-08-31 01:17:39 -07:00
Nick Gerleman
989f352e03 C++ Cleanup 6/N: YGFloatOptional (#1356)
Summary:
X-link: https://github.com/facebook/react-native/pull/39224

Pull Request resolved: https://github.com/facebook/yoga/pull/1356

X-link: https://github.com/facebook/react-native/pull/39196

## This diff

This renames YGFloatOptional to FloatOptional, adds it to a namespace, and moves it to a subdirectory. This needs Fabric updates because Fabric uses Yoga internals for props storage.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

bypass-github-export-checks

Reviewed By: shwanton

Differential Revision: D48847256

fbshipit-source-id: ab9729a4a02ab90d974183425935f4d274db5732
2023-08-31 01:17:39 -07:00
Nick Gerleman
c029041707 C++ Cleanup 5/N: Reorganize Utils (#1357)
Summary:
X-link: https://github.com/facebook/react-native/pull/39222

Pull Request resolved: https://github.com/facebook/yoga/pull/1357

X-link: https://github.com/facebook/react-native/pull/39199

## This diff

This splits `Utils.h` and `Utils.cpp`, and tweaks naming and namespaces.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

bypass-github-export-checks

Reviewed By: shwanton

Differential Revision: D48847260

fbshipit-source-id: b99df3029cd66257a7ae64de28c13e8751ceb20c
2023-08-31 01:17:39 -07:00
Nick Gerleman
b959774af7 C++ Cleanup 4/N: Reorganize Log and YGNodePrint (#1354)
Summary:
X-link: https://github.com/facebook/react-native/pull/39220

Pull Request resolved: https://github.com/facebook/yoga/pull/1354

X-link: https://github.com/facebook/react-native/pull/39197

## This diff

Moves these files to a `yoga/debug` subdirectory and does some mild renaming, namespace adjustment, and removes Yoga internal log function from list of library exports.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

bypass-github-export-checks

Reviewed By: shwanton

Differential Revision: D48847259

fbshipit-source-id: c1607b1c6457d5a47039c735cdb7c365a301ebc0
2023-08-31 01:17:39 -07:00
Nick Gerleman
992f073746 C++ Cleanup 3/N: Reorganize YGNode (#1350)
Summary:
X-link: https://github.com/facebook/react-native/pull/39219

Pull Request resolved: https://github.com/facebook/yoga/pull/1350

X-link: https://github.com/facebook/react-native/pull/39170

## This diff

This diff adds a top level `node` directory for code related to Yoga nodes and data structures on them (inc moving `YGLayout` to `LayoutResults`).

The public API for config handles is `YGNodeRef`, which is forward declared to be a pointer to a struct named `YGNode`. The existing `YGNode` is split into `yoga::Node`, as the private C++ implementation, inheriting from `YGNode`, a marker type represented as an empty struct. The public API continues to accept `YGNodeRef`, which continues to be `YGNode *`, but it must be cast to its concrete internal representation at the API boundary before doing work on it.

This change ends up needing to touch quite a bit, due to the amount of code that mixed and matched private and public APIs. Don't be scared though, because these changes are very mechanical, and Phabricator's line-count is 3x the actual amount due to mirrors and dirsyncs.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

bypass-github-export-checks

Reviewed By: shwanton

Differential Revision: D48847258

fbshipit-source-id: fc560893533b55a5c2d52c37d8e9a59f7369f174
2023-08-30 19:57:16 -07:00
Nick Gerleman
f82babba8a C++ Cleanup 2/N: Reorganize YGConfig (#1348)
Summary:
X-link: https://github.com/facebook/react-native/pull/39218

X-link: https://github.com/facebook/react-native/pull/39169

Pull Request resolved: https://github.com/facebook/yoga/pull/1348

## This diff

This diff adds a top level `config` directory for code related to configuring Yoga and Yoga Nodes.

The public API for config handles is `YGConfigRef`, which is forward declared to be a pointer to a struct named `YGConfig`. The existing `YGConfig` is split into `yoga::Config`, as the private C++ implementation, inheriting from `YGConfig`, a marker type represented as an empty struct. The public API continues to accept `YGConfigRef`, which continues to be `YGConfig *`, but it must be cast to its concrete internal representation at the API boundary before doing work on it.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

Reviewed By: shwanton

Differential Revision: D48847257

fbshipit-source-id: 7a2157d169ba80a6f79620693ae45bb10dfca5a3
2023-08-30 16:27:32 -07:00
Nick Gerleman
65d7f95901 C++ Cleanup 1/N: Reorganize YGStyle (#1349)
Summary:
X-link: https://github.com/facebook/react-native/pull/39221

Pull Request resolved: https://github.com/facebook/yoga/pull/1349

X-link: https://github.com/facebook/react-native/pull/39171

## This diff

This diff adds a `style` directory for code related to storing and manipulating styles. `YGStyle`, which is not a public API, is renamed to `yoga::Style` and moved into this folder, alongside `CompactValue`. We will eventually add `ValuePool` alongside this for the next generation style representation.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

Reviewed By: shwanton

Differential Revision: D48847261

fbshipit-source-id: 0fc8c6991e19079f3f0d55d368574757e453fe93
2023-08-30 16:27:32 -07:00
Zhiyao Zhou
2a32637c56 Revert D48710084: C++ Cleanup 1/N: Reorganize YGStyle
Differential Revision:
D48710084

Original commit changeset: 20961aee30d5

Original Phabricator Diff: D48710084

fbshipit-source-id: 79cda4f13979b8d0cdf87dabbfc13cbd17abe488
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
13c5ce2234 Revert D48710796: C++ Cleanup 2/N: Reorganize YGConfig
Differential Revision:
D48710796

Original commit changeset: d548553f7ce8

Original Phabricator Diff: D48710796

fbshipit-source-id: c8b2de245f3894f6a87c262ec70d313020aa228e
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
ea7f61a3db Revert D48712710: C++ Cleanup 3/N: Reorganize YGNode
Differential Revision:
D48712710

Original commit changeset: d28eae38469a

Original Phabricator Diff: D48712710

fbshipit-source-id: 7a10b071edcf045ce98bbf8f9deca0d0e2e80a14
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
6ca56e87ce Revert D48763820: C++ Cleanup 4/N: Reorganize Log and YGNodePrint
Differential Revision:
D48763820

Original commit changeset: 7e3ed7354497

Original Phabricator Diff: D48763820

fbshipit-source-id: 1bea996374f14481160aba8f87940c00e229aa69
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
4c0e89e492 Revert D48767465: C++ Cleanup 5/N: Reorganize Utils
Differential Revision:
D48767465

Original commit changeset: da7157953292

Original Phabricator Diff: D48767465

fbshipit-source-id: 0dd948e2c4e6b3aaeb6e197b28b565c0b385d033
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
7cf0483b17 Revert D48767992: C++ Cleanup 6/N: YGFloatOptional
Differential Revision:
D48767992

Original commit changeset: afaff0234359

Original Phabricator Diff: D48767992

fbshipit-source-id: 4666bdbb83aebbf2f7373b3a10a8c1dd0a03f92c
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
8a95b785a8 Revert D48768374: C++ Cleanup 7/N: BitUtils
Differential Revision:
D48768374

Original commit changeset: 921a22ec88bd

Original Phabricator Diff: D48768374

fbshipit-source-id: 59106ab3d03619940023dac1c2af62fd88566773
2023-08-29 23:27:25 -07:00
Nick Gerleman
866b4f7d62 C++ Cleanup 7/N: BitUtils (#1351)
Summary:
X-link: https://github.com/facebook/react-native/pull/39200

Pull Request resolved: https://github.com/facebook/yoga/pull/1351

## This diff

This splits up `BitUtils.h`, does some minor renaming, and namespace consistency fixes.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48768374

fbshipit-source-id: 921a22ec88bd470da1ef9b51f8954afc073d327d
2023-08-29 21:32:56 -07:00
Nick Gerleman
20fd7695e1 C++ Cleanup 6/N: YGFloatOptional (#1356)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1356

X-link: https://github.com/facebook/react-native/pull/39196

## This diff

This renames YGFloatOptional to FloatOptional, adds it to a namespace, and moves it to a subdirectory. This needs Fabric updates because Fabric uses Yoga internals for props storage.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D48767992

fbshipit-source-id: afaff023435915dbd5e571fd1ee2e695e4f59a5c
2023-08-29 21:32:56 -07:00
Nick Gerleman
8fd4d290e6 C++ Cleanup 5/N: Reorganize Utils (#1357)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1357

X-link: https://github.com/facebook/react-native/pull/39199

## This diff

This splits `Utils.h` and `Utils.cpp`, and tweaks naming and namespaces.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48767465

fbshipit-source-id: da71579532924b3a912454163fe281c481770a77
2023-08-29 21:32:56 -07:00
Nick Gerleman
9ba8aa409c C++ Cleanup 4/N: Reorganize Log and YGNodePrint (#1354)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1354

X-link: https://github.com/facebook/react-native/pull/39197

## This diff

Moves these files to a `yoga/debug` subdirectory and does some mild renaming, namespace adjustment, and removes Yoga internal log function from list of library exports.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48763820

fbshipit-source-id: 7e3ed7354497a7e85b2a1f20ab50b0e2baeb4862
2023-08-29 21:32:56 -07:00
Nick Gerleman
59f75b0194 C++ Cleanup 3/N: Reorganize YGNode (#1350)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1350

X-link: https://github.com/facebook/react-native/pull/39170

## This diff

This diff adds a top level `node` directory for code related to Yoga nodes and data structures on them (inc moving `YGLayout` to `LayoutResults`).

The public API for config handles is `YGNodeRef`, which is forward declared to be a pointer to a struct named `YGNode`. The existing `YGNode` is split into `yoga::Node`, as the private C++ implementation, inheriting from `YGNode`, a marker type represented as an empty struct. The public API continues to accept `YGNodeRef`, which continues to be `YGNode *`, but it must be cast to its concrete internal representation at the API boundary before doing work on it.

This change ends up needing to touch quite a bit, due to the amount of code that mixed and matched private and public APIs. Don't be scared though, because these changes are very mechanical, and Phabricator's line-count is 3x the actual amount due to mirrors and dirsyncs.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D48712710

fbshipit-source-id: d28eae38469afa24a8cb03e4e75eeb8e431173c5
2023-08-29 21:32:56 -07:00
Nick Gerleman
5af3a5d1d9 C++ Cleanup 2/N: Reorganize YGConfig (#1348)
Summary:
X-link: https://github.com/facebook/react-native/pull/39169

Pull Request resolved: https://github.com/facebook/yoga/pull/1348

## This diff

This diff adds a top level `config` directory for code related to configuring Yoga and Yoga Nodes.

The public API for config handles is `YGConfigRef`, which is forward declared to be a pointer to a struct named `YGConfig`. The existing `YGConfig` is split into `yoga::Config`, as the private C++ implementation, inheriting from `YGConfig`, a marker type represented as an empty struct. The public API continues to accept `YGConfigRef`, which continues to be `YGConfig *`, but it must be cast to its concrete internal representation at the API boundary before doing work on it.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D48710796

fbshipit-source-id: d548553f7ce872488ebdd697e0aceaa9a625df62
2023-08-29 21:32:56 -07:00
Nick Gerleman
b289d12248 C++ Cleanup 1/N: Reorganize YGStyle (#1349)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1349

X-link: https://github.com/facebook/react-native/pull/39171

## This diff

This diff adds a `style` directory for code related to storing and manipulating styles. `YGStyle`, which is not a public API, is renamed to `yoga::Style` and moved into this folder, alongside `CompactValue`. We will eventually add `ValuePool` alongside this for the next generation style representation.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D48710084

fbshipit-source-id: 20961aee30d54a6b0d8c1cc2976df09b9b6d486a
2023-08-29 21:32:56 -07:00
Andrew Wang
49fbd406b6 Ship the fix for local reference overflow in Yoga (#1347)
Summary:
X-link: https://github.com/facebook/litho/pull/954

X-link: https://github.com/facebook/react-native/pull/39132

Pull Request resolved: https://github.com/facebook/yoga/pull/1347

# Context

Reviewed By: NickGerleman, astreet

Differential Revision: D48607502

fbshipit-source-id: 79552bc76879d1fc15341423ae6fbadeab2fb7af
2023-08-24 12:48:56 -07:00
Nick Gerleman
38ad93c87b Fix segfault calling YGJNILogFunc (#1344)
Summary:
X-link: https://github.com/facebook/react-native/pull/39051

Pull Request resolved: https://github.com/facebook/yoga/pull/1344

`YGJNILogFunc` has a bug where it uses a `va_list` to determine the length of a printf string, then reuses the same `va_list` later after it has already been iterated through. Even if no arguments are present, this may cause a crash looking something like:

```
C  [libsystem_platform.dylib+0xf12]  _platform_strlen+0x12
C  [libsystem_c.dylib+0x31bf]  __vfprintf+0x1339
C  [libsystem_c.dylib+0x307ce]  _vsnprintf+0x100
C  [libsystem_c.dylib+0x6965]  vsnprintf+0x44
C  [libyoga.dylib+0x5161]  YGJNILogFunc(YGConfig*, YGNode*, YGLogLevel, void*, char const*, __va_list_tag*)+0x59
```

Fixing this fixes crashing unit tests which are not explicitly disabled.

Reviewed By: yungsters

Differential Revision: D48388548

fbshipit-source-id: 492e7a89aeb5f9d15485ce31641875a295356bef
2023-08-18 00:07:51 -07:00
Roland Crosby
910adaa5dc Update standalone JS docs (#1342)
Summary:
Excited to see some activity around this project! The move from Flow to TypeScript broke one of the links in the documentation, which this PR fixes. I went ahead and updated the example code as well, since it looks like some things moved around since the switch to the async loader.

Pull Request resolved: https://github.com/facebook/yoga/pull/1342

Reviewed By: yungsters

Differential Revision: D48337554

Pulled By: NickGerleman

fbshipit-source-id: 8397cab60cf2104e271029a235f287a179ece2f4
2023-08-14 21:20:59 -07:00
Lvv.me
ef5784aca6 Add SwiftPM support (#1339)
Summary:
Using yoga in Swift

```swift
import UIKit
import yoga

let YGUndefined = Float.nan

UIGraphicsBeginImageContextWithOptions(CGSize(width: 1, height: 1), true, 0)
let scale = UIGraphicsGetCurrentContext()?.ctm.a ?? 1
UIGraphicsEndImageContext()

let config = YGConfigNew()
YGConfigSetUseWebDefaults(config, true)
YGConfigSetPointScaleFactor(config, Float(scale))

let root = YGNodeNewWithConfig(config)
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow)
YGNodeStyleSetFlexWrap(root, YGWrapWrap)
YGNodeStyleSetWidth(root, 200)

for i in 0..<4 {
    let leaf = YGNodeNewWithConfig(config)
    YGNodeStyleSetAspectRatio(leaf, 1)
    YGNodeStyleSetWidthPercent(leaf, 50)
    YGNodeInsertChild(root, leaf, UInt32(i))
}

YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGNodeStyleGetDirection(root))

for i in 0..<4 {
    let leaf = YGNodeGetChild(root, UInt32(i))
    let left = YGNodeLayoutGetLeft(leaf)
    let top = YGNodeLayoutGetTop(leaf)
    let width = YGNodeLayoutGetWidth(leaf)
    let height = YGNodeLayoutGetHeight(leaf)

    print("leaf \(i): origin: \(left), \(top), size: \(width), \(height)")
}

let width = YGNodeLayoutGetWidth(root)
let height = YGNodeLayoutGetHeight(root)

print("root size: \(width), \(height)")

YGNodeFreeRecursive(root)
YGConfigFree(config)
```

Pull Request resolved: https://github.com/facebook/yoga/pull/1339

Reviewed By: cipolleschi

Differential Revision: D48166958

Pulled By: NickGerleman

fbshipit-source-id: 72fef99729d01c7ba291b11f047cf75fd39f7630
2023-08-10 17:40:10 -07:00
Nick Gerleman
c18e2566a0 Fix set-version script corrupting files when new version is shorter than old one
Summary: We were leaving the last bits of the previous string around if writing a new file which is shorter. See 30b697d3fe for an example.

Reviewed By: cortinico

Differential Revision: D47824696

fbshipit-source-id: 82ebafd9cd1720752cbc62ea93c5b9362395d5c8
2023-07-28 09:48:07 -07:00
Nick Gerleman
44507ec62e Unify ESLint and Prettier across xplat/yoga (#1335)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1335

Reviewed By: christophpurrer

Differential Revision: D47459866

fbshipit-source-id: fd6b4e4e2518d91968ac7180b32129b3f70edf88
2023-07-17 14:27:32 -07:00
Nick Gerleman
05b2edfb85 Explicit C++ toolchain on ubuntu-latest (#1334)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1334

Last change made me discover CMake on Ubuntu defaults to GCC. This change makes it so that we explicitly configure whether to use Clang/LLVM or GCC when building on machines with the `ubuntu-latest` image.

Reviewed By: christophpurrer

Differential Revision: D47462132

fbshipit-source-id: e81fb6d4b1740ab2913d39b6e90c52d674e5a4f2
2023-07-14 20:54:41 -07:00
Nick Gerleman
61bf4d15ab Fixup Yoga UT compilation on non-clang compilers (#1333)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1333

Yoga is compiled on more than clang, both internally, and in OSS. D47345669 added unguarded usage of `
#pragma clang diagnostic push` to Yoga UTs which will cause unrecognized pragma errors if building the tests on other platforms.

The code here is flagged for implicitly converting enum to float. This is test code which is using the enum as an arbitrary differentiating input, so I just changed this to an explicit cast, which I assume should silence the warning.

Reviewed By: NuriAmari

Differential Revision: D47460301

fbshipit-source-id: 952ff61e0c26deb8bbff8b860faf30896753a3bd
2023-07-14 09:49:50 -07:00
dependabot[bot]
45b0697960 Bump semver from 5.7.1 to 5.7.2 (#1328)
Summary:
Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/npm/node-semver/releases">semver's releases</a>.</em></p>
<blockquote>
<h2>v5.7.2</h2>
<h2><a href="https://github.com/npm/node-semver/compare/v5.7.1...v5.7.2">5.7.2</a> (2023-07-10)</h2>
<h3>Bug Fixes</h3>
<ul>
<li><a href="2f8fd41487"><code>2f8fd41</code></a> <a href="https://redirect.github.com/npm/node-semver/pull/585">https://github.com/facebook/yoga/issues/585</a> better handling of whitespace (<a href="https://redirect.github.com/npm/node-semver/issues/585">https://github.com/facebook/yoga/issues/585</a>) (<a href="https://github.com/joaomoreno"><code>@​joaomoreno</code></a>, <a href="https://github.com/lukekarrys"><code>@​lukekarrys</code></a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md">semver's changelog</a>.</em></p>
<blockquote>
<h2><a href="https://github.com/npm/node-semver/compare/v5.7.1...v5.7.2">5.7.2</a> (2023-07-10)</h2>
<h3>Bug Fixes</h3>
<ul>
<li><a href="2f8fd41487"><code>2f8fd41</code></a> <a href="https://redirect.github.com/npm/node-semver/pull/585">https://github.com/facebook/yoga/issues/585</a> better handling of whitespace (<a href="https://redirect.github.com/npm/node-semver/issues/585">https://github.com/facebook/yoga/issues/585</a>) (<a href="https://github.com/joaomoreno"><code>@​joaomoreno</code></a>, <a href="https://github.com/lukekarrys"><code>@​lukekarrys</code></a>)</li>
</ul>
<h2>5.7</h2>
<ul>
<li>Add <code>minVersion</code> method</li>
</ul>
<h2>5.6</h2>
<ul>
<li>Move boolean <code>loose</code> param to an options object, with
backwards-compatibility protection.</li>
<li>Add ability to opt out of special prerelease version handling with
the <code>includePrerelease</code> option flag.</li>
</ul>
<h2>5.5</h2>
<ul>
<li>Add version coercion capabilities</li>
</ul>
<h2>5.4</h2>
<ul>
<li>Add intersection checking</li>
</ul>
<h2>5.3</h2>
<ul>
<li>Add <code>minSatisfying</code> method</li>
</ul>
<h2>5.2</h2>
<ul>
<li>Add <code>prerelease(v)</code> that returns prerelease components</li>
</ul>
<h2>5.1</h2>
<ul>
<li>Add Backus-Naur for ranges</li>
<li>Remove excessively cute inspection methods</li>
</ul>
<h2>5.0</h2>
<ul>
<li>Remove AMD/Browserified build artifacts</li>
<li>Fix ltr and gtr when using the <code>*</code> range</li>
<li>Fix for range <code>*</code> with a prerelease identifier</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="f8cc313550"><code>f8cc313</code></a> chore: release 5.7.2</li>
<li><a href="2f8fd41487"><code>2f8fd41</code></a> fix: better handling of whitespace (<a href="https://redirect.github.com/npm/node-semver/issues/585">https://github.com/facebook/yoga/issues/585</a>)</li>
<li><a href="deb5ad51bf"><code>deb5ad5</code></a> chore: <code>@​npmcli/template-oss</code><a href="https://github.com/4"><code>@​4</code></a>.16.0</li>
<li>See full diff in <a href="https://github.com/npm/node-semver/compare/v5.7.1...v5.7.2">compare view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a href="https://www.npmjs.com/~lukekarrys">lukekarrys</a>, a new releaser for semver since your current version.</p>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=semver&package-manager=npm_and_yarn&previous-version=5.7.1&new-version=5.7.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

 ---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `dependabot rebase` will rebase this PR
- `dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `dependabot merge` will merge this PR after your CI passes on it
- `dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `dependabot cancel merge` will cancel a previously requested merge and block automerging
- `dependabot reopen` will reopen this PR if it is closed
- `dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/facebook/yoga/network/alerts).

</details>

Pull Request resolved: https://github.com/facebook/yoga/pull/1328

Reviewed By: yungsters

Differential Revision: D47414316

Pulled By: NickGerleman

fbshipit-source-id: 9a38149c18cfc0fef714ffc9ce73f92a463224a1
2023-07-13 18:13:35 -07:00
Nick Gerleman
aa6a5d8888 Docusarus: Build validation (#1329)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1329

Add build validation for `website-next`, also adding validation that `yoga-layout/sync` may be bundled by Webpack out-of-the-box.

Reviewed By: christophpurrer

Differential Revision: D47414176

fbshipit-source-id: 9adc4f9673333f4f79c91352f445489d6da05a07
2023-07-13 14:08:07 -07:00
Nick Gerleman
45088187a7 Docusaurus: Replant Playground (#1331)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1331

This lifts and copies code from the Yoga Playground component of the old website, to the new one, using a live workspace version of JS Yoga. This may eventually be used if the new website is fleshed out, but this also gives us real-world validation of the Yoga bindings in a web scenario, compared to the Node test runner. There is still some cleanup here needed, but we are able to bundle, typecheck, and render the playground now.

The code here is mostly the same as before, but I removed some of the cruftier bits (e.g. URL shortener that goes to some private Heroku instance), and needed to do some tweaks for the new Yoga package, and TypeScript.

This is currently using `yoga-layout/sync`, the asmjs bindings. But I had previously checked bundling against the wasm ones.

Reviewed By: cortinico

Differential Revision: D46884439

fbshipit-source-id: f53f0855c131cd2b81975bf05f71c43713600616
2023-07-13 14:08:07 -07:00
Nuri Amari
6ae890dccd Pragma guard remaining -Wenum-conversion failures
Summary:
These incorrect enum conversions constitute compile errors
with Pika / Xcode 15. Pragma guard the current offenders so
we can make the warning fatal again.

Reviewed By: drodriguez

Differential Revision: D47345669

fbshipit-source-id: bb85a93e9f48236c9f8c54d59d55a86648c1c6fd
2023-07-13 09:53:47 -07:00
Nick Gerleman
5bbaadfa54 Add blurb about configuring TypeScript for ESM resolution (#1330)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1330

This has been tripping folks up a bit. Add a blurb to the package README to call it out.

Reviewed By: cortinico

Differential Revision: D47370333

fbshipit-source-id: f07b2e4d0e23865e3554c7aaf6ec77dff71a7423
2023-07-12 15:43:10 -07:00
Nick Gerleman
5310eb3cf7 Separate Node and Web Binaries (#1325)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1325

Fixes https://github.com/facebook/yoga/issues/1321

Reviewed By: cortinico

Differential Revision: D47368830

fbshipit-source-id: 570a45ad7fd182ef82e6edda4037ae2f6faa0c75
2023-07-12 15:43:10 -07:00
Nick Gerleman
7097b12b92 Remove YogaKit
Summary: We deprecated this as part of the Yoga 2.0 release. The last version is still present as part of the release-v2.0 branch, and was still published, but we are not carrying the code forward. This removes it.

Reviewed By: mdvacca

Differential Revision: D47136781

fbshipit-source-id: ac60939efb2372db04e33ed26456bad2f3b5852b
2023-07-12 12:19:27 -07:00
Nick Gerleman
660edcec20 C++ 17 style nested namespaces (#1326)
Summary:
X-link: https://github.com/facebook/react-native/pull/38304

Pull Request resolved: https://github.com/facebook/yoga/pull/1326

For better readability

Reviewed By: christophpurrer

Differential Revision: D47384926

fbshipit-source-id: 2f60d50a185331b3624d45d1fc45f98d504b3034
2023-07-12 09:38:40 -07:00
Nick Gerleman
423dc155d8 Target C++ 17 (#1327)
Summary:
X-link: https://github.com/facebook/react-native/pull/38303

Pull Request resolved: https://github.com/facebook/yoga/pull/1327

This bumps Yoga to C++ 17 for a few reasons:
1. New versions of C++ may introduce behavior changes (e.g. evaluation order) and deprecations. Keeping the version closer to the version of large users helps avoid that.
2. C++ 17 unblocks some new bits I have wanted to use at times, like `std::optional`, `std::variant`, `if constexpr`, `[[nodiscard]]`.
3. There are already changes in C++ 20 that would be directly useful to Yoga, like `std::bit_cast` to avoid `memcpy` style type punning.

There has been some contention around C++ versions before, but by the time the next stable version of Yoga is out, it will have been more than 6 years (~2 C++ versions) since a stable version of Clang/LLVM with C++ 17 support. I would not like to go back further than n-2.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D47383922

fbshipit-source-id: eb95d4853f2168b68d6df5fddb797236eac55870
2023-07-12 09:38:40 -07:00
Nicola Corti
dbd8e915d5 Remove the build-logic module
Summary:
As now we have a single module to publish, I'm removing the build-logic folder and moving everything inside the java/build.gradle file.
I've also converted it to Kotlin,

Reviewed By: NickGerleman

Differential Revision: D47259204

fbshipit-source-id: 2378d9e9598d7816f230db5f763f2b0f4cdf01d0
2023-07-11 04:30:02 -07:00
Nick Gerleman
f7324fb71e Remove YogaLayout ViewGroup (#1318)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1318

We deprecated this as part of the Yoga 2.0 release. The last version is still present as part of the `release-v2.0` branch, and was still published, but we are not carrying the code forward. This removes it.

There are a couple followups here:
1. The top-level organization (e.g. a gradle-specific directory called `build-logic` in a multi-language repo) can and should be cleaned up. Yoga Java bindings should be condensed to the `java` folder.
2. We no longer have a sample app excersizing the bindings. We should resolve this by getting the JNI binding UTs working in OSS again.

Reviewed By: cortinico

Differential Revision: D47136243

fbshipit-source-id: 72f74914effde2c895934ac1100adfd305044d46
2023-07-05 22:00:16 -07:00
Nick Gerleman
1b40f05b8c Fixes for publish workflows (#1319)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1319

This fixes a few issues encountered during publishing Yoga `2.0.0-beta.1`.

1. The tag trigger was missing quotes needed to be valid syntax
2. `pod trunk publish` must be run with `--synchronous` if we are publishing a package that relies on another just published package. There does not seem to be a way to just publish evertything at once.
3. `yarn publish` was not reading the NPM auth token from the environment, so we write it to a `.npmrc` before publishing.
4. The root `.gitignore` was not updated when moving to yarn workspaces to ignore `node_modules`, so the OSS Yoga repo (not internal) will, try to add its contents after `yarn install`.

Reviewed By: cortinico

Differential Revision: D47135994

fbshipit-source-id: d8c9b05176a98443be1ebc7cf74996f22520d20d
2023-06-30 11:44:15 -07:00