From 038e11dc285fd1cd8af6fd155cc4b27e16113a7e Mon Sep 17 00:00:00 2001 From: Yureka Date: Sun, 11 Jan 2026 16:51:20 +0100 Subject: [PATCH 1/2] pkgsMusl.patchutils: fix build Upstream has addressed this in release 0.4.3 and later with commit dc88e96 "Integrate gnulib properly". Since these versions of patchutils need to stay around for fetchpatch / fetchpatch2 Fixed-Output Derivations, we'll need to carry these patches. --- pkgs/tools/text/patchutils/0.3.3.nix | 6 ++- pkgs/tools/text/patchutils/0.4.2.nix | 5 +- pkgs/tools/text/patchutils/default.nix | 3 ++ .../text/patchutils/getenv-signature.patch | 46 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 pkgs/tools/text/patchutils/getenv-signature.patch diff --git a/pkgs/tools/text/patchutils/0.3.3.nix b/pkgs/tools/text/patchutils/0.3.3.nix index f1aea0a847f0..2efd44fc787a 100644 --- a/pkgs/tools/text/patchutils/0.3.3.nix +++ b/pkgs/tools/text/patchutils/0.3.3.nix @@ -5,6 +5,10 @@ callPackage ./generic.nix ( // { version = "0.3.3"; sha256 = "0g5df00cj4nczrmr4k791l7la0sq2wnf8rn981fsrz1f3d2yix4i"; - patches = [ ./drop-comments.patch ]; # we would get into a cycle when using fetchpatch on this one + patches = [ + # we would get into a cycle when using fetchpatch on this one + ./drop-comments.patch + ./getenv-signature.patch + ]; } ) diff --git a/pkgs/tools/text/patchutils/0.4.2.nix b/pkgs/tools/text/patchutils/0.4.2.nix index 18625c2d9822..ef25f66d3876 100644 --- a/pkgs/tools/text/patchutils/0.4.2.nix +++ b/pkgs/tools/text/patchutils/0.4.2.nix @@ -7,6 +7,9 @@ callPackage ./generic.nix ( sha256 = "sha256-iHWwll/jPeYriQ9s15O+f6/kGk5VLtv2QfH+1eu/Re0="; # for gitdiff extraBuildInputs = [ python3 ]; - patches = [ ./Make-grepdiff1-test-case-pcre-aware.patch ]; + patches = [ + ./Make-grepdiff1-test-case-pcre-aware.patch + ./getenv-signature.patch + ]; } ) diff --git a/pkgs/tools/text/patchutils/default.nix b/pkgs/tools/text/patchutils/default.nix index c79b1d7110c7..04d033383c53 100644 --- a/pkgs/tools/text/patchutils/default.nix +++ b/pkgs/tools/text/patchutils/default.nix @@ -5,5 +5,8 @@ callPackage ./generic.nix ( // { version = "0.3.4"; sha256 = "0xp8mcfyi5nmb5a2zi5ibmyshxkb1zv1dgmnyn413m7ahgdx8mfg"; + patches = [ + ./getenv-signature.patch + ]; } ) diff --git a/pkgs/tools/text/patchutils/getenv-signature.patch b/pkgs/tools/text/patchutils/getenv-signature.patch new file mode 100644 index 000000000000..1a6956ca83cc --- /dev/null +++ b/pkgs/tools/text/patchutils/getenv-signature.patch @@ -0,0 +1,46 @@ +From 64e5c63ef72ab97ecae6d43845634aa34da0b426 Mon Sep 17 00:00:00 2001 +From: Yureka +Date: Sun, 11 Jan 2026 16:49:07 +0100 +Subject: [PATCH] getopt.{c,h}: Do not use unspecified signatures + +Unspecified signatures no longer work with C23, and the GNU getopt signature matches the one specified by POSIX +--- + src/getopt.c | 2 +- + src/getopt.h | 7 ------- + 2 files changed, 1 insertion(+), 8 deletions(-) + +diff --git a/src/getopt.c b/src/getopt.c +index 9bafa45..c268441 100644 +--- a/src/getopt.c ++++ b/src/getopt.c +@@ -209,7 +209,7 @@ static char *posixly_correct; + whose names are inconsistent. */ + + #ifndef getenv +-extern char *getenv (); ++extern char *getenv (const char *); + #endif + + static char * +diff --git a/src/getopt.h b/src/getopt.h +index a1b8dd6..0aea224 100644 +--- a/src/getopt.h ++++ b/src/getopt.h +@@ -138,14 +138,7 @@ struct option + `getopt'. */ + + #if (defined __STDC__ && __STDC__) || defined __cplusplus +-# ifdef __GNU_LIBRARY__ +-/* Many other libraries have conflicting prototypes for getopt, with +- differences in the consts, in stdlib.h. To avoid compilation +- errors, only prototype getopt for the GNU C library. */ + extern int getopt (int __argc, char *const *__argv, const char *__shortopts); +-# else /* not __GNU_LIBRARY__ */ +-extern int getopt (); +-# endif /* __GNU_LIBRARY__ */ + + # ifndef __need_getopt + extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, +-- +2.52.0 + From 2a8b0c3f56ebbfd2f83977aa883cda280b571b6b Mon Sep 17 00:00:00 2001 From: Yureka Date: Fri, 16 Jan 2026 19:11:42 +0100 Subject: [PATCH 2/2] pkgsMusl.onnxruntime: fix build --- .../by-name/on/onnxruntime/musl-cstdint.patch | 24 +++++++++ .../on/onnxruntime/musl-execinfo.patch | 33 ++++++++++++ pkgs/by-name/on/onnxruntime/package.nix | 51 +++++++++++++------ 3 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 pkgs/by-name/on/onnxruntime/musl-cstdint.patch create mode 100644 pkgs/by-name/on/onnxruntime/musl-execinfo.patch diff --git a/pkgs/by-name/on/onnxruntime/musl-cstdint.patch b/pkgs/by-name/on/onnxruntime/musl-cstdint.patch new file mode 100644 index 000000000000..cf98d69fd88f --- /dev/null +++ b/pkgs/by-name/on/onnxruntime/musl-cstdint.patch @@ -0,0 +1,24 @@ +diff --git a/include/onnxruntime/core/framework/tensor_shape.h b/include/onnxruntime/core/framework/tensor_shape.h +index d4ee4a0e5e..c33bea9cf7 100644 +--- a/include/onnxruntime/core/framework/tensor_shape.h ++++ b/include/onnxruntime/core/framework/tensor_shape.h +@@ -8,6 +8,7 @@ + #include + #include + #include ++#include + + #include + #include "core/common/inlined_containers_fwd.h" +diff --git a/onnxruntime/test/perftest/strings_helper.h b/onnxruntime/test/perftest/strings_helper.h +index d6c6f6112a..8580c86db6 100644 +--- a/onnxruntime/test/perftest/strings_helper.h ++++ b/onnxruntime/test/perftest/strings_helper.h +@@ -7,6 +7,7 @@ + #include + #include + #include ++#include + + namespace onnxruntime { + namespace perftest { diff --git a/pkgs/by-name/on/onnxruntime/musl-execinfo.patch b/pkgs/by-name/on/onnxruntime/musl-execinfo.patch new file mode 100644 index 000000000000..3d6b4c014e4d --- /dev/null +++ b/pkgs/by-name/on/onnxruntime/musl-execinfo.patch @@ -0,0 +1,33 @@ +From 7bc56c886c8b9fa27842a14bbb964ffe8e576a9e Mon Sep 17 00:00:00 2001 +From: Jaeyoon Jung +Date: Tue, 12 Aug 2025 10:55:52 +0900 +Subject: [PATCH] Fix build with musl + +Added __GLIBC__ macro for 'execinfo.h' and related functions as they are +GLIBC specific and not available in other libc implementation like musl. +--- + onnxruntime/core/platform/posix/stacktrace.cc | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/onnxruntime/core/platform/posix/stacktrace.cc b/onnxruntime/core/platform/posix/stacktrace.cc +index a34f6fd82ddd1..ab00f5fbb233e 100644 +--- a/onnxruntime/core/platform/posix/stacktrace.cc ++++ b/onnxruntime/core/platform/posix/stacktrace.cc +@@ -3,7 +3,7 @@ + + #include "core/common/common.h" + +-#if !defined(__ANDROID__) && !defined(__wasm__) && !defined(_OPSCHEMA_LIB_) && !defined(_AIX) ++#if !defined(__ANDROID__) && !defined(__wasm__) && !defined(_OPSCHEMA_LIB_) && !defined(_AIX) && defined(__GLIBC__) + #include + #endif + #include +@@ -13,7 +13,7 @@ namespace onnxruntime { + std::vector GetStackTrace() { + std::vector stack; + +-#if !defined(NDEBUG) && !defined(__ANDROID__) && !defined(__wasm__) && !defined(_OPSCHEMA_LIB_) ++#if !defined(NDEBUG) && !defined(__ANDROID__) && !defined(__wasm__) && !defined(_OPSCHEMA_LIB_) && defined(__GLIBC__) + constexpr int kCallstackLimit = 64; // Maximum depth of callstack + + void* array[kCallstackLimit]; diff --git a/pkgs/by-name/on/onnxruntime/package.nix b/pkgs/by-name/on/onnxruntime/package.nix index 0f4de22c3222..4b932dc5996b 100644 --- a/pkgs/by-name/on/onnxruntime/package.nix +++ b/pkgs/by-name/on/onnxruntime/package.nix @@ -5,6 +5,7 @@ fetchFromGitHub, applyPatches, fetchpatch, + fetchurl, abseil-cpp_202407, cmake, cpuinfo, @@ -151,6 +152,20 @@ effectiveStdenv.mkDerivation (finalAttrs: { url = "https://github.com/microsoft/onnxruntime/commit/8ebd0bf1cf02414584d15d7244b07fa97d65ba02.patch"; hash = "sha256-vX+kaFiNdmqWI91JELcLpoaVIHBb5EPbI7rCAMYAx04="; }) + + # Skip execinfo include on musl + # https://github.com/microsoft/onnxruntime/pull/25726 + ./musl-execinfo.patch + # Add missing include which is only needed on musl (is implied in other includes on glibc) + # https://github.com/microsoft/onnxruntime/pull/26969 + ./musl-cstdint.patch + + # Fix build of unit tests with musl libc + # https://github.com/microsoft/onnxruntime/issues/9155 + (fetchurl { + url = "https://gitlab.alpinelinux.org/alpine/aports/-/raw/462dfe0eb4b66948fe48de44545cc22bb64fdf9f/community/onnxruntime/0001-Remove-MATH_NO_EXCEPT-macro.patch"; + hash = "sha256-BdeGYevZExWWCuJ1lSw0Roy3h+9EbJgFF8qMwVxSn1A="; + }) ]; nativeBuildInputs = [ @@ -302,21 +317,26 @@ effectiveStdenv.mkDerivation (finalAttrs: { (lib.cmakeBool "onnxruntime_USE_COMPOSABLE_KERNEL_CK_TILE" false) ]; - env = lib.optionalAttrs rocmSupport { - MIOPEN_PATH = rocmPackages.miopen; - # HIP steps fail to find ROCm libs when not in HIPFLAGS, causing - # fatal error: 'rocrand/rocrand.h' file not found - HIPFLAGS = lib.concatMapStringsSep " " (pkg: "-I${lib.getInclude pkg}/include") [ - rocmPackages.hipblas - rocmPackages.hipcub - rocmPackages.hiprand - rocmPackages.hipsparse - rocmPackages.rocblas - rocmPackages.rocprim - rocmPackages.rocrand - rocmPackages.rocthrust - ]; - }; + env = + lib.optionalAttrs rocmSupport { + MIOPEN_PATH = rocmPackages.miopen; + # HIP steps fail to find ROCm libs when not in HIPFLAGS, causing + # fatal error: 'rocrand/rocrand.h' file not found + HIPFLAGS = lib.concatMapStringsSep " " (pkg: "-I${lib.getInclude pkg}/include") [ + rocmPackages.hipblas + rocmPackages.hipcub + rocmPackages.hiprand + rocmPackages.hipsparse + rocmPackages.rocblas + rocmPackages.rocprim + rocmPackages.rocrand + rocmPackages.rocthrust + ]; + } + // lib.optionalAttrs effectiveStdenv.hostPlatform.isMusl { + NIX_CFLAGS_COMPILE = "-DFLATBUFFERS_LOCALE_INDEPENDENT=0"; + GTEST_FILTER = "*:-ContribOpTest.StringNormalizer*"; + }; doCheck = !( @@ -336,6 +356,7 @@ effectiveStdenv.mkDerivation (finalAttrs: { hardeningEnable = lib.optionals (effectiveStdenv.hostPlatform.system == "loongarch64-linux") [ "nostrictaliasing" ]; + hardeningDisable = lib.optional effectiveStdenv.hostPlatform.isMusl "fortify"; postPatch = '' substituteInPlace cmake/libonnxruntime.pc.cmake.in \