Add Global CMake Build and OSS Tests (#1217)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1217 This updates the CMake build present for being able to share options, fixing up flags, etc. A GTest build is added as well, along with a script and VSCode debug target so that OSS contributors can very easily run and debug tests on any OS. Note that this isn't completely done (need to revise Windows, Mac, documentation), but should be finished enough otherwise for review. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D42406686 fbshipit-source-id: 95e7ba5e4751c496a171785490e85cf0097fa839
This commit is contained in:
committed by
Facebook GitHub Bot
parent
53872e2521
commit
83c6997f29
66
README.md
66
README.md
@@ -1,28 +1,24 @@
|
||||
# Yoga [](https://opensource.fb.com/support-ukraine) [](http://cocoapods.org/pods/YogaKit) [](https://www.npmjs.com/package/yoga-layout) [](https://bintray.com/facebook/maven/com.facebook.yoga%3Ayoga/_latestVersion) [](https://www.nuget.org/packages/Facebook.Yoga)
|
||||
# Yoga [](https://opensource.fb.com/support-ukraine) [](http://cocoapods.org/pods/YogaKit) [](https://www.npmjs.com/package/yoga-layout) [](https://search.maven.org/artifact/com.facebook.yoga/yoga)
|
||||
|
||||
Yoga is an embeddable and performant flexbox layout engine with bindings for multiple languages.
|
||||
|
||||
|
||||
## Building
|
||||
Yoga builds with [buck](https://buckbuild.com). Make sure you install buck before contributing to Yoga. Yoga's main implementation is in C++, with bindings to supported languages and frameworks. When making changes to Yoga please ensure the changes are also propagated to these bindings when applicable.
|
||||
|
||||
Alternatively, you can build and install Yoga using [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
|
||||
Yoga's main implementation targets C++ 14 with accompanying build logic in CMake. A wrapper is provided to build the main library and run unit tests.
|
||||
|
||||
```sh
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg integrate install
|
||||
./vcpkg install yoga
|
||||
./unit_tests <Debug|Release>
|
||||
```
|
||||
|
||||
The Yoga port in vcpkg is kept up to date by Microsoft team members and community contributors.
|
||||
While not required, this script will use [ninja](https://ninja-build.org/) if it is installed for faster builds.
|
||||
|
||||
If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
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.
|
||||
|
||||
## Testing
|
||||
For testing we rely on [gtest](https://github.com/google/googletest) as a submodule. After cloning Yoga run `git submodule init` followed by `git submodule update`.
|
||||
|
||||
For any changes you make you should ensure that all the tests are passing. In case you make any fixes or additions to the library please also add tests for that change to ensure we don't break anything in the future. Tests are located in the `tests` directory. Run the tests by executing `buck test //:yoga`.
|
||||
|
||||
Instead of manually writing a test which ensures parity with web implementations of Flexbox you can run `gentest/gentest.rb` to generate a test for you. You can write html which you want to verify in Yoga, in `gentest/fixtures` folder, such as the following.
|
||||
## Adding Tests
|
||||
|
||||
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`.
|
||||
|
||||
```html
|
||||
<div id="my_test" style="width: 100px; height: 100px; align-items: center;">
|
||||
@@ -30,41 +26,11 @@ Instead of manually writing a test which ensures parity with web implementations
|
||||
</div>
|
||||
```
|
||||
|
||||
Run `gentest/gentest.rb` to generate test code and re-run `buck test //:yoga` to validate the behavior. One test case will be generated for every root `div` in the input html.
|
||||
To generate new tests from added fixtures:
|
||||
1. Run `bundle install` in the `gentest` directory to install dependencies of the test generator.
|
||||
2. Run `ruby gentest.rb` in the `gentest` directory.
|
||||
|
||||
You should run `bundle install` in the `gentest` directory to install dependencies for the `gentest/gentest.rb` Ruby script.
|
||||
|
||||
### .NET
|
||||
.NET testing is not integrated in buck yet, you might need to set up .NET testing environment. We have a script which to launch C# test on macOS, `csharp/tests/Facebook.Yoga/test_macos.sh`.
|
||||
## Debugging
|
||||
|
||||
## Benchmarks
|
||||
Benchmarks are located in `benchmark/YGBenchmark.c` and can be run with `buck run //benchmark:benchmark`. If you think your change has affected performance please run this before and after your change to validate that nothing has regressed. Benchmarks are run on every commit in CI.
|
||||
|
||||
### JavaScript
|
||||
Installing through NPM
|
||||
```sh
|
||||
npm install yoga-layout
|
||||
```
|
||||
By default this will install the library and try to build for all platforms (node, browser asm, and standalone webpack). You may receive errors if you do not have the required platform development tools already installed. To preset the platform you'd like to build for you can set a .npmrc property first.
|
||||
```sh
|
||||
npm config set yoga-layout:platform standalone
|
||||
```
|
||||
This will now only run the standalone webpack build upon install.
|
||||
|
||||
## Build Platforms
|
||||
|
||||
| name | description |
|
||||
|----------------|-------------------------------------------------|
|
||||
| all (default) | Builds all of these platforms. |
|
||||
| browser | Builds asm js browser version. |
|
||||
| node | Builds node js version. |
|
||||
| standalone | Runs webpack. |
|
||||
| none | Does nothing. You can use the prepackaged libs. |
|
||||
|
||||
## Maintainer Release Guide
|
||||
|
||||
Release artifacts are published automatically when a new GitHub release is
|
||||
created. The publishing workflows may also be executed manually, given a Git
|
||||
Tag, to re-attempt publish.
|
||||
|
||||
NPM and NuGet packages are not currently published.
|
||||
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).
|
||||
|
Reference in New Issue
Block a user