From a1441bba0ac04509b3d4ebb4e1406f591d40fb75 Mon Sep 17 00:00:00 2001 From: luigi-rosso Date: Thu, 15 May 2025 18:21:04 +0000 Subject: [PATCH] chore: fix clang-17 compiler (#9666) 8a1f3286b9 * chore: fix clang-17 compiler * chore: adding missing file * fix: rive_native builds * chore: remove no runtime linking on linux * chore: more fixes * chore: removing rive_common * chore: use build_rive.sh for ios * chore: use rive_build.sh for recorder * chore: fix fill missing version * chore: add rive_build.sh to path * chore: add rive_build.sh to pr_ios_tests.yaml * chore: add rive_build to the recorder tests * chore: drop rive_flutter tests * chore: fixing ios tests * fix misspelled * chore: cleanup * chore: use latest zlib * chore: premake5.lua redirects to premake5_v2 * fix: tvos and ios builds * fix: unreal build path for miniaudio Co-authored-by: Luigi Rosso --- .rive_head | 2 +- build.sh | 4 +- build/build_rive.sh | 18 ++ build/premake5.lua | 286 +----------------- build/rive_build_config.lua | 6 +- dependencies/miniaudio.m | 1 + dependencies/premake5_libpng_v2.lua | 6 +- dependencies/premake5_miniaudio_v2.lua | 17 +- include/rive/math/contour_measure.hpp | 2 +- premake5_v2.lua | 65 ---- src/animation/animation_reset_factory.cpp | 7 +- src/animation/linear_animation.cpp | 4 +- src/animation/linear_animation_instance.cpp | 17 +- src/animation/state_machine_instance.cpp | 5 +- src/animation/state_transition.cpp | 8 +- src/audio/audio_engine.cpp | 12 - src/audio/audio_engine.m | 4 - .../scrolling/scroll_constraint.cpp | 8 +- src/constraints/scrolling/scroll_physics.cpp | 2 +- src/math/contour_measure.cpp | 4 +- src/math/n_slicer_helpers.cpp | 2 +- src/shapes/image.cpp | 24 +- src/text/cursor.cpp | 6 +- tests/include/rive_testing.hpp | 4 + .../ios_tests.xcodeproj/project.pbxproj | 2 + tests/rive_tools_project.lua | 24 +- tests/unit_tests/premake5.lua | 3 +- .../runtime/raw_text_input_test.cpp | 12 +- tests/unit_tests/test.sh | 14 +- viewer/build/premake5_viewer.lua | 2 +- 30 files changed, 131 insertions(+), 440 deletions(-) create mode 100644 dependencies/miniaudio.m delete mode 100644 src/audio/audio_engine.m diff --git a/.rive_head b/.rive_head index f45f416b..cbcd8527 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -c0844f01b5cfea4b9d9e97ba9a8082c1081ac64f +8a1f3286b9fb09b1921d290bf29907c841516c38 diff --git a/build.sh b/build.sh index 080e8bec..0c816825 100755 --- a/build.sh +++ b/build.sh @@ -32,8 +32,8 @@ if [ "$OPTION" = 'help' ]; then else build() { echo "Building Rive for platform=$platform option=$OPTION" - echo premake5 gmake2 --with_rive_text --with_rive_audio=system --with_rive_layout "$1" - PREMAKE="premake5 gmake2 --with_rive_text --with_rive_audio=system --with_rive_layout $1" + echo premake5 --file=premake5_v2.lua gmake2 --with_rive_text --with_rive_audio=system --with_rive_layout "$1" + PREMAKE="premake5 --file=premake5_v2.lua gmake2 --with_rive_text --with_rive_audio=system --with_rive_layout $1" eval "$PREMAKE" if [ "$OPTION" = "clean" ]; then make clean diff --git a/build/build_rive.sh b/build/build_rive.sh index 43238bee..09af01a3 100755 --- a/build/build_rive.sh +++ b/build/build_rive.sh @@ -126,6 +126,24 @@ else while [[ $# -gt 0 ]]; do case "$1" in "release") RIVE_CONFIG="${RIVE_CONFIG:-release}" ;; + "xros") + RIVE_OS="${RIVE_OS:-ios}" + RIVE_VARIANT="${RIVE_VARIANT:-xros}" + ;; + "xrsimulator") + RIVE_OS=${RIVE_OS:-ios} + RIVE_VARIANT="${RIVE_VARIANT:-xrsimulator}" + RIVE_ARCH="${RIVE_ARCH:-universal}" # The simulator requires universal builds. + ;; + "appletvos") + RIVE_OS="${RIVE_OS:-ios}" + RIVE_VARIANT="${RIVE_VARIANT:-appletvos}" + ;; + "appletvsimulator") + RIVE_OS=${RIVE_OS:-ios} + RIVE_VARIANT="${RIVE_VARIANT:-appletvsimulator}" + RIVE_ARCH="${RIVE_ARCH:-universal}" # The simulator requires universal builds. + ;; "ios") RIVE_OS="${RIVE_OS:-ios}" ;; "iossim") RIVE_OS=${RIVE_OS:-ios} diff --git a/build/premake5.lua b/build/premake5.lua index 3599d41a..23c1e630 100644 --- a/build/premake5.lua +++ b/build/premake5.lua @@ -1,285 +1 @@ -workspace('rive') -configurations({ 'debug', 'release' }) - -require('setup_compiler') - -filter({ 'options:with_rive_tools' }) -do - defines({ 'WITH_RIVE_TOOLS' }) -end -filter({ 'options:with_rive_text' }) -do - defines({ 'WITH_RIVE_TEXT' }) -end -filter({ 'options:with_rive_audio=system' }) -do - defines({ 'WITH_RIVE_AUDIO', 'MA_NO_RESOURCE_MANAGER' }) -end - -filter({ 'options:with_rive_audio=external' }) -do - defines({ - 'WITH_RIVE_AUDIO', - 'EXTERNAL_RIVE_AUDIO_ENGINE', - 'MA_NO_DEVICE_IO', - 'MA_NO_RESOURCE_MANAGER', - }) -end -filter({ 'options:with_rive_layout' }) -do - defines({ 'WITH_RIVE_LAYOUT' }) -end -filter({}) - -dofile(path.join(path.getabsolute('../dependencies/'), 'premake5_harfbuzz.lua')) -dofile(path.join(path.getabsolute('../dependencies/'), 'premake5_sheenbidi.lua')) -dofile(path.join(path.getabsolute('../dependencies/'), 'premake5_miniaudio.lua')) -dofile(path.join(path.getabsolute('../dependencies/'), 'premake5_yoga.lua')) - -project('rive') -do - kind('StaticLib') - language('C++') - targetdir('%{cfg.system}/bin/%{cfg.buildcfg}') - objdir('%{cfg.system}/obj/%{cfg.buildcfg}') - includedirs({ - '../include', - harfbuzz .. '/src', - sheenbidi .. '/Headers', - miniaudio, - yoga, - }) - - defines({ 'YOGA_EXPORT=', '_RIVE_INTERNAL_' }) - - includedirs({ - '../dependencies/', - }) - forceincludes({ 'rive_yoga_renames.h' }) - - files({ '../src/**.cpp' }) - - flags({ 'FatalCompileWarnings' }) - - filter({ 'options:for_unreal' }) - do - cppdialect('C++17') - defines({ '_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR' }) - end - - filter({ 'options:not for_unreal' }) - do - cppdialect('C++11') - end - - filter({ 'system:macosx' }) - do - buildoptions({ - -- this triggers too much on linux, so just enable here for now - '-Wimplicit-float-conversion', - }) - end - - -- filter {'toolset:not msc', 'files:../src/audio/audio_engine.cpp'} - filter({ 'system:not windows', 'files:../src/audio/audio_engine.cpp' }) - do - buildoptions({ '-Wno-implicit-int-conversion' }) - end - - filter({ 'system:windows', 'files:../src/audio/audio_engine.cpp' }) - do - -- Too many warnings from miniaudio.h - removeflags({ 'FatalCompileWarnings' }) - end - - -- filter 'files:../src/audio/audio_engine.cpp' - -- do - -- buildoptions { - -- '-Wno-implicit-int-conversion' - -- } - -- end - - filter({ 'system:macosx', 'options:variant=runtime' }) - do - buildoptions({ - '-Wimplicit-float-conversion -fembed-bitcode -arch arm64 -arch x86_64 -isysroot ' - .. (os.getenv('MACOS_SYSROOT') or ''), - }) - end - - filter({ 'system:macosx', 'configurations:release' }) - do - buildoptions({ '-flto=full' }) - end - - filter({ 'system:ios' }) - do - buildoptions({ '-flto=full', '-Wno-implicit-int-conversion' }) - files({ '../src/audio/audio_engine.m' }) - end - - filter('system:windows') - do - architecture('x64') - defines({ '_USE_MATH_DEFINES' }) - end - - filter({ 'system:ios', 'options:variant=system' }) - do - buildoptions({ - '-mios-version-min=13.0 -fembed-bitcode -arch arm64 -isysroot ' - .. (os.getenv('IOS_SYSROOT') or ''), - }) - end - - filter({ 'system:ios', 'options:variant=emulator' }) - do - buildoptions({ - '--target=arm64-apple-ios13.0.0-simulator', - '-mios-version-min=13.0 -arch arm64 -arch x86_64 -isysroot ' - .. (os.getenv('IOS_SYSROOT') or ''), - }) - targetdir('%{cfg.system}_sim/bin/%{cfg.buildcfg}') - objdir('%{cfg.system}_sim/obj/%{cfg.buildcfg}') - end - - filter({ 'system:ios', 'options:variant=xros' }) - do - buildoptions({ - '--target=arm64-apple-xros1.0', - '-fembed-bitcode -arch arm64 -isysroot ' - .. (os.getenv('XROS_SYSROOT') or ''), - }) - targetdir('xros/bin/%{cfg.buildcfg}') - objdir('xros/obj/%{cfg.buildcfg}') - end - - filter({ 'system:ios', 'options:variant=xrsimulator' }) - do - buildoptions({ - '--target=arm64-apple-xros1.0-simulator', - '-arch arm64 -arch x86_64 -isysroot ' - .. (os.getenv('XROS_SYSROOT') or ''), - }) - targetdir('xrsimulator/bin/%{cfg.buildcfg}') - objdir('xrsimulator/obj/%{cfg.buildcfg}') - end - - filter({ 'system:ios', 'options:variant=appletvos' }) - do - buildoptions({ - '--target=arm64-apple-tvos', - '-mappletvos-version-min=16.0', - '-fembed-bitcode -arch arm64 -isysroot ' - .. (os.getenv('APPLETVOS_SYSROOT') or ''), - }) - targetdir('appletvos/bin/%{cfg.buildcfg}') - objdir('appletvos/obj/%{cfg.buildcfg}') - end - - filter({ 'system:ios', 'options:variant=appletvsimulator' }) - do - buildoptions({ - '--target=arm64-apple-tvos-simulator', - '-mappletvsimulator-version-min=16.0', - '-arch arm64 -arch x86_64 -isysroot ' - .. (os.getenv('APPLETVOS_SYSROOT') or ''), - }) - targetdir('appletvsimulator/bin/%{cfg.buildcfg}') - objdir('appletvsimulator/obj/%{cfg.buildcfg}') - end - - filter('system:macosx or system:ios') - do - files({ '../src/text/font_hb_apple.mm' }) - end - - filter({ 'system:android', 'configurations:release' }) - do - buildoptions({ '-flto=full' }) - end - - -- Is there a way to pass 'arch' as a variable here? - filter({ 'system:android', 'options:arch=x86' }) - do - targetdir('%{cfg.system}/x86/bin/%{cfg.buildcfg}') - objdir('%{cfg.system}/x86/obj/%{cfg.buildcfg}') - -- Ignore fatal warning for miniaudio on x86 devices. - filter({ 'files:../src/audio/audio_engine.cpp' }) - do - buildoptions({ '-Wno-atomic-alignment' }) - end - end - - filter({ 'system:android', 'options:arch=x64' }) - do - targetdir('%{cfg.system}/x64/bin/%{cfg.buildcfg}') - objdir('%{cfg.system}/x64/obj/%{cfg.buildcfg}') - end - - filter({ 'system:android', 'options:arch=arm' }) - do - targetdir('%{cfg.system}/arm/bin/%{cfg.buildcfg}') - objdir('%{cfg.system}/arm/obj/%{cfg.buildcfg}') - end - - filter({ 'system:android', 'options:arch=arm64' }) - do - targetdir('%{cfg.system}/arm64/bin/%{cfg.buildcfg}') - objdir('%{cfg.system}/arm64/obj/%{cfg.buildcfg}') - end - - filter('configurations:debug') - do - defines({ 'DEBUG' }) - symbols('On') - end - - filter('configurations:release') - do - defines({ 'RELEASE' }) - defines({ 'NDEBUG' }) - optimize('On') - end -end - -newoption({ - trigger = 'variant', - value = 'type', - description = 'Choose a particular variant to build', - allowed = { - { 'system', 'Builds the static library for the provided system' }, - { 'emulator', 'Builds for an emulator/simulator for the provided system' }, - { - 'runtime', - 'Build the static library specifically targeting our runtimes', - }, - { 'xros', 'Builds for Apple Vision Pro' }, - { 'xrsimulator', 'Builds for Apple Vision Pro simulator' }, - { 'appletvos', 'Builds for Apple TV' }, - { 'appletvsimulator', 'Builds for Apple TV simulator' }, - }, - default = 'system', -}) - -newoption({ - trigger = 'with_rive_tools', - description = 'Enables tools usually not necessary for runtime.', -}) - -newoption({ - trigger = 'with_rive_text', - description = 'Compiles in text features.', -}) - -newoption({ - trigger = 'with_rive_audio', - value = 'disabled', - description = 'The audio mode to use.', - allowed = { { 'disabled' }, { 'system' }, { 'external' } }, -}) - -newoption({ - trigger = 'with_rive_layout', - description = 'Compiles in layout features.', -}) +require('premake5_v2.lua') diff --git a/build/rive_build_config.lua b/build/rive_build_config.lua index 3393c2c4..e468cabd 100644 --- a/build/rive_build_config.lua +++ b/build/rive_build_config.lua @@ -421,16 +421,16 @@ if _OPTIONS['os'] == 'android' then end -- Windows requires extentions for .cmd files. - local ndk_ext = ''; + local ndk_ext = '' if os.host() == 'windows' then - ndk_ext = '.cmd'; + ndk_ext = '.cmd' end -- update the android_ndk toolset to use the appropriate binaries. local android_ndk_tools = { cc = ndk_toolchain .. '/bin/' .. android_target .. '-clang' .. ndk_ext, cxx = ndk_toolchain .. '/bin/' .. android_target .. '-clang++' .. ndk_ext, - ar = ndk_toolchain .. '/bin/llvm-ar' + ar = ndk_toolchain .. '/bin/llvm-ar', } function premake.tools.android_ndk.gettoolname(cfg, tool) return android_ndk_tools[tool] diff --git a/dependencies/miniaudio.m b/dependencies/miniaudio.m new file mode 100644 index 00000000..e1f3216a --- /dev/null +++ b/dependencies/miniaudio.m @@ -0,0 +1 @@ +#include "miniaudio.c" diff --git a/dependencies/premake5_libpng_v2.lua b/dependencies/premake5_libpng_v2.lua index 96424abb..712eb015 100644 --- a/dependencies/premake5_libpng_v2.lua +++ b/dependencies/premake5_libpng_v2.lua @@ -2,7 +2,7 @@ dofile('rive_build_config.lua') local dependency = require('dependency') libpng = dependency.github('glennrp/libpng', 'libpng16') -zlib = dependency.github('madler/zlib', '04f42ceca40f73e2978b50e93806c2a18c1281fc') +zlib = dependency.github('madler/zlib', 'v1.3.1') includedirs({ './' }) forceincludes({ 'rive_png_renames.h' }) @@ -50,7 +50,7 @@ end newoption({ trigger = 'force_no_unistd_h', - description = "prevent HAVE_UNISTD_H from being defined for zlib" + description = 'prevent HAVE_UNISTD_H from being defined for zlib', }) project('zlib') @@ -88,7 +88,7 @@ do }) end - filter({'system:not windows', 'options:not force_no_unistd_h'}) + filter({ 'system:not windows', 'options:not force_no_unistd_h' }) do defines({ 'HAVE_UNISTD_H' }) end diff --git a/dependencies/premake5_miniaudio_v2.lua b/dependencies/premake5_miniaudio_v2.lua index c2098b4f..04781b77 100644 --- a/dependencies/premake5_miniaudio_v2.lua +++ b/dependencies/premake5_miniaudio_v2.lua @@ -1,3 +1,18 @@ dofile('rive_build_config.lua') local dependency = require('dependency') -miniaudio = dependency.github('rive-app/miniaudio', 'rive_changes_4') +miniaudio = dependency.github('rive-app/miniaudio', 'rive_changes_5') + +project('miniaudio') +do + kind('StaticLib') + includedirs({ miniaudio }) + + filter('system:ios') + do + files({ 'miniaudio.m' }) + end + filter('system:not ios') + do + files({ miniaudio .. '/miniaudio.c' }) + end +end diff --git a/include/rive/math/contour_measure.hpp b/include/rive/math/contour_measure.hpp index fca2e43c..04356927 100644 --- a/include/rive/math/contour_measure.hpp +++ b/include/rive/math/contour_measure.hpp @@ -27,7 +27,7 @@ public: unsigned m_tValue : 30; // Dot30 t value for the end of this segment unsigned m_type : 2; // [private enum] - float getT() const { return m_tValue * kInvScaleD30; } + float getT() const { return (float)m_tValue * kInvScaleD30; } bool operator<(const Segment& other) const { diff --git a/premake5_v2.lua b/premake5_v2.lua index efe1944e..df93c8c6 100644 --- a/premake5_v2.lua +++ b/premake5_v2.lua @@ -85,65 +85,6 @@ do forceincludes({ 'rive_yoga_renames.h' }) end - filter({ 'system:linux' }) - do - defines({ 'MA_NO_RUNTIME_LINKING' }) - end - - filter({ 'system:macosx' }) - do - buildoptions({ - -- this triggers too much on linux, so just enable here for now - '-Wimplicit-float-conversion', - }) - end - - -- filter {'toolset:not msc', 'files:src/audio/audio_engine.cpp'} - filter({ 'system:not windows', 'files:src/audio/audio_engine.cpp' }) - do - buildoptions({ '-Wno-implicit-int-conversion' }) - end - - filter({ 'system:windows', 'files:src/audio/audio_engine.cpp' }) - do - -- Too many warnings from miniaudio.h - removeflags({ 'FatalCompileWarnings' }) - end - - filter({ 'system:windows', 'toolset:clang', 'files:src/audio/audio_engine.cpp' }) - do - buildoptions({ - '-Wno-nonportable-system-include-path', - '-Wno-zero-as-null-pointer-constant', - '-Wno-missing-prototypes', - '-Wno-cast-qual', - '-Wno-format-nonliteral', - '-Wno-cast-align', - '-Wno-covered-switch-default', - '-Wno-comma', - '-Wno-tautological-type-limit-compare', - '-Wno-extra-semi-stmt', - '-Wno-tautological-constant-out-of-range-compare', - '-Wno-implicit-fallthrough', - '-Wno-implicit-int-conversion', - '-Wno-undef', - '-Wno-unused-function', - }) - end - - -- filter 'files:src/audio/audio_engine.cpp' - -- do - -- buildoptions { - -- '-Wno-implicit-int-conversion' - -- } - -- end - - -- Ignore fatal warning for miniaudio on x86 android build. - filter({ 'system:android', 'options:arch=x86', 'files:src/audio/audio_engine.cpp' }) - do - buildoptions({ '-Wno-atomic-alignment' }) - end - filter({ 'system:macosx', 'options:variant=runtime' }) do buildoptions({ @@ -152,12 +93,6 @@ do }) end - filter('system:ios') - do - buildoptions({ '-flto=full', '-Wno-implicit-int-conversion' }) - files({ 'src/audio/audio_engine.m' }) - end - filter('system:windows') do architecture('x64') diff --git a/src/animation/animation_reset_factory.cpp b/src/animation/animation_reset_factory.cpp index 9b4221f7..ace9919f 100644 --- a/src/animation/animation_reset_factory.cpp +++ b/src/animation/animation_reset_factory.cpp @@ -153,14 +153,15 @@ public: auto value = keyedProperty->first() ->as() ->value(); - animationReset->writePropertyValue(value); + animationReset->writePropertyValue( + (float)value); } } else { animationReset->writePropertyValue( - CoreRegistry::getColor(component, - propertyKey)); + (float)CoreRegistry::getColor(component, + propertyKey)); } break; } diff --git a/src/animation/linear_animation.cpp b/src/animation/linear_animation.cpp index 6ad28ecd..fce55584 100644 --- a/src/animation/linear_animation.cpp +++ b/src/animation/linear_animation.cpp @@ -79,11 +79,11 @@ StatusCode LinearAnimation::import(ImportStack& importStack) float LinearAnimation::startSeconds() const { - return (enableWorkArea() ? workStart() : 0) / (float)fps(); + return (enableWorkArea() ? (float)workStart() : 0.0f) / (float)fps(); } float LinearAnimation::endSeconds() const { - return (enableWorkArea() ? workEnd() : duration()) / (float)fps(); + return (float)(enableWorkArea() ? workEnd() : duration()) / (float)fps(); } float LinearAnimation::startTime() const diff --git a/src/animation/linear_animation_instance.cpp b/src/animation/linear_animation_instance.cpp index e0d91b08..f7887ba6 100644 --- a/src/animation/linear_animation_instance.cpp +++ b/src/animation/linear_animation_instance.cpp @@ -81,12 +81,13 @@ bool LinearAnimationInstance::advance(float elapsedSeconds, false); } - int fps = animation.fps(); + float fps = (float)animation.fps(); float frames = m_time * fps; - int start = animation.enableWorkArea() ? animation.workStart() : 0; - int end = - animation.enableWorkArea() ? animation.workEnd() : animation.duration(); - int range = end - start; + float start = + animation.enableWorkArea() ? (float)animation.workStart() : 0.0f; + float end = animation.enableWorkArea() ? (float)animation.workEnd() + : (float)animation.duration(); + float range = end - start; bool didLoop = false; @@ -232,8 +233,10 @@ void LinearAnimationInstance::time(float value) // can track change even when setting time. auto diff = m_totalTime - m_lastTotalTime; - int start = (m_animation->enableWorkArea() ? m_animation->workStart() : 0) * - m_animation->fps(); + float start = + (m_animation->enableWorkArea() ? (float)m_animation->workStart() + : 0.0f) * + (float)m_animation->fps(); m_totalTime = value - start; m_lastTotalTime = m_totalTime - diff; diff --git a/src/animation/state_machine_instance.cpp b/src/animation/state_machine_instance.cpp index 4ef3f087..21f3f0cc 100644 --- a/src/animation/state_machine_instance.cpp +++ b/src/animation/state_machine_instance.cpp @@ -247,13 +247,14 @@ public: if (totalWeight > 0) { double randomWeight = randomValue() * totalWeight * 1.0; - float currentWeight = 0; + double currentWeight = 0; size_t index = 0; StateTransition* transition; while (index < stateFrom->transitionCount()) { transition = stateFrom->transition(index); - auto transitionWeight = transition->evaluatedRandomWeight(); + double transitionWeight = + (double)transition->evaluatedRandomWeight(); if (currentWeight + transitionWeight > randomWeight) { transition->useLayerInConditions(m_stateMachineInstance, diff --git a/src/animation/state_transition.cpp b/src/animation/state_transition.cpp index 26ec9186..bdcdf0a2 100644 --- a/src/animation/state_transition.cpp +++ b/src/animation/state_transition.cpp @@ -97,11 +97,11 @@ float StateTransition::mixTime(const LayerState* stateFrom) const animationDuration = animation->durationSeconds(); } } - return duration() / 100.0f * animationDuration; + return (float)duration() / 100.0f * animationDuration; } else { - return duration() / 1000.0f; + return (float)duration() / 1000.0f; } } @@ -122,9 +122,9 @@ float StateTransition::exitTimeSeconds(const LayerState* stateFrom, animationDuration = exitAnimation->durationSeconds(); } - return start + exitTime() / 100.0f * animationDuration; + return start + (float)exitTime() / 100.0f * animationDuration; } - return exitTime() / 1000.0f; + return (float)exitTime() / 1000.0f; } const LinearAnimationInstance* StateTransition::exitTimeAnimationInstance( diff --git a/src/audio/audio_engine.cpp b/src/audio/audio_engine.cpp index eef97b6d..b18e6b45 100644 --- a/src/audio/audio_engine.cpp +++ b/src/audio/audio_engine.cpp @@ -1,17 +1,5 @@ #ifdef WITH_RIVE_AUDIO #include "rive/math/simd.hpp" -#ifdef __APPLE__ -#include -#if TARGET_IPHONE_SIMULATOR || TARGET_OS_MACCATALYST || TARGET_OS_IPHONE -// Don't define MINIAUDIO_IMPLEMENTATION ON iOS -#elif TARGET_OS_MAC -#define MINIAUDIO_IMPLEMENTATION -#else -#error "Unknown Apple platform" -#endif -#else -#define MINIAUDIO_IMPLEMENTATION -#endif #include "miniaudio.h" #include "rive/audio/audio_engine.hpp" diff --git a/src/audio/audio_engine.m b/src/audio/audio_engine.m deleted file mode 100644 index f272bea4..00000000 --- a/src/audio/audio_engine.m +++ /dev/null @@ -1,4 +0,0 @@ -#ifdef WITH_RIVE_AUDIO -#define MINIAUDIO_IMPLEMENTATION -#include "miniaudio.h" -#endif \ No newline at end of file diff --git a/src/constraints/scrolling/scroll_constraint.cpp b/src/constraints/scrolling/scroll_constraint.cpp index 58f40d3d..bda9221a 100644 --- a/src/constraints/scrolling/scroll_constraint.cpp +++ b/src/constraints/scrolling/scroll_constraint.cpp @@ -234,17 +234,17 @@ Vec2D ScrollConstraint::positionAtIndex(float index) { return Vec2D(); } - auto i = 0; + uint32_t i = 0; LayoutNodeProvider* lastChild; for (auto child : content()->children()) { auto c = LayoutNodeProvider::from(child); if (c != nullptr) { - auto floorIndex = std::floor(index); - if (i == floorIndex) + float floorIndex = std::floor(index); + if (i == (uint32_t)floorIndex) { - auto mod = index - floorIndex; + float mod = index - floorIndex; auto bounds = c->layoutBounds(); return Vec2D(-bounds.left() - bounds.width() * mod, -bounds.top() - bounds.height() * mod); diff --git a/src/constraints/scrolling/scroll_physics.cpp b/src/constraints/scrolling/scroll_physics.cpp index 8df42e23..74740e02 100644 --- a/src/constraints/scrolling/scroll_physics.cpp +++ b/src/constraints/scrolling/scroll_physics.cpp @@ -11,7 +11,7 @@ void ScrollPhysics::accumulate(Vec2D delta) auto ms = std::chrono::duration_cast( now.time_since_epoch()) .count(); - float elapsedSeconds = (ms - m_lastTime) / 1000000.0f; + float elapsedSeconds = (float)(ms - m_lastTime) / 1000000.0f; if (elapsedSeconds > 0) { auto lastSpeed = m_speed; diff --git a/src/math/contour_measure.cpp b/src/math/contour_measure.cpp index bf6bdb05..5fd28179 100644 --- a/src/math/contour_measure.cpp +++ b/src/math/contour_measure.cpp @@ -342,7 +342,7 @@ float ContourMeasureIter::addQuadSegs(ContourMeasure::Segment* segs, uint32_t ptIndex, float distance) const { - const float dt = 1.f / segmentCount; + const float dt = 1.f / (float)segmentCount; const EvalQuad eval(pts); float t = dt; @@ -366,7 +366,7 @@ float ContourMeasureIter::addCubicSegs(ContourMeasure::Segment* segs, uint32_t ptIndex, float distance) const { - const float dt = 1.f / segmentCount; + const float dt = 1.f / (float)segmentCount; const EvalCubic eval(pts); float t = dt; diff --git a/src/math/n_slicer_helpers.cpp b/src/math/n_slicer_helpers.cpp index a5aa7db5..f7dc71c0 100644 --- a/src/math/n_slicer_helpers.cpp +++ b/src/math/n_slicer_helpers.cpp @@ -92,7 +92,7 @@ ScaleInfo NSlicerHelpers::analyzeUVStops(const std::vector& uvs, float fallbackSize = 0; if (!useScale && numEmptyPatch != 0) { - fallbackSize = (size - fixedSize / scale) / numEmptyPatch; + fallbackSize = (size - fixedSize / scale) / (float)numEmptyPatch; } return {useScale, scaleFactor, fallbackSize}; diff --git a/src/shapes/image.cpp b/src/shapes/image.cpp index ccb87e8b..49e51fe3 100644 --- a/src/shapes/image.cpp +++ b/src/shapes/image.cpp @@ -36,8 +36,8 @@ void Image::draw(Renderer* renderer) if (clipResult != ClipResult::emptyClip) { - auto width = renderImage->width(); - auto height = renderImage->height(); + float width = (float)renderImage->width(); + float height = (float)renderImage->height(); if (m_Mesh != nullptr) { @@ -59,8 +59,8 @@ Core* Image::hitTest(HitInfo* hinfo, const Mat2D& xform) // TODO: handle clip? auto renderImage = imageAsset()->renderImage(); - int width = renderImage->width(); - int height = renderImage->height(); + float width = (float)renderImage->width(); + float height = (float)renderImage->height(); if (m_Mesh) { @@ -143,7 +143,7 @@ float Image::width() const { return 0.0f; } - return renderImage->width(); + return (float)renderImage->width(); } float Image::height() const @@ -159,7 +159,7 @@ float Image::height() const { return 0.0f; } - return renderImage->height(); + return (float)renderImage->height(); } Vec2D Image::measureLayout(float width, @@ -214,15 +214,17 @@ void Image::controlSize(Vec2D size, void Image::updateImageScale() { // User-created meshes are not affected by scale - if (m_Mesh != nullptr && m_Mesh->type() == MeshType::vertex) + if ((m_Mesh != nullptr && m_Mesh->type() == MeshType::vertex) || + imageAsset() == nullptr) { return; } - if (imageAsset() != nullptr && imageAsset()->renderImage() != nullptr && - !std::isnan(m_layoutWidth) && !std::isnan(m_layoutHeight)) + auto renderImage = imageAsset()->renderImage(); + if (renderImage != nullptr && !std::isnan(m_layoutWidth) && + !std::isnan(m_layoutHeight)) { - auto newScaleX = m_layoutWidth / imageAsset()->renderImage()->width(); - auto newScaleY = m_layoutHeight / imageAsset()->renderImage()->height(); + float newScaleX = m_layoutWidth / (float)renderImage->width(); + float newScaleY = m_layoutHeight / (float)renderImage->height(); if (newScaleX != scaleX() || newScaleY != scaleY()) { scaleX(newScaleX); diff --git a/src/text/cursor.cpp b/src/text/cursor.cpp index a8683f94..59f1f4cc 100644 --- a/src/text/cursor.cpp +++ b/src/text/cursor.cpp @@ -134,7 +134,7 @@ CursorPosition CursorPosition::fromOrderedLine(const OrderedLine& orderedLine, nextTextIndex++; } uint32_t parts = nextTextIndex - textIndex; - uint32_t part = (uint32_t)std::round(ratio * parts); + uint32_t part = (uint32_t)std::round(ratio * (float)parts); return CursorPosition( lineIndex, @@ -285,8 +285,8 @@ void Cursor::selectionRects(std::vector& rects, subtractUint32(firstCodePointIndex, codePointIndex); uint32_t before = subtractUint32(endCodePointIndex, lastCodePointIndex); - float startFactor = after / (float)count; - float endFactor = (count - before) / (float)count; + float startFactor = (float)after / (float)count; + float endFactor = (float)(count - before) / (float)count; if (run->dir() == TextDirection::rtl) { startFactor = 1.0f - startFactor; diff --git a/tests/include/rive_testing.hpp b/tests/include/rive_testing.hpp index 99c3847c..168fd877 100644 --- a/tests/include/rive_testing.hpp +++ b/tests/include/rive_testing.hpp @@ -13,6 +13,10 @@ bool aboutEqual(const rive::Mat2D& a, const rive::Mat2D& b); CHECK(a.x == b.x); \ CHECK(a.y == b.y); +#define CHECK_AABB(a, b) \ + CHECK_VEC2D(a.min(), b.min()); \ + CHECK_VEC2D(a.max(), b.max()); + namespace Catch { template <> struct StringMaker diff --git a/tests/ios_tests/ios_tests.xcodeproj/project.pbxproj b/tests/ios_tests/ios_tests.xcodeproj/project.pbxproj index dd434e91..b2142723 100644 --- a/tests/ios_tests/ios_tests.xcodeproj/project.pbxproj +++ b/tests/ios_tests/ios_tests.xcodeproj/project.pbxproj @@ -324,6 +324,7 @@ "-ltools_common", "-lgoldens", "-lgms", + '-lminiaudio', ); "OTHER_LDFLAGS[sdk=iphonesimulator*]" = ( "-lrive", @@ -337,6 +338,7 @@ "-ltools_common", "-lgoldens", "-lgms", + '-lminiaudio', ); PRODUCT_BUNDLE_IDENTIFIER = "rive.app.golden-test-app"; PRODUCT_NAME = rive_ios_tests; diff --git a/tests/rive_tools_project.lua b/tests/rive_tools_project.lua index a496570e..218b2749 100644 --- a/tests/rive_tools_project.lua +++ b/tests/rive_tools_project.lua @@ -38,6 +38,7 @@ function rive_tools_project(name, project_kind) 'rive_yoga', 'rive_harfbuzz', 'rive_sheenbidi', + 'miniaudio', }) else kind(project_kind) @@ -120,7 +121,7 @@ function rive_tools_project(name, project_kind) end -- Match PLS math options for testing simd. - filter({'system:not windows', 'options:not no_ffp_contract'}) + filter({ 'system:not windows', 'options:not no_ffp_contract' }) do buildoptions({ '-ffp-contract=on', @@ -169,6 +170,7 @@ function rive_tools_project(name, project_kind) 'rive_yoga', 'rive_harfbuzz', 'rive_sheenbidi', + 'miniaudio', }) filter({ 'kind:ConsoleApp or SharedLib or WindowedApp', 'options:not no_rive_jpeg' }) @@ -197,7 +199,17 @@ function rive_tools_project(name, project_kind) libdirs({ RIVE_RUNTIME_DIR .. '/skia/dependencies/glfw_build/src/Release', }) - links({ 'glfw3', 'opengl32', 'd3d11', 'd3d12', 'dxguid', 'dxgi', 'Dbghelp', 'd3dcompiler', 'ws2_32' }) + links({ + 'glfw3', + 'opengl32', + 'd3d11', + 'd3d12', + 'dxguid', + 'dxgi', + 'Dbghelp', + 'd3dcompiler', + 'ws2_32', + }) end filter({ 'kind:ConsoleApp or SharedLib or WindowedApp', 'system:macosx' }) @@ -289,13 +301,13 @@ do RIVE_PLS_DIR .. '/path_fiddle/fiddle_context_dawn.cpp', }) - if _TARGET_OS == 'windows'then + if _TARGET_OS == 'windows' then externalincludedirs({ - dx12_headers .. '/include/directx' + dx12_headers .. '/include/directx', }) end - - filter({ 'options:for_unreal'}) + + filter({ 'options:for_unreal' }) do defines({ 'RIVE_UNREAL', 'RIVE_TOOLS_NO_GLFW', 'RIVE_TOOLS_NO_GL' }) end diff --git a/tests/unit_tests/premake5.lua b/tests/unit_tests/premake5.lua index 987a04a2..273fc6f9 100644 --- a/tests/unit_tests/premake5.lua +++ b/tests/unit_tests/premake5.lua @@ -58,7 +58,6 @@ do miniaudio, yoga, pls_generated_headers, - -- openlibm .. '/include', }) links({ @@ -71,7 +70,7 @@ do 'zlib', 'libjpeg', 'libwebp', - -- 'openlibm', + 'miniaudio', }) files({ diff --git a/tests/unit_tests/runtime/raw_text_input_test.cpp b/tests/unit_tests/runtime/raw_text_input_test.cpp index 448d120d..608e1e26 100644 --- a/tests/unit_tests/runtime/raw_text_input_test.cpp +++ b/tests/unit_tests/runtime/raw_text_input_test.cpp @@ -102,20 +102,20 @@ TEST_CASE("cursor is placed correctly with ltr paragraphs", "[text_input]") textInput.maxWidth(maxWidth); textInput.fontSize(72.0f); - CHECK(textInput.bounds() == AABB()); + CHECK_AABB(textInput.bounds(), AABB()); NoOpFactory factory; textInput.update(&factory); - CHECK(textInput.bounds() == AABB(0, 0, 500, 216)); - CHECK(textInput.measure(500, 400) == AABB(0, 0, 500, 216)); + CHECK_AABB(textInput.bounds(), AABB(0, 0, 446.51953f, 216)); + CHECK_AABB(textInput.measure(500, 400), AABB(0, 0, 446.51953f, 216)); CHECK(textInput.measureCount == 1); // measure count should still be one if we re-measured with same sizes. - CHECK(textInput.measure(500, 400) == AABB(0, 0, 500, 216)); + CHECK_AABB(textInput.measure(500, 400), AABB(0, 0, 446.51953f, 216)); CHECK(textInput.measureCount == 1); - CHECK(textInput.measure(400, 400) == AABB(0, 0, 400, 324)); + CHECK_AABB(textInput.measure(400, 400), AABB(0, 0, 318.97266f, 324)); CHECK(textInput.measureCount == 2); textInput.text("one two three four five six"); - CHECK(textInput.measure(400, 400) == AABB(0, 0, 400, 324)); + CHECK_AABB(textInput.measure(400, 400), AABB(0, 0, 318.97266f, 324)); CHECK(textInput.measureCount == 3); textInput.text("one two three four five"); diff --git a/tests/unit_tests/test.sh b/tests/unit_tests/test.sh index 4a40cd2f..8da1e12f 100755 --- a/tests/unit_tests/test.sh +++ b/tests/unit_tests/test.sh @@ -41,6 +41,10 @@ while [[ $# -gt 0 ]]; do export REBASELINE_SILVERS=true shift # past argument ;; + clean) + rm -fR out + shift # past argument + ;; *) shift # past argument ;; @@ -78,13 +82,6 @@ fi export PREMAKE=$PWD/dependencies/bin/premake5 -for var in "$@"; do - if [[ $var = "clean" ]]; then - echo 'Cleaning...' - rm -fR out - fi -done - mkdir -p out if [[ $machine = "macosx" ]]; then @@ -107,7 +104,8 @@ if [[ $machine = "macosx" ]]; then OUT_DIR="$(out_dir)" $PREMAKE $TARGET $PREMAKE_COMMANDS --out=$OUT_DIR pushd $OUT_DIR - make -j$(($(sysctl -n hw.physicalcpu) + 1)) + # make -j$(($(sysctl -n hw.physicalcpu) + 1)) + make popd rm -fR silvers/tarnished mkdir -p silvers/tarnished diff --git a/viewer/build/premake5_viewer.lua b/viewer/build/premake5_viewer.lua index be3b9a21..19de9856 100644 --- a/viewer/build/premake5_viewer.lua +++ b/viewer/build/premake5_viewer.lua @@ -36,7 +36,7 @@ do yoga, }) - links({ 'rive','rive_decoders', 'rive_harfbuzz', 'rive_sheenbidi', 'rive_yoga' }) + links({ 'rive', 'rive_decoders', 'rive_harfbuzz', 'rive_sheenbidi', 'rive_yoga', 'miniaudio' }) libdirs({ rive .. '/build/%{cfg.system}/bin/%{cfg.buildcfg}' })