Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 106 additions & 3 deletions mssql_python/pybind/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Build Instructions for Developers

This README provides instructions to build the DDBC Bindings PYD for your system (supports Windows x64 and arm64).
This README provides instructions to build the DDBC Bindings for your system and documents the platform-specific dependencies.

## **Key Architecture Handling**

1. **Architecture Normalization** (from `mssql_python/ddbc_bindings.py`):
- Windows: `win64/amd64/x64` → `x64`, `win32/x86` → `x86`, `arm64` → `arm64`
- macOS: Always uses `universal2` for distribution
- Linux: `x64/amd64` → `x86_64`, `arm64/aarch64` → `arm64`

2. **Build System Support**:
- CMake handles universal binaries for macOS (`arm64;x86_64`)
- Windows `mssql_python/pybind/build.bat` supports x64, x86, and ARM64
- Linux builds are distribution-aware (Debian/Ubuntu vs RHEL)

3. **Runtime Loading**:
- `LoadDriverLibrary()` in `mssql_python/pybind/ddbc_bindings.cpp` handles platform-specific loading
- Windows uses `LoadLibraryW()`
- macOS/Linux uses `dlopen()`

---

## Building on Windows
> Supporting Windows x64 & ARM64 only
Expand All @@ -25,7 +44,7 @@ This README provides instructions to build the DDBC Bindings PYD for your system
- The script will:
- Clean up existing build directories
- Detect VS Build Tools Installation, and start compilation for your Python version and Windows architecture
- Compile `ddbc_bindings.cpp` using CMake and create properly versioned PYD file (`ddbc_bindings.cp313-amd64.pyd`)
- Compile `mssql_python/pybind/ddbc_bindings.cpp` using CMake and create properly versioned PYD file (`ddbc_bindings.cp313-amd64.pyd`)
- Move the built PYD file to the parent `mssql_python` directory

## Building on MacOS
Expand Down Expand Up @@ -59,6 +78,90 @@ This README provides instructions to build the DDBC Bindings PYD for your system
- Clean any existing build artifacts
- Detect system architecture
- Configure CMake with appropriate include/library paths
- Compile `ddbc_bindings.cpp` using CMake
- Compile `mssql_python/pybind/ddbc_bindings.cpp` using CMake
- Generate the `.so` file (e.g., `ddbc_bindings.cp313-universal2.so`)
- Copy the output SO file to the parent `mssql_python` directory

## Architecture Dependencies Summary

### **Directory Structure**
```
mssql_python/
├── libs/
│ ├── windows/
│ │ ├── x64/
│ │ ├── x86/
│ │ └── arm64/
│ ├── macos/
│ │ ├── arm64/lib/
│ │ └── x86_64/lib/
│ └── linux/
│ ├── debian_ubuntu/
│ │ ├── x86_64/lib/
│ │ └── arm64/lib/
│ └── rhel/
│ ├── x86_64/lib/
│ └── arm64/lib/
└── ddbc_bindings.cp{python_version}-{architecture}.{extension}
```

### **Windows (.dll files)**
Windows builds depend on these DLLs for different architectures:

**x64 (amd64):**
- `msodbcsql18.dll` - Main driver
- `msodbcdiag18.dll` - Diagnostic library
- `mssql-auth.dll` - Authentication library (for Entra ID)
- `vcredist/msvcp140.dll` - Visual C++ runtime (from vcredist)

**x86 (win32):**
- `msodbcsql18.dll` - Main driver
- `msodbcdiag18.dll` - Diagnostic library
- `mssql-auth.dll` - Authentication library
- `vcredist/msvcp140.dll` - Visual C++ runtime (from vcredist)

**ARM64:**
- `msodbcsql18.dll` - Main driver
- `msodbcdiag18.dll` - Diagnostic library
- `mssql-auth.dll` - Authentication library
- `vcredist/msvcp140.dll` - Visual C++ runtime (from vcredist)

### **macOS (.dylib files)**
macOS builds use universal2 binaries and depend on:

**Packaged Dependencies (arm64 & x86_64):**
- `libmsodbcsql.18.dylib` - Main driver
- `libodbcinst.2.dylib` - Installer library

### **Linux (.so files)**
Linux builds support multiple distributions:

**Debian/Ubuntu x86_64:**
- `libmsodbcsql-18.5.so.1.1` - Main driver
- `libodbcinst.so.2` - Installer library

**Debian/Ubuntu ARM64:**
- `libmsodbcsql-18.5.so.1.1` - Main driver
- `libodbcinst.so.2` - Installer library

**RHEL/CentOS x86_64:**
- `libmsodbcsql-18.5.so.1.1` - Main driver
- `libodbcinst.so.2` - Installer library

**RHEL/CentOS ARM64:**
- `libmsodbcsql-18.5.so.1.1` - Main driver
- `libodbcinst.so.2` - Installer library

## **Python Extension Modules**
Your build system generates architecture-specific Python extension modules:

**Naming Convention:** `ddbc_bindings.cp{python_version}-{architecture}.{extension}`

Examples:
- Windows x64: `ddbc_bindings.cp311-amd64.pyd`
- Windows x86: `ddbc_bindings.cp311-win32.pyd`
- Windows ARM64: `ddbc_bindings.cp311-arm64.pyd`
- macOS Universal: `ddbc_bindings.cp311-universal2.so`
- Linux x86_64: `ddbc_bindings.cp311-x86_64.so`
- Linux ARM64: `ddbc_bindings.cp311-arm64.so`

2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import pytest
import os
from mssql_python import connect, ddbc_bindings
from mssql_python import connect
import time

def pytest_configure(config):
Expand Down
Loading