2023-07-12 12:19:27 -07:00
# Yoga [](https://opensource.fb.com/support-ukraine) [](http://cocoapods.org/pods/Yoga) [](https://www.npmjs.com/package/yoga-layout) [](https://search.maven.org/artifact/com.facebook.yoga/yoga)
2023-01-16 07:56:11 -08:00
Yoga is an embeddable and performant flexbox layout engine with bindings for multiple languages.
2017-02-13 09:27:44 -08:00
2023-01-16 07:56:11 -08:00
## Building
2023-12-14 11:48:22 -08:00
Breaking: Use C++ 20 (#1382)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1382
X-link: https://github.com/facebook/react-native/pull/39437
Have been running into places where C++ 20 makes life easier for use like `std::bit_cast` (that one is easy to polyfill), in-class member initializer support for bitfields, designated initializers, defaulted comparison operator, concepts instead of SFINAE, and probably more.
Our other infra is in the process of making this jump, or already has. This tests it out everywhere, across the various reference builds, to see if we have any issues.
This is a bit more aggressive than I had previously communicated, but n - 1 is going to be a better long term place than n - 2.
If we wanted to use `std::bit_cast` we would need one of:
1. GCC 11+ (~2.5 years old)
1. Clang 14 (~2.5 years old)
1. VS 16.11 (~2 years old)
For mobile this means:
1. NDK 26 (still in Beta 😭)
1. XCode 14.3.0 (~6 months old)
https://en.cppreference.com/w/cpp/compiler_support/20
That isn't quite doable yet, but we can start taking advantage of language features in the meantime. More of these will be supported in older toolchains.
Anyone needing support for older C++ versions can lag behind on more recent changes. E.g. Yoga 2.0 supports C++ 14.
bypass-github-export-checks
Changelog: [Internal]
Reviewed By: cortinico
Differential Revision: D49261607
fbshipit-source-id: ceb06eac20dfe93352d7b796d6847a7314069cf3
2023-09-19 01:28:35 -07:00
Yoga's main implementation targets C++ 20 with accompanying build logic in CMake. A wrapper is provided to build the main library and run unit tests.
Add vcpkg installation instructions (#970)
Summary:
Yoga is available as a port in VCPKG , documenting the install process here will help users get started by providing a single set of commands to build yoga, ready to be included in their projects.
VCPKG is a C++ library manager that simplifies installation for yoga and other project dependencies, we also test whether our library ports build in various configurations (dynamic, static) on various platforms (OSX, Linux, Windows: x86, x64, UWP, ARM) to keep a wide coverage for users.
I'm a maintainer for vcpkg, and here is what the port script looks like. We try to keep the library maintained as close as possible to the original library.
Pull Request resolved: https://github.com/facebook/yoga/pull/970
Reviewed By: yungsters
Differential Revision: D40027569
Pulled By: yungsters
fbshipit-source-id: ca9a6aa481c7b46e96c5937fe3cc7b716e464e4d
2022-10-03 21:10:17 -07:00
```sh
2023-01-16 07:56:11 -08:00
./unit_tests < Debug | Release >
Add vcpkg installation instructions (#970)
Summary:
Yoga is available as a port in VCPKG , documenting the install process here will help users get started by providing a single set of commands to build yoga, ready to be included in their projects.
VCPKG is a C++ library manager that simplifies installation for yoga and other project dependencies, we also test whether our library ports build in various configurations (dynamic, static) on various platforms (OSX, Linux, Windows: x86, x64, UWP, ARM) to keep a wide coverage for users.
I'm a maintainer for vcpkg, and here is what the port script looks like. We try to keep the library maintained as close as possible to the original library.
Pull Request resolved: https://github.com/facebook/yoga/pull/970
Reviewed By: yungsters
Differential Revision: D40027569
Pulled By: yungsters
fbshipit-source-id: ca9a6aa481c7b46e96c5937fe3cc7b716e464e4d
2022-10-03 21:10:17 -07:00
```
2023-01-16 07:56:11 -08:00
While not required, this script will use [ninja ](https://ninja-build.org/ ) if it is installed for faster builds.
Yoga is additionally part of the [vcpkg ](https://github.com/Microsoft/vcpkg/ ) collection of ports maintained by Microsoft and community contributors. If the version is out of date, please [create an issue or pull request ](https://github.com/Microsoft/vcpkg ) on the vcpkg repository.
Add vcpkg installation instructions (#970)
Summary:
Yoga is available as a port in VCPKG , documenting the install process here will help users get started by providing a single set of commands to build yoga, ready to be included in their projects.
VCPKG is a C++ library manager that simplifies installation for yoga and other project dependencies, we also test whether our library ports build in various configurations (dynamic, static) on various platforms (OSX, Linux, Windows: x86, x64, UWP, ARM) to keep a wide coverage for users.
I'm a maintainer for vcpkg, and here is what the port script looks like. We try to keep the library maintained as close as possible to the original library.
Pull Request resolved: https://github.com/facebook/yoga/pull/970
Reviewed By: yungsters
Differential Revision: D40027569
Pulled By: yungsters
fbshipit-source-id: ca9a6aa481c7b46e96c5937fe3cc7b716e464e4d
2022-10-03 21:10:17 -07:00
2023-01-16 07:56:11 -08:00
## Adding Tests
2016-08-12 08:47:17 -07:00
2023-01-16 07:56:11 -08:00
Many of Yoga's tests are automatically generated, using HTML fixtures describing node structure. These are rendered in Chrome to generate an expected layout result for the tree. New fixtures can be added to `gentest/fixtures` .
2016-08-12 08:47:17 -07:00
```html
2016-12-07 16:18:13 +00:00
< div id = "my_test" style = "width: 100px; height: 100px; align-items: center;" >
2016-08-12 08:47:17 -07:00
< div style = "width: 50px; height: 50px;" > < / div >
< / div >
```
2016-07-25 09:41:00 -07:00
2023-01-16 07:56:11 -08:00
To generate new tests from added fixtures:
2021-05-21 11:40:17 -07:00
2023-12-15 16:26:31 -08:00
1. Ensure you have [yarn classic ](https://classic.yarnpkg.com ) installed.
2023-12-14 11:48:22 -08:00
2. Run `yarn install` to install dependencies for the test generator.
3. Run `yarn gentest` in the `yoga` directory.
2021-05-21 11:40:17 -07:00
2023-01-16 07:56:11 -08:00
## Debugging
2021-05-21 11:40:17 -07:00
2023-01-16 07:56:11 -08:00
Yoga provides a VSCode "launch.json" configuration which allows debugging unit tests. Simply add your breakpoints, and run "Debug C++ Unit tests (lldb)" (or "Debug C++ Unit tests (vsdbg)" on Windows).