From 380b583a360dcbd20509c20996e64911eab98206 Mon Sep 17 00:00:00 2001 From: gargsaumya Date: Thu, 27 Nov 2025 12:34:25 +0000 Subject: [PATCH 1/2] fix current cmake warnings in linux and add support to treat warnings as errors at build step --- mssql_python/pybind/CMakeLists.txt | 14 ++++++++++++++ mssql_python/pybind/ddbc_bindings.cpp | 13 ++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/mssql_python/pybind/CMakeLists.txt b/mssql_python/pybind/CMakeLists.txt index 5d1e28f4..1966e48c 100644 --- a/mssql_python/pybind/CMakeLists.txt +++ b/mssql_python/pybind/CMakeLists.txt @@ -8,6 +8,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Enable verbose output to see actual compiler/linker commands set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Verbose output" FORCE) +# Treat CMake warnings as errors +set(CMAKE_WARN_DEPRECATED_DEPRECATION FALSE) +set(CMAKE_ERROR_DEPRECATED TRUE) +set(CMAKE_WARN_DEPRECATED TRUE) + if (MSVC) # Security compiler options for OneBranch compliance message(STATUS "Applying MSVC security compiler options for OneBranch compliance") @@ -302,6 +307,15 @@ if(MSVC) target_compile_options(ddbc_bindings PRIVATE /W4 /WX) endif() +# Add warning flags for GCC/Clang on Linux and macOS +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(ddbc_bindings PRIVATE + -Werror + -Wattributes + -Wint-to-pointer-cast + ) +endif() + # Add macOS-specific string conversion fix if(APPLE) message(STATUS "Enabling macOS string conversion fix") diff --git a/mssql_python/pybind/ddbc_bindings.cpp b/mssql_python/pybind/ddbc_bindings.cpp index 9a828011..3fbc5d07 100644 --- a/mssql_python/pybind/ddbc_bindings.cpp +++ b/mssql_python/pybind/ddbc_bindings.cpp @@ -114,6 +114,10 @@ py::object get_uuid_class() { // Struct to hold parameter information for binding. Used by SQLBindParameter. // This struct is shared between C++ & Python code. +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wattributes" +#endif struct ParamInfo { SQLSMALLINT inputOutputType; SQLSMALLINT paramCType; @@ -124,6 +128,9 @@ struct ParamInfo { bool isDAE = false; // Indicates if we need to stream py::object dataPtr; }; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // Mirrors the SQL_NUMERIC_STRUCT. But redefined to replace val char array // with std::string, because pybind doesn't allow binding char array. @@ -713,7 +720,7 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params, } SQL_NUMERIC_STRUCT* numericPtr = reinterpret_cast(dataPtr); rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_PRECISION, - (SQLPOINTER)numericPtr->precision, 0); + reinterpret_cast(static_cast(numericPtr->precision)), 0); if (!SQL_SUCCEEDED(rc)) { LOG("BindParameters: SQLSetDescField(SQL_DESC_PRECISION) " "failed for param[%d] - SQLRETURN=%d", @@ -721,7 +728,7 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params, return rc; } - rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_SCALE, (SQLPOINTER)numericPtr->scale, 0); + rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_SCALE, reinterpret_cast(static_cast(numericPtr->scale)), 0); if (!SQL_SUCCEEDED(rc)) { LOG("BindParameters: SQLSetDescField(SQL_DESC_SCALE) failed " "for param[%d] - SQLRETURN=%d", @@ -729,7 +736,7 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params, return rc; } - rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_DATA_PTR, (SQLPOINTER)numericPtr, 0); + rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_DATA_PTR, reinterpret_cast(numericPtr), 0); if (!SQL_SUCCEEDED(rc)) { LOG("BindParameters: SQLSetDescField(SQL_DESC_DATA_PTR) failed " "for param[%d] - SQLRETURN=%d", From a449e6780579c8f35777353f16fa19973a851be1 Mon Sep 17 00:00:00 2001 From: gargsaumya Date: Thu, 27 Nov 2025 12:55:31 +0000 Subject: [PATCH 2/2] copilot review comments --- mssql_python/pybind/CMakeLists.txt | 13 +++++++++---- mssql_python/pybind/ddbc_bindings.cpp | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/mssql_python/pybind/CMakeLists.txt b/mssql_python/pybind/CMakeLists.txt index 1966e48c..45893318 100644 --- a/mssql_python/pybind/CMakeLists.txt +++ b/mssql_python/pybind/CMakeLists.txt @@ -9,7 +9,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Verbose output" FORCE) # Treat CMake warnings as errors -set(CMAKE_WARN_DEPRECATED_DEPRECATION FALSE) set(CMAKE_ERROR_DEPRECATED TRUE) set(CMAKE_WARN_DEPRECATED TRUE) @@ -310,10 +309,16 @@ endif() # Add warning flags for GCC/Clang on Linux and macOS if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_compile_options(ddbc_bindings PRIVATE - -Werror - -Wattributes - -Wint-to-pointer-cast + -Werror # Treat warnings as errors + -Wattributes # Enable attribute warnings (cross-compiler) ) + + # GCC-specific warning flags + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(ddbc_bindings PRIVATE + -Wint-to-pointer-cast # GCC-specific warning for integer-to-pointer casts + ) + endif() endif() # Add macOS-specific string conversion fix diff --git a/mssql_python/pybind/ddbc_bindings.cpp b/mssql_python/pybind/ddbc_bindings.cpp index 3fbc5d07..31cdc514 100644 --- a/mssql_python/pybind/ddbc_bindings.cpp +++ b/mssql_python/pybind/ddbc_bindings.cpp @@ -114,6 +114,9 @@ py::object get_uuid_class() { // Struct to hold parameter information for binding. Used by SQLBindParameter. // This struct is shared between C++ & Python code. +// Suppress -Wattributes warning for ParamInfo struct +// The warning is triggered because pybind11 handles visibility attributes automatically, +// and having additional attributes on the struct can cause conflicts on Linux with GCC #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wattributes" @@ -728,7 +731,7 @@ SQLRETURN BindParameters(SQLHANDLE hStmt, const py::list& params, return rc; } - rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_SCALE, reinterpret_cast(static_cast(numericPtr->scale)), 0); + rc = SQLSetDescField_ptr(hDesc, 1, SQL_DESC_SCALE, reinterpret_cast(static_cast(numericPtr->scale)), 0); if (!SQL_SUCCEEDED(rc)) { LOG("BindParameters: SQLSetDescField(SQL_DESC_SCALE) failed " "for param[%d] - SQLRETURN=%d",