From 4cd527d969eef3d54e8814582249f6aa1c3a0a6e Mon Sep 17 00:00:00 2001 From: Matteo Pacini Date: Tue, 14 Oct 2025 22:08:16 +0100 Subject: [PATCH] gtk3: fix sincos detection with clang Backport GTK MR 5531 to fix sincos detection with clang on all platforms. The issue occurs because meson's function detection doesn't include proper headers or -D_GNU_SOURCE when checking for sincos(), causing it to fail detection even when the function is available (especially with clang). This backports the fix from GTK 4 (MR 5531) which was never backported to the gtk-3-24 branch. The patch adds proper headers and compiler flags to meson's function detection, and updates gtkgears.c to use a wrapper function that conditionally uses sincos() only when properly detected. Upstream MR: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/5531 See: https://github.com/NixOS/nixpkgs/pull/449689 --- pkgs/development/libraries/gtk/3.x.nix | 6 ++ .../gtk/patches/3.0-mr5531-backport.patch | 93 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 pkgs/development/libraries/gtk/patches/3.0-mr5531-backport.patch diff --git a/pkgs/development/libraries/gtk/3.x.nix b/pkgs/development/libraries/gtk/3.x.nix index e37a40923d1a..00d85ff5d1a5 100644 --- a/pkgs/development/libraries/gtk/3.x.nix +++ b/pkgs/development/libraries/gtk/3.x.nix @@ -88,6 +88,12 @@ stdenv.mkDerivation (finalAttrs: { patches = [ ./patches/3.0-immodules.cache.patch ./patches/3.0-Xft-setting-fallback-compute-DPI-properly.patch + # Backport of MR 5531 to fix sincos detection with clang + # Adds proper headers and -D_GNU_SOURCE to function checks + # MR 5531 was only merged into GTK 4, never backported to gtk-3-24 + # See: https://github.com/NixOS/nixpkgs/pull/449689 + # Upstream: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/5531 + ./patches/3.0-mr5531-backport.patch ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ # X11 module requires which is not installed on Darwin diff --git a/pkgs/development/libraries/gtk/patches/3.0-mr5531-backport.patch b/pkgs/development/libraries/gtk/patches/3.0-mr5531-backport.patch new file mode 100644 index 000000000000..afbfb1f95eb6 --- /dev/null +++ b/pkgs/development/libraries/gtk/patches/3.0-mr5531-backport.patch @@ -0,0 +1,93 @@ +From f1fb82c739aebc6b37090f8ebf74d856129116d3 Mon Sep 17 00:00:00 2001 +From: Matteo Pacini +Date: Tue, 14 Oct 2025 22:03:27 +0100 +Subject: [PATCH] Backport MR 5531: Fix sincos detection with clang + +Add proper headers and -D_GNU_SOURCE to function checks to ensure +functions like sincos are properly detected, especially with clang. + +Also fix gtkgears.c to avoid issues when sincos is in headers but +not detected by the build system. + +Backport of https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/5531 +adapted for GTK 3.24.49. +--- + meson.build | 10 +++++++++- + tests/gtkgears.c | 22 ++++++++++++---------- + 2 files changed, 21 insertions(+), 11 deletions(-) + +diff --git a/meson.build b/meson.build +index 08337ec..92d7781 100644 +--- a/meson.build ++++ b/meson.build +@@ -255,7 +255,15 @@ check_functions = [ + ] + + foreach func : check_functions +- if cc.has_function(func, dependencies: libm) ++ if cc.has_function(func, ++ args: '-D_GNU_SOURCE', ++ prefix: ++ '#include \n' + ++ '#include \n' + ++ '#include \n' + ++ '#include \n' + ++ '#include ', ++ dependencies: libm) + cdata.set('HAVE_' + func.underscorify().to_upper(), 1) + endif + endforeach +diff --git a/tests/gtkgears.c b/tests/gtkgears.c +index 062b611..ba7e196 100644 +--- a/tests/gtkgears.c ++++ b/tests/gtkgears.c +@@ -48,14 +48,16 @@ + #define VERTICES_PER_TOOTH 34 + #define GEAR_VERTEX_STRIDE 6 + +-#ifndef HAVE_SINCOS +-static void +-sincos (double x, double *_sin, double *_cos) ++static inline void ++_sincos (double x, double *_sin, double *_cos) + { ++#ifdef HAVE_SINCOS ++ sincos (x, _sin, _cos); ++#else + *_sin = sin (x); + *_cos = cos (x); +-} + #endif ++} + + /** + * Struct describing the vertices in triangle strip +@@ -306,11 +308,11 @@ create_gear (GLfloat inner_radius, + struct point p[7]; + + /* Calculate needed sin/cos for varius angles */ +- sincos(i * 2.0 * G_PI / teeth + da * 0, &s[0], &c[0]); +- sincos(i * 2.0 * M_PI / teeth + da * 1, &s[1], &c[1]); +- sincos(i * 2.0 * M_PI / teeth + da * 2, &s[2], &c[2]); +- sincos(i * 2.0 * M_PI / teeth + da * 3, &s[3], &c[3]); +- sincos(i * 2.0 * M_PI / teeth + da * 4, &s[4], &c[4]); ++ _sincos(i * 2.0 * G_PI / teeth + da * 0, &s[0], &c[0]); ++ _sincos(i * 2.0 * M_PI / teeth + da * 1, &s[1], &c[1]); ++ _sincos(i * 2.0 * M_PI / teeth + da * 2, &s[2], &c[2]); ++ _sincos(i * 2.0 * M_PI / teeth + da * 3, &s[3], &c[3]); ++ _sincos(i * 2.0 * M_PI / teeth + da * 4, &s[4], &c[4]); + + GEAR_POINT(p[0], r2, 1); + GEAR_POINT(p[1], r2, 2); +@@ -519,7 +521,7 @@ void perspective(GLfloat *m, GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloa + identity(tmp); + + deltaZ = zFar - zNear; +- sincos(radians, &sine, &cosine); ++ _sincos(radians, &sine, &cosine); + + if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) + return; +-- +2.50.1 (Apple Git-155) +