Skip to content

Commit 453faeb

Browse files
FEAT: PDB File generation to make Private symbols for DDBC Bindings (#71)
### Summary This pull request introduces changes to improve debugging support for the `ddbc_bindings` project by enabling PDB (Program Database) file generation and ensuring proper handling of these files during the build process. The changes primarily focus on updating the CMake configuration and build script. ### Debugging Support Improvements: * **Enabled PDB generation for MSVC builds in Release mode**: Added compile and link options in `CMakeLists.txt` to ensure PDB files are generated when building with MSVC in Release mode. (`mssql_python/pybind/CMakeLists.txt`, [mssql_python/pybind/CMakeLists.txtR8-R13](diffhunk://#diff-dbb5892fbbb28149d1639664797cf3adb48ced28ec11aba95f2e2b338ca46badR8-R13)) * **Configured PDB properties for `ddbc_bindings` target**: Set properties in `CMakeLists.txt` to specify the PDB file name and output directory for the `ddbc_bindings` target. (`mssql_python/pybind/CMakeLists.txt`, [mssql_python/pybind/CMakeLists.txtR113-R119](diffhunk://#diff-dbb5892fbbb28149d1639664797cf3adb48ced28ec11aba95f2e2b338ca46badR113-R119)) * **Handled PDB file copying in build script**: Updated `build.bat` to check for the existence of the PDB file after the build, copy it to the appropriate directory if found, and log diagnostic messages for success or warnings if the file is missing. (`mssql_python/pybind/build.bat`, [mssql_python/pybind/build.batR147-R155](diffhunk://#diff-a08055320153458138a68ccff086b540cb080819b76f921664caa782603a4c2eR147-R155)) ### Issue Reference Fixes [AB#37472](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/37472) ### Solution Implemented <!-- Explain the fix implemented --> - [x] Updated `CMakeLists` and `build.bat` to generate a PDB file for release ### Checklist - [x] **Tests Passed** (if applicable) - [x] **Code is formatted** - [x] **Docs Updated** (if necessary) ### Testing Performed <!-- How was this fix tested? --> - [x] Unit Tests - [x] Manual Testing - [x] Python Version: `3.13.3` - [x] OS: `Windows` --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 77c287e commit 453faeb

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# Ignore all files in the pybind/build directory
22
mssql_python/pybind/build/
33

4-
mssql_python/pybind/pymsbuild/build/
5-
6-
# Ignore pyd file
7-
mssql_python/ddbc_bindings.pyd
8-
94
# Ignore pycache files and folders
105
__pycache__/
116
**/__pycache__/
@@ -43,6 +38,7 @@ build/
4338
# C extensions
4439
*.so
4540
*.pyd
41+
*.pdb
4642

4743
# IDE files
4844
.vscode/

eng/pipelines/build-whl-pipeline.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ jobs:
126126
TargetFolder: '$(Build.ArtifactStagingDirectory)\all-pyds'
127127
displayName: 'Place PYD file into artifacts directory'
128128

129+
# Copy the built .pdb files to staging folder for artifacts
130+
- task: CopyFiles@2
131+
inputs:
132+
SourceFolder: '$(Build.SourcesDirectory)\mssql_python\pybind\build\$(targetArch)\py$(shortPyVer)\Release'
133+
Contents: 'ddbc_bindings.cp$(shortPyVer)-*.pdbs'
134+
TargetFolder: '$(Build.ArtifactStagingDirectory)\all-pdbs'
135+
displayName: 'Place PDB file into artifacts directory'
136+
129137
# Build wheel package for the current architecture
130138
- script: |
131139
python -m pip install --upgrade pip

eng/pipelines/pr-validation-pipeline.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ jobs:
6262
publishLocation: 'Container'
6363
displayName: 'Publish pyd file as artifact'
6464

65+
- task: PublishBuildArtifacts@1
66+
inputs:
67+
PathtoPublish: 'mssql_python/ddbc_bindings.cp313-amd64.pdb'
68+
ArtifactName: 'ddbc_bindings'
69+
publishLocation: 'Container'
70+
displayName: 'Publish pdb file as artifact'
71+
6572
- task: PublishTestResults@2
6673
condition: succeededOrFailed()
6774
inputs:

mssql_python/pybind/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ project(ddbc_bindings)
55
set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77

8+
if (MSVC)
9+
# Enable PDB generation for all target types
10+
add_compile_options("$<$<CONFIG:Release>:/Zi>")
11+
add_link_options("$<$<CONFIG:Release>:/DEBUG /OPT:REF /OPT:ICF>")
12+
endif()
13+
814
# Detect platform
915
if(WIN32)
1016
set(PLATFORM_NAME "windows")
@@ -19,6 +25,7 @@ endif()
1925
# Set default architecture if not provided
2026
if(NOT DEFINED ARCHITECTURE)
2127
if(WIN32)
28+
# Default to x64 for Windows
2229
set(ARCHITECTURE "win64")
2330
elseif(APPLE)
2431
# Check if we're on Apple Silicon or Intel
@@ -207,6 +214,13 @@ set_target_properties(ddbc_bindings PROPERTIES
207214
OUTPUT_NAME "ddbc_bindings.cp${PYTHON_VERSION}-${WHEEL_ARCH}"
208215
SUFFIX "${MODULE_EXTENSION}"
209216
)
217+
# Ensure PDB is generated in Release
218+
set_target_properties(ddbc_bindings PROPERTIES
219+
COMPILE_PDB_NAME "ddbc_bindings.cp${PYTHON_VERSION}-${WHEEL_ARCH}"
220+
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
221+
PDB_NAME "ddbc_bindings.cp${PYTHON_VERSION}-${WHEEL_ARCH}"
222+
PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
223+
)
210224

211225
# Include directories for all architectures
212226
if(NOT DEFINED ODBC_INCLUDE_DIR)

mssql_python/pybind/build.bat

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,20 @@ set OUTPUT_DIR=%BUILD_DIR%\Release
142142

143143
if exist "%OUTPUT_DIR%\%PYD_NAME%" (
144144
copy /Y "%OUTPUT_DIR%\%PYD_NAME%" "%SOURCE_DIR%\.."
145-
echo [SUCCESS] Copied %PYD_NAME% to %SOURCE_DIR%..
145+
echo [SUCCESS] Copied %PYD_NAME% to %SOURCE_DIR%\..
146+
147+
echo [DIAGNOSTIC] Copying PDB file if it exists...
148+
set PDB_NAME=ddbc_bindings.cp%PYTAG%-%WHEEL_ARCH%.pdb
149+
echo [DEBUG] Computed PDB_NAME: !PDB_NAME!
150+
151+
if exist "%OUTPUT_DIR%\!PDB_NAME!" (
152+
echo [DIAGNOSTIC] Found PDB file: "!PDB_NAME!"
153+
echo [DIAGNOSTIC] Copying PDB file to source directory...
154+
copy /Y "%OUTPUT_DIR%\!PDB_NAME!" "%SOURCE_DIR%\.."
155+
echo [SUCCESS] Copied !PDB_NAME! to %SOURCE_DIR%..
156+
) else (
157+
echo [WARNING] PDB file !PDB_NAME! not found in output directory.
158+
)
146159

147160
setlocal enabledelayedexpansion
148161
for %%I in ("%SOURCE_DIR%..") do (

0 commit comments

Comments
 (0)