From 6f80a35b21779782d579717932ab9faa0c86c260 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 11 May 2023 00:18:43 -0700 Subject: [PATCH] DRAFT: Use reference Yoga CMake build (#1291) Summary: X-link: https://github.com/facebook/yoga/pull/1291 Pull Request resolved: https://github.com/facebook/react-native/pull/37371 **Draft:** This is a draft change that I cannot make a draft in Phabricator because I want to export it to GitHub. This makes React Native use `libyogacore` as provided by Yoga's reference CMake build. This in turn matches Yoga in the OSS RN build to the same compilation settings we use internally. It also means less differences between all the builds (maintainability win). Changelog: [Android][Changed] - Use reference Yoga CMake Build Differential Revision: D45764537 fbshipit-source-id: 6580a7f07120ceebf3c0623e86c1865461af72cc --- .../jni/first-party/yogajni/CMakeLists.txt | 17 +++++-------- .../first-party/yogajni/jni/CMakeLists.txt | 25 +++++++++++++++++++ .../ReactCommon/yoga/CMakeLists.txt | 18 ++++--------- 3 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/jni/CMakeLists.txt diff --git a/packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/CMakeLists.txt b/packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/CMakeLists.txt index 8f08a9977a7e09..e4a960629ce487 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/CMakeLists.txt +++ b/packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/CMakeLists.txt @@ -6,15 +6,10 @@ cmake_minimum_required(VERSION 3.13) set(CMAKE_VERBOSE_MAKEFILE on) -add_compile_options( - -fvisibility=hidden - -fexceptions - -frtti - -O3) +# Yoga by default does not enable optimizations in debug builds. Enable -O2 +# for all builds in RN for faster debug app performance (at the cost of not +# being able to debug inside Yoga) +set(CMAKE_BUILD_TYPE Release) -file(GLOB yoga_SRC CONFIGURE_DEPENDS jni/*.cpp) -add_library(yoga SHARED ${yoga_SRC}) - -target_include_directories(yoga PUBLIC jni) - -target_link_libraries(yoga yogacore fb fbjni log android) +set(YOGA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../ReactCommon/yoga) +add_subdirectory(jni) diff --git a/packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/jni/CMakeLists.txt b/packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/jni/CMakeLists.txt new file mode 100644 index 00000000000000..b006ad6baf0154 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/jni/first-party/yogajni/jni/CMakeLists.txt @@ -0,0 +1,25 @@ +# 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. + +cmake_minimum_required(VERSION 3.13) +project(yogajni) +set(CMAKE_VERBOSE_MAKEFILE on) + +if (NOT DEFINED YOGA_ROOT) + set(YOGA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) +endif() + +include(${YOGA_ROOT}/cmake/project-defaults.cmake) + +add_subdirectory(${YOGA_ROOT}/yoga ${CMAKE_CURRENT_BINARY_DIR}/yoga) + +file(GLOB SOURCES CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/jni/*.cpp) +file(GLOB VERSION_SCRIPT CONFIGURE_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/yogajni.version) + +add_library(yoga SHARED ${SOURCES}) +target_link_libraries(yoga yogacore) +target_link_options(yoga PRIVATE -Wl,--version-script=${VERSION_SCRIPT}) diff --git a/packages/react-native/ReactCommon/yoga/CMakeLists.txt b/packages/react-native/ReactCommon/yoga/CMakeLists.txt index ff370aa76ebd05..644c6cb1b132e0 100644 --- a/packages/react-native/ReactCommon/yoga/CMakeLists.txt +++ b/packages/react-native/ReactCommon/yoga/CMakeLists.txt @@ -6,17 +6,9 @@ cmake_minimum_required(VERSION 3.13) set(CMAKE_VERBOSE_MAKEFILE on) -add_compile_options( - -fexceptions - -frtti - -O3 - -Wall - -Wpedantic - -Wno-gnu-zero-variadic-macro-arguments) +# Yoga by default does not enable optimizations in debug builds. Enable -O2 +# for all builds in RN for faster debug app performance (at the cost of not +# being able to debug inside Yoga) +set(CMAKE_BUILD_TYPE Release) -file(GLOB_RECURSE yogacore_SRC CONFIGURE_DEPENDS yoga/*.cpp) -add_library(yogacore STATIC ${yogacore_SRC}) - -target_include_directories(yogacore PUBLIC .) - -target_link_libraries(yogacore android log) +add_subdirectory(yoga)