Skip to content

Commit

Permalink
Merge pull request #2 from cntrump/feature/upgrade_yoga3
Browse files Browse the repository at this point in the history
Upgrade to yoga3 (b12e0a2)
  • Loading branch information
cntrump authored Jan 25, 2025
2 parents 1c02081 + b2ba557 commit 29e62b4
Show file tree
Hide file tree
Showing 180 changed files with 43,291 additions and 14,281 deletions.
14 changes: 10 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


import PackageDescription

Expand Down Expand Up @@ -31,9 +38,9 @@ let package = Package(
name: "YogaKitSwift",
dependencies: ["YogaKit", "Yoga"],
path: ".",
exclude: ["yoga/include/Yoga.modulemap"],
sources: ["YogaKit/YogaKit.Swift"],
cSettings: [
.headerSearchPath("."),
.headerSearchPath("yoga")
]),
.target(
Expand All @@ -49,13 +56,12 @@ let package = Package(
.target(
name: "Yoga",
path: ".",
exclude: ["yoga/Yoga.h"],
sources: ["yoga"],
publicHeadersPath: "yoga/include",
cSettings: [
.headerSearchPath(".")
])
],
swiftLanguageVersions: [.v5],
cLanguageStandard: .gnu11,
cxxLanguageStandard: .gnucxx14
cxxLanguageStandard: CXXLanguageStandard(rawValue: "c++20")
)
79 changes: 20 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,35 @@
# Yoga [![CocoaPods](https://img.shields.io/cocoapods/v/YogaKit.svg)](http://cocoapods.org/pods/YogaKit) [![npm](https://img.shields.io/npm/v/yoga-layout.svg)](https://www.npmjs.com/package/yoga-layout) [![bintray](https://img.shields.io/bintray/v/facebook/maven/com.facebook.yoga:yoga.svg)](https://bintray.com/facebook/maven/com.facebook.yoga%3Ayoga/_latestVersion) [![NuGet](https://img.shields.io/nuget/v/Facebook.Yoga.svg)](https://www.nuget.org/packages/Facebook.Yoga)
# Yoga [![CocoaPods](https://img.shields.io/cocoapods/v/Yoga.svg)](http://cocoapods.org/pods/Yoga) [![npm](https://img.shields.io/npm/v/yoga-layout.svg)](https://www.npmjs.com/package/yoga-layout) [![Maven Central](https://img.shields.io/maven-central/v/com.facebook.yoga/yoga)](https://search.maven.org/artifact/com.facebook.yoga/yoga) ![SPM](https://img.shields.io/badge/SPM-Supported-blue.svg)

## 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.

## 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`.
Yoga is an embeddable and performant flexbox layout engine with bindings for multiple languages.

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`.
## Building

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.
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.

```html
<div id="my_test" style="width: 100px; height: 100px; align-items: center;">
<div style="width: 50px; height: 50px;"></div>
</div>
```sh
./unit_tests <Debug|Release>
```

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.
While not required, this script will use [ninja](https://ninja-build.org/) if it is installed for faster builds.

You may need to install the latest watir-webdriver gem (`gem install watir-webdriver`) and [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/) to run `gentest/gentest.rb` Ruby script.
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.

### .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`.
## Adding Tests

## 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.
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`.

### 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
```html
<div id="my_test" style="width: 100px; height: 100px; align-items: center;">
<div style="width: 50px; height: 50px;"></div>
</div>
```
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. |
To generate new tests from added fixtures:

## Maintainer Release Guide
1. Ensure you have [yarn classic](https://classic.yarnpkg.com) installed.
2. Run `yarn install` to install dependencies for the test generator.
3. Run `yarn gentest` in the `yoga` directory.

To publish a new release, follow these steps:

1. Ensure you have your GPG key set up and your [OSS Sonatype](https://oss.sonatype.org/) credentials handy.
2. Add the follow entries to either your local `gradle.properties` (don't forget to revert) or your global `~/.gradle/gradle.properties`:

```
# You get these from https://oss.sonatype.org/#profile;User%20Token
mavenCentralRepositoryUsername=<username>
mavenCentralRepositoryPassword=<password>
# You can get the keyId (in GPG 1.4 format) by running `gpg1 --list-keys`.
signing.secretKeyRingFile=</path/to/secring.gpg>
signing.keyId=<key_id>
signing.password=<key_password>
```
## Debugging

3. Change the `VERSION_NAME` in `gradle.properties` to a non-SNAPSHOT release.
4. Commit and land the version change.
5. Run `./gradlew publishToMaven`.
6. Run `./gradlew closeAndReleaseRepository`.
7. Change the `VERSION_NAME` in `gradle.properties` back to a new SNAPSHOT release.
8. Commit and land the version change.
9. Celebrate! You've made a release!
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).
2 changes: 1 addition & 1 deletion YogaKit/Source/YGLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ - (void)configureLayoutWithBlock:(NS_NOESCAPE YGLayoutConfigurationBlock)block {

#pragma mark - Private

static YGSize YGMeasureView(YGNodeRef node, double width, YGMeasureMode widthMode, double height, YGMeasureMode heightMode) {
static YGSize YGMeasureView(YGNodeConstRef node, double width, YGMeasureMode widthMode, double height, YGMeasureMode heightMode) {
const CGFloat constrainedWidth = (widthMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : width;
const CGFloat constrainedHeight = (heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : height;

Expand Down
4 changes: 1 addition & 3 deletions YogaKit/Tests/YogaKitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,9 @@ - (void)testMarkingDirtyOnlyWorksOnLeafNodes {
subview.yoga.isIncludedInLayout = YES;
[container addSubview:subview];

XCTAssertFalse(container.yoga.isDirty);
[container.yoga markDirty];
XCTAssertFalse(container.yoga.isDirty);
XCTAssertTrue(container.yoga.isDirty);

XCTAssertFalse(subview.yoga.isDirty);
[subview.yoga markDirty];
XCTAssertTrue(subview.yoga.isDirty);
}
Expand Down
Loading

0 comments on commit 29e62b4

Please sign in to comment.