From 591417f43a7d260f7045f1532f0109ae12526b46 Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Mon, 9 Jun 2025 17:09:07 +0530 Subject: [PATCH 1/6] FEAT: PDB File generation to make Private symbols for DDBC Bindings --- mssql_python/pybind/CMakeLists.txt | 13 +++++++++++++ mssql_python/pybind/build.bat | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/mssql_python/pybind/CMakeLists.txt b/mssql_python/pybind/CMakeLists.txt index dceb2efc..3becd4e5 100644 --- a/mssql_python/pybind/CMakeLists.txt +++ b/mssql_python/pybind/CMakeLists.txt @@ -5,6 +5,12 @@ project(ddbc_bindings) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +if (MSVC) + # Enable PDB generation for all target types + add_compile_options("$<$:/Zi>") + add_link_options("$<$:/DEBUG /OPT:REF /OPT:ICF>") +endif() + # Set default architecture if not provided if(NOT DEFINED ARCHITECTURE) set(ARCHITECTURE "win64") @@ -104,6 +110,13 @@ set_target_properties(ddbc_bindings PROPERTIES OUTPUT_NAME "ddbc_bindings.cp${PYTHON_VERSION}-${WHEEL_ARCH}" SUFFIX ".pyd" ) +# Ensure PDB is generated in Release +set_target_properties(ddbc_bindings PROPERTIES + COMPILE_PDB_NAME "ddbc_bindings.cp${PYTHON_VERSION}-${WHEEL_ARCH}" + COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + PDB_NAME "ddbc_bindings.cp${PYTHON_VERSION}-${WHEEL_ARCH}" + PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" +) # Include directories for all architectures target_include_directories(ddbc_bindings PRIVATE diff --git a/mssql_python/pybind/build.bat b/mssql_python/pybind/build.bat index e96c6a57..e688a4f9 100644 --- a/mssql_python/pybind/build.bat +++ b/mssql_python/pybind/build.bat @@ -144,6 +144,15 @@ if exist "%OUTPUT_DIR%\%PYD_NAME%" ( copy /Y "%OUTPUT_DIR%\%PYD_NAME%" "%SOURCE_DIR%\.." echo [SUCCESS] Copied %PYD_NAME% to %SOURCE_DIR%.. + echo [DIAGNOSTIC] Copying PDB file if it exists... + set PDB_NAME=ddbc_bindings.cp%PYTAG%-%WHEEL_ARCH%.pdb + if exist "%OUTPUT_DIR%\%PDB_NAME%" ( + copy /Y "%OUTPUT_DIR%\%PDB_NAME%" "%SOURCE_DIR%\.." + echo [SUCCESS] Copied %PDB_NAME% to %SOURCE_DIR%.. + ) else ( + echo [WARNING] PDB file %PDB_NAME% not found in output directory. + ) + setlocal enabledelayedexpansion for %%I in ("%SOURCE_DIR%..") do ( set PARENT_DIR=%%~fI From c53449224b25c5f4370559583d97eb660e33884a Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Tue, 10 Jun 2025 08:50:13 +0530 Subject: [PATCH 2/6] Debugging for PDB copying duplicates --- mssql_python/pybind/build.bat | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mssql_python/pybind/build.bat b/mssql_python/pybind/build.bat index e688a4f9..aa161f79 100644 --- a/mssql_python/pybind/build.bat +++ b/mssql_python/pybind/build.bat @@ -147,6 +147,8 @@ if exist "%OUTPUT_DIR%\%PYD_NAME%" ( echo [DIAGNOSTIC] Copying PDB file if it exists... set PDB_NAME=ddbc_bindings.cp%PYTAG%-%WHEEL_ARCH%.pdb if exist "%OUTPUT_DIR%\%PDB_NAME%" ( + echo [DIAGNOSTIC] Found PDB file: %PDB_NAME% + echo [DIAGNOSTIC] Copying PDB file to source directory... copy /Y "%OUTPUT_DIR%\%PDB_NAME%" "%SOURCE_DIR%\.." echo [SUCCESS] Copied %PDB_NAME% to %SOURCE_DIR%.. ) else ( From 9dbf24c3c934241d97cfd8b03416ecab68049992 Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Tue, 10 Jun 2025 09:07:55 +0530 Subject: [PATCH 3/6] fixed variable issue and push as artifact --- .gitignore | 6 +----- eng/pipelines/pr-validation-pipeline.yml | 7 +++++++ mssql_python/pybind/build.bat | 14 ++++++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 1ae348ea..ccbdf893 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,6 @@ # Ignore all files in the pybind/build directory mssql_python/pybind/build/ -mssql_python/pybind/pymsbuild/build/ - -# Ignore pyd file -mssql_python/ddbc_bindings.pyd - # Ignore pycache files and folders __pycache__/ **/__pycache__/ @@ -43,6 +38,7 @@ build/ # C extensions *.so *.pyd +*.pdb # IDE files .vscode/ diff --git a/eng/pipelines/pr-validation-pipeline.yml b/eng/pipelines/pr-validation-pipeline.yml index 171ba302..610904a9 100644 --- a/eng/pipelines/pr-validation-pipeline.yml +++ b/eng/pipelines/pr-validation-pipeline.yml @@ -58,6 +58,13 @@ jobs: publishLocation: 'Container' displayName: 'Publish pyd file as artifact' + - task: PublishBuildArtifacts@1 + inputs: + PathtoPublish: 'mssql_python/ddbc_bindings.cp313-amd64.pdb' + ArtifactName: 'ddbc_bindings' + publishLocation: 'Container' + displayName: 'Publish pdb file as artifact' + - task: PublishTestResults@2 condition: succeededOrFailed() inputs: diff --git a/mssql_python/pybind/build.bat b/mssql_python/pybind/build.bat index aa161f79..9f02de92 100644 --- a/mssql_python/pybind/build.bat +++ b/mssql_python/pybind/build.bat @@ -142,17 +142,19 @@ set OUTPUT_DIR=%BUILD_DIR%\Release if exist "%OUTPUT_DIR%\%PYD_NAME%" ( copy /Y "%OUTPUT_DIR%\%PYD_NAME%" "%SOURCE_DIR%\.." - echo [SUCCESS] Copied %PYD_NAME% to %SOURCE_DIR%.. + echo [SUCCESS] Copied %PYD_NAME% to %SOURCE_DIR%\.. echo [DIAGNOSTIC] Copying PDB file if it exists... set PDB_NAME=ddbc_bindings.cp%PYTAG%-%WHEEL_ARCH%.pdb - if exist "%OUTPUT_DIR%\%PDB_NAME%" ( - echo [DIAGNOSTIC] Found PDB file: %PDB_NAME% + echo [DEBUG] Computed PDB_NAME: !PDB_NAME! + + if exist "%OUTPUT_DIR%\!PDB_NAME!" ( + echo [DIAGNOSTIC] Found PDB file: "!PDB_NAME!" echo [DIAGNOSTIC] Copying PDB file to source directory... - copy /Y "%OUTPUT_DIR%\%PDB_NAME%" "%SOURCE_DIR%\.." - echo [SUCCESS] Copied %PDB_NAME% to %SOURCE_DIR%.. + copy /Y "%OUTPUT_DIR%\!PDB_NAME!" "%SOURCE_DIR%\.." + echo [SUCCESS] Copied !PDB_NAME! to %SOURCE_DIR%.. ) else ( - echo [WARNING] PDB file %PDB_NAME% not found in output directory. + echo [WARNING] PDB file !PDB_NAME! not found in output directory. ) setlocal enabledelayedexpansion From c0e8a6c9dc5cfad9e1c8a51dc7d37b202db27ecb Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Wed, 11 Jun 2025 10:19:09 +0530 Subject: [PATCH 4/6] add PDBs in build whl artifacts --- eng/pipelines/build-whl-pipeline.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eng/pipelines/build-whl-pipeline.yml b/eng/pipelines/build-whl-pipeline.yml index 1801c9f6..69c6cfa5 100644 --- a/eng/pipelines/build-whl-pipeline.yml +++ b/eng/pipelines/build-whl-pipeline.yml @@ -119,6 +119,14 @@ jobs: TargetFolder: '$(Build.ArtifactStagingDirectory)\all-pyds' displayName: 'Place PYD file into artifacts directory' + # Copy the built .pdb files to staging folder for artifacts + - task: CopyFiles@2 + inputs: + SourceFolder: '$(Build.SourcesDirectory)\mssql_python\pybind\build\$(targetArch)\py$(shortPyVer)\Release' + Contents: 'ddbc_bindings.cp$(shortPyVer)-*.pdbs' + TargetFolder: '$(Build.ArtifactStagingDirectory)\all-pdbs' + displayName: 'Place PDB file into artifacts directory' + # Build wheel package for the current architecture - script: | python -m pip install --upgrade pip From 2cb026fe18c2e03eae8c5b303f71c67c969741df Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Mon, 16 Jun 2025 17:31:53 +0530 Subject: [PATCH 5/6] Copilot - Update mssql_python/pybind/CMakeLists.txt Suggestion from copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- mssql_python/pybind/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mssql_python/pybind/CMakeLists.txt b/mssql_python/pybind/CMakeLists.txt index f5ca6e31..59907e6b 100644 --- a/mssql_python/pybind/CMakeLists.txt +++ b/mssql_python/pybind/CMakeLists.txt @@ -6,9 +6,9 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if (MSVC) - # Enable PDB generation for all target types - add_compile_options("$<$:/Zi>") - add_link_options("$<$:/DEBUG /OPT:REF /OPT:ICF>") + # Enable PDB generation for the ddbc_bindings target + target_compile_options(ddbc_bindings PRIVATE "$<$:/Zi>") + target_link_options(ddbc_bindings PRIVATE "$<$:/DEBUG /OPT:REF /OPT:ICF>") endif() # Detect platform From a46eb048a7804d38acdfa7556210426dab1fd424 Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Tue, 17 Jun 2025 12:05:12 +0530 Subject: [PATCH 6/6] revert copilot changes --- mssql_python/pybind/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mssql_python/pybind/CMakeLists.txt b/mssql_python/pybind/CMakeLists.txt index 59907e6b..f5ca6e31 100644 --- a/mssql_python/pybind/CMakeLists.txt +++ b/mssql_python/pybind/CMakeLists.txt @@ -6,9 +6,9 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if (MSVC) - # Enable PDB generation for the ddbc_bindings target - target_compile_options(ddbc_bindings PRIVATE "$<$:/Zi>") - target_link_options(ddbc_bindings PRIVATE "$<$:/DEBUG /OPT:REF /OPT:ICF>") + # Enable PDB generation for all target types + add_compile_options("$<$:/Zi>") + add_link_options("$<$:/DEBUG /OPT:REF /OPT:ICF>") endif() # Detect platform