Skip to content

Commit

Permalink
wpewebkit: Fix build failure on musl (roundeven and roundevenf)
Browse files Browse the repository at this point in the history
While building WPEWebKit on musl-based systems, errors occur due to
the absence of roundevenf and roundeven functions. These are not
available in musl and other non-glibc platforms.

This patch provides fallback implementations for both functions.

Upstream: https://bugs.webkit.org/show_bug.cgi?id=281216
  • Loading branch information
psaavedra committed Oct 12, 2024
1 parent ee69051 commit a5ba3dd
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
From 3c54d2278eba24fe75ff2c04b74807e118ed7562 Mon Sep 17 00:00:00 2001
From: Pablo Saavedra <[email protected]>
Date: Thu, 10 Oct 2024 15:11:47 +0200
Subject: [PATCH] [JSC] Fix build failure on musl: Add fallback for roundeven
and roundevenf https://bugs.webkit.org/show_bug.cgi?id=281216

Reviewed by NOBODY (OOPS!).

While building WPEWebKit on musl-based systems, errors occur due to
the absence of roundevenf and roundeven functions. These are not
available in musl and other non-glibc platforms.

This patch provides fallback implementations for both functions.

* Source/JavaScriptCore/runtime/MathCommon.cpp:
(JSC::Math::roundevenf):
(JSC::Math::roundeven):
---
Source/JavaScriptCore/runtime/MathCommon.cpp | 22 ++++++++++++++++++++
1 file changed, 22 insertions(+)

Upstream-Status: Submitted [https://bugs.webkit.org/show_bug.cgi?id=281216]

diff --git a/Source/JavaScriptCore/runtime/MathCommon.cpp b/Source/JavaScriptCore/runtime/MathCommon.cpp
index 0cd276b20126..625f9146c1ea 100644
--- a/Source/JavaScriptCore/runtime/MathCommon.cpp
+++ b/Source/JavaScriptCore/runtime/MathCommon.cpp
@@ -635,6 +635,28 @@ JSC_DEFINE_NOEXCEPT_JIT_OPERATION(f64_nearest, double, (double operand))
return std::nearbyint(operand);
}

+#if OS(LINUX) && !defined(__GLIBC__)
+static inline float roundevenf(float operand)
+{
+ float rounded = roundf(operand);
+ if (fabsf(operand - rounded) == 0.5f) {
+ if (fmod(rounded, 2.0f) != 0.0f)
+ return rounded - copysignf(1.0f, operand);
+ }
+ return rounded;
+}
+
+static inline double roundeven(double operand)
+{
+ double rounded = round(operand);
+ if (fabs(operand - rounded) == 0.5) {
+ if (fmod(rounded, 2.0) != 0.0)
+ return rounded - copysign(1.0, operand);
+ }
+ return rounded;
+}
+#endif
+
JSC_DEFINE_NOEXCEPT_JIT_OPERATION(f32_roundeven, float, (float operand)) { return roundevenf(operand); }
JSC_DEFINE_NOEXCEPT_JIT_OPERATION(f64_roundeven, double, (double operand)) { return roundeven(operand); }
JSC_DEFINE_NOEXCEPT_JIT_OPERATION(f32_trunc, float, (float operand)) { return std::trunc(operand); }
--
2.43.0

4 changes: 3 additions & 1 deletion recipes-browser/wpewebkit/wpewebkit_2.46.1.bb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ require conf/include/devupstream.inc

FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"

SRC_URI = "https://wpewebkit.org/releases/${BPN}-${PV}.tar.xz;name=tarball"
SRC_URI = "https://wpewebkit.org/releases/${BPN}-${PV}.tar.xz;name=tarball \
file://0001-JSC-Fix-build-failure-on-musl-Add-fallback-for-round.patch \
"

SRC_URI[tarball.sha256sum] = "1e0aaf870f36001c42b1ce5a2027b4101bed878746e437cc6d6fed0693afe9ad"

Expand Down

0 comments on commit a5ba3dd

Please sign in to comment.