diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000000..cce5bff174 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,124 @@ +name: Build Binaries + +on: + - push + - pull_request + - workflow_dispatch + +defaults: + run: + shell: bash + +jobs: + build-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup + uses: ./.github/actions/setup-cpp + with: + toolchain: GCC + + - name: Setup JS + uses: ./.github/actions/setup-js + + - name: Restore emsdk + uses: ./.github/actions/cache-emsdk + + - name: Build + run: | + cmake -B build -S yoga -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -G Ninja + cmake --build build --config Release + mkdir -p dist/linux + cp build/libyogacore.so dist/linux/libyoga.so + + - name: Build JS + working-directory: javascript + run: | + yarn build + mkdir -p ../dist/webgl + cp build/libyogaObjLib.a ../dist/webgl/libyoga.a + + - name: Upload Binaries + uses: actions/upload-artifact@v4 + if: github.event_name == 'push' + with: + path: dist/** + name: prebuilt_yoga_binaries_linux + + build-macos: + runs-on: macos-13 + steps: + - uses: actions/checkout@v3 + + - name: Setup Apple + uses: ./.github/actions/setup-apple + + - name: Build + run: | + cmake -B build -S yoga -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" + cmake --build build --config Release + mkdir -p dist/osx + cp build/libyogacore.dylib dist/osx/libyoga.dylib + + - name: Build IOS + run: | + rm -rf build + cmake -B build -S yoga -D CMAKE_BUILD_TYPE=Release -G Xcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_Swift_COMPILER_FORCED=true -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 + cmake --build build --config Release + mkdir -p dist/iOS + cp build/Release-iphoneos/libyogacore.a dist/iOS/libyoga.a + + - name: Upload Binaries + uses: actions/upload-artifact@v4 + if: github.event_name == 'push' + with: + path: dist/** + name: prebuilt_yoga_binaries_macos + + build-windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup + uses: ./.github/actions/setup-cpp + with: + toolchain: MSVC + + - name: Build + run: | + cmake -B build -S yoga -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON + cmake -B build32 -S yoga -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -A Win32 + cmake --build build --config Release + cmake --build build32 --config Release + mkdir -p dist/win-x64 dist/win-x86 + cp build/Release/yogacore.dll dist/win-x64/yoga.dll + cp build32/Release/yogacore.dll dist/win-x86/yoga.dll + + - name: Upload Binaries + uses: actions/upload-artifact@v4 + if: github.event_name == 'push' + with: + path: dist/** + name: prebuilt_yoga_binaries_windows + + build-android: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/setup-android + + - name: Build + run: | + ./gradlew :yoga:assembleRelease + mkdir -p dist/android + cp java/build/outputs/aar/yoga-release.aar dist/android/yoga.aar + + - name: Upload Binaries + uses: actions/upload-artifact@v4 + if: github.event_name == 'push' + with: + path: dist/** + name: prebuilt_yoga_binaries_android diff --git a/.gitignore b/.gitignore index 7d75c154c7..e238466673 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ node_modules # Xcode ## Build generated build/ +build32/ DerivedData/ ## Various settings diff --git a/.vscode/settings.json b/.vscode/settings.json index 9339156445..ce4cacff77 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,10 +1,9 @@ { "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "eslint.format.enable": true, - "eslint.packageManager": "yarn", "eslint.enable": true, "eslint.validate": [ "javascript", diff --git a/cmake/project-defaults.cmake b/cmake/project-defaults.cmake index a6960bb629..8392ef61ae 100644 --- a/cmake/project-defaults.cmake +++ b/cmake/project-defaults.cmake @@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) add_compile_definitions($<$:DEBUG>) @@ -18,7 +19,6 @@ add_compile_options( /EHsc # Enable warnings and warnings as errors /W4 - /WX # Enable RTTI $<$:/GR> # Use /O2 (Maximize Speed) diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt index d8afd671c2..75c3ba4065 100644 --- a/java/CMakeLists.txt +++ b/java/CMakeLists.txt @@ -6,6 +6,7 @@ cmake_minimum_required(VERSION 3.13...3.26) project(yogajni) set(CMAKE_VERBOSE_MAKEFILE on) +set(BUILD_SHARED_LIBS on) set(YOGA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) include(${YOGA_ROOT}/cmake/project-defaults.cmake) diff --git a/javascript/CMakeLists.txt b/javascript/CMakeLists.txt index b1a1278fcd..5b11c1ef79 100644 --- a/javascript/CMakeLists.txt +++ b/javascript/CMakeLists.txt @@ -3,6 +3,8 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. +option(BUILD_STATIC_LIBS "Build static library (.a) instead of object library" OFF) + cmake_minimum_required(VERSION 3.13...3.26) set(CMAKE_VERBOSE_MAKEFILE on) project(yoga) @@ -24,8 +26,7 @@ set(COMPILE_OPTIONS -fno-exceptions -fno-rtti -g0 - -Os - "SHELL:-s STRICT=1") + -Os) add_compile_options(${COMPILE_OPTIONS}) @@ -52,7 +53,11 @@ add_link_options( link_libraries(embind) -add_library(yogaObjLib OBJECT ${SOURCES}) +if(BUILD_STATIC_LIBS) + add_library(yogaObjLib STATIC ${SOURCES}) +else() + add_library(yogaObjLib OBJECT ${SOURCES}) +endif() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/binaries) diff --git a/javascript/just.config.cjs b/javascript/just.config.cjs index 520060c7d7..21d2e61b56 100644 --- a/javascript/just.config.cjs +++ b/javascript/just.config.cjs @@ -213,6 +213,7 @@ function emcmakeGenerateTask() { '-B', 'build', ...(process.platform === 'win32' ? [] : ['-G', 'Ninja']), + '-D BUILD_STATIC_LIBS=ON', ]; logger.info(['emcmake', ...args].join(' ')); diff --git a/yoga/CMakeLists.txt b/yoga/CMakeLists.txt index b6eca1ac72..52f9ee811a 100644 --- a/yoga/CMakeLists.txt +++ b/yoga/CMakeLists.txt @@ -3,6 +3,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. +option(BUILD_SHARED_LIBS "Build shared libraries (DLLs) instead of static libraries" OFF) cmake_minimum_required(VERSION 3.13...3.26) project(yogacore) @@ -22,7 +23,15 @@ file(GLOB SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/**/*.cpp) -add_library(yogacore STATIC ${SOURCES}) +if(BUILD_SHARED_LIBS) + if(WIN32) + add_library(yogacore MODULE ${SOURCES}) + else() + add_library(yogacore SHARED ${SOURCES}) + endif() +else() + add_library(yogacore STATIC ${SOURCES}) +endif() # Yoga conditionally uses when building for Android if (ANDROID) diff --git a/yoga/config/Config.h b/yoga/config/Config.h index 7bcffd1484..bb646736bc 100644 --- a/yoga/config/Config.h +++ b/yoga/config/Config.h @@ -22,7 +22,8 @@ namespace facebook::yoga { class Config; class Node; -using ExperimentalFeatureSet = std::bitset()>; +constexpr size_t ExperimentalFeatureCount = 1; +using ExperimentalFeatureSet = std::bitset; // Whether moving a node from an old to new config should dirty previously // calculated layout results. @@ -76,6 +77,7 @@ class YG_EXPORT Config : public ::YGConfig { uint32_t version_ = 0; ExperimentalFeatureSet experimentalFeatures_{}; + Errata errata_ = Errata::None; float pointScaleFactor_ = 1.0f; void* context_ = nullptr;