pkgsMusl.onnxruntime: fix build

This commit is contained in:
Yureka
2026-01-17 02:39:20 +01:00
parent 038e11dc28
commit 2a8b0c3f56
3 changed files with 93 additions and 15 deletions
@@ -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 <iosfwd>
#include <string>
#include <vector>
+#include <cstdint>
#include <gsl/gsl>
#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 <unordered_map>
#include <unordered_set>
#include <vector>
+#include <cstdint>
namespace onnxruntime {
namespace perftest {
@@ -0,0 +1,33 @@
From 7bc56c886c8b9fa27842a14bbb964ffe8e576a9e Mon Sep 17 00:00:00 2001
From: Jaeyoon Jung <jaeyoon.jung@lge.com>
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 <execinfo.h>
#endif
#include <vector>
@@ -13,7 +13,7 @@ namespace onnxruntime {
std::vector<std::string> GetStackTrace() {
std::vector<std::string> 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];
+36 -15
View File
@@ -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 \