From 23f764490838c0855798471fb93ec3aadd723e18 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Fri, 4 Apr 2025 18:09:33 -0700 Subject: Fix ONNX build warnings and remove std::filesystem dependency. Extracted from cmake/patches/onnx/onnx.patch in onnxruntime PR #24012 (commit 23f764490838c0855798471fb93ec3aadd723e18). The ONNX_MINIMAL_BUILD parts were removed as they are not needed for the Guix package. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d7ca846..69aa622f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -499,6 +499,7 @@ if (MSVC) endif() else() # On non-Windows, hide all symbols we don't need + set(EXTRA_FLAGS "-Wno-unused-parameter") set(ONNX_API_DEFINE "-DONNX_API=__attribute__\(\(__visibility__\(\"default\"\)\)\)") set_target_properties(onnx_proto PROPERTIES CXX_VISIBILITY_PRESET hidden) set_target_properties(onnx_proto PROPERTIES VISIBILITY_INLINES_HIDDEN 1) diff --git a/onnx/common/file_utils.h b/onnx/common/file_utils.h index b847798e..a6c31904 100644 --- a/onnx/common/file_utils.h +++ b/onnx/common/file_utils.h @@ -6,7 +6,6 @@ #pragma once -#include #include #include @@ -17,8 +16,7 @@ namespace ONNX_NAMESPACE { template void LoadProtoFromPath(const std::string proto_path, T& proto) { - std::filesystem::path proto_u8_path = std::filesystem::u8path(proto_path); - std::fstream proto_stream(proto_u8_path, std::ios::in | std::ios::binary); + std::fstream proto_stream(proto_path, std::ios::in | std::ios::binary); if (!proto_stream.good()) { fail_check("Unable to open proto file: ", proto_path, ". Please check if it is a valid proto. "); } diff --git a/onnx/onnx_pb.h b/onnx/onnx_pb.h index 0aab3e26..398ac2d6 100644 --- a/onnx/onnx_pb.h +++ b/onnx/onnx_pb.h @@ -47,10 +47,28 @@ #define ONNX_API ONNX_IMPORT #endif +#if defined(__GNUC__) +#pragma GCC diagnostic push + +// In file included from onnx/onnx-ml.pb.h:30: +// In file included from google/protobuf/extension_set.h:53: +// google/protobuf/parse_context.h:328:47: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32] +#if defined(__has_warning) +#if __has_warning("-Wshorten-64-to-32") +#pragma GCC diagnostic ignored "-Wshorten-64-to-32" +#endif +#endif // defined(__has_warning) + +#endif // defined(__GNUC__) + #ifdef ONNX_ML #include "onnx/onnx-ml.pb.h" #else #include "onnx/onnx.pb.h" #endif +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + #endif // ! ONNX_ONNX_PB_H