From ba5ed99861d836c33e0ebe94fda254a3e050dcba Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Sun, 11 Aug 2024 22:18:48 +0100 Subject: [PATCH] x265: fix build on x86_64-darwin Update to 3.6 pulled in local definition of `__rdtsc()` symbol in the test suite and caused symbol clash: /tmp/nix-build-x265-3.6.drv-0/x265_3.6/source/test/testharness.h:78:24: error: static declaration of '__rdtsc' follows non-static declaration static inline uint32_t __rdtsc(void) ^ /tmp/nix-build-x265-3.6.drv-0/x265_3.6/source/test/testharness.h:78:24: note: '__rdtsc' is a builtin with type 2 The change avoids redefinition if the compiler already provides the builtin. --- .../libraries/x265/darwin-__rdtsc.patch | 29 +++++++++++++++++++ pkgs/development/libraries/x265/default.nix | 6 ++++ 2 files changed, 35 insertions(+) create mode 100644 pkgs/development/libraries/x265/darwin-__rdtsc.patch diff --git a/pkgs/development/libraries/x265/darwin-__rdtsc.patch b/pkgs/development/libraries/x265/darwin-__rdtsc.patch new file mode 100644 index 000000000000..a052f818af10 --- /dev/null +++ b/pkgs/development/libraries/x265/darwin-__rdtsc.patch @@ -0,0 +1,29 @@ +From 5ad351f7d271d0be0611797542c831898b2f531c Mon Sep 17 00:00:00 2001 +From: Sergei Trofimovich +Date: Sun, 11 Aug 2024 22:09:34 +0100 +Subject: [PATCH] source/test/testharness.h: don't redefine `__rdtsc()` builtin + +On darwin clang-16 provides `__rdtsc()` builtin. As a result the build +fails in `nixpkgs` as: + + source/test/testharness.h:78:24: error: static declaration of '__rdtsc' follows non-static declaration + static inline uint32_t __rdtsc(void) + ^ + x265_3.6/source/test/testharness.h:78:24: note: '__rdtsc' is a builtin with type 2 + +The change avoid redefinition on targets that define `__rdtsc()` builtin. +--- + source/test/testharness.h | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/test/testharness.h ++++ b/test/testharness.h +@@ -69,6 +69,8 @@ protected: + #include + #elif HAVE_RDTSC + #include ++#elif defined(__has_builtin) && __has_builtin(__rdtsc) ++/* compiler-provided builtin */ + #elif (!defined(__APPLE__) && (defined (__GNUC__) && (defined(__x86_64__) || defined(__i386__)))) + #include + #elif ( !defined(__APPLE__) && defined (__GNUC__) && defined(__ARM_NEON__)) diff --git a/pkgs/development/libraries/x265/default.nix b/pkgs/development/libraries/x265/default.nix index e58e910c2bba..3d10538314f0 100644 --- a/pkgs/development/libraries/x265/default.nix +++ b/pkgs/development/libraries/x265/default.nix @@ -41,6 +41,12 @@ stdenv.mkDerivation rec { hash = "sha256-ZjUx80HFOJ9GDXMOYuEKT8yjQoyiyhCWk4Z7xf4uKAc="; }; + # TODO: apply patch unconditionally in staging. It's conditional to + # save rebuild on staging-next. + patches = lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [ + ./darwin-__rdtsc.patch + ]; + sourceRoot = "x265_${version}/source"; postPatch = ''