Build C++ extensions for Python with cross-platform support (MSVC/GCC)
Project description
py-cxx-builder
A Python library for building C++ extensions with cross-platform support for MSVC (Windows) and GCC (Linux/macOS).
Installation
pip install py-cxx-builder
Features
- Cross-platform support: MSVC on Windows, GCC on Linux/macOS
- Automatic detection of Python include directories
- Parallel compilation using multiprocessing
- Static library generation before linking
- Automatic dependency detection (header files)
- Generation of
compile_commands.jsonfor IDE integration
Quick Start
from py_cxx_builder import CXXBuilder
import glob
# Create a builder instance
builder = CXXBuilder()
# Add macros
builder.add_macro('MY_MACRO', 1)
# Add source files
builder.add_files(['src/module.cpp', 'src/utils.cpp'])
# Set the main extension file
builder.set_main_file('src/main.cpp')
# Add include directories
builder.include_dirs.append('include')
# Build the extension
builder.build('my_extension')
API Reference
CXXBuilder
The main class for building C++ extensions.
Methods
add_macro(key, value=None): Add a preprocessor macroadd_files(files, directory=None, kind=None): Add source files to compileremove_files(files, directory=None): Remove source files from the buildset_main_file(fn, directory=None): Set the main extension source filedetect(hdr, lib, macros=None): Detect if a header exists and add librarybuild(name, nprocess=None): Build the extension module
Attributes
include_dirs: List of include directorieslibdirs: List of library directoriesmacros: List of preprocessor macroslibs: List of libraries to linkextra_compile_args: Extra compiler argumentsextra_link_args: Extra linker arguments
Platform-Specific Notes
Windows (MSVC)
The builder automatically configures:
/O2optimization/std:c++20standard- Debug symbols with PDB files
- UTF-8 source encoding
Linux/macOS (GCC)
The builder automatically configures:
-O2optimization-std=c++20standard- Position-independent code (
-fpic) - Dead code stripping
Requirements
- Python >= 3.10
- setuptools >= 61.0
- A C++ compiler (MSVC on Windows, GCC on Linux/macOS)
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_cxx_builder-0.1.1.tar.gz.
File metadata
- Download URL: py_cxx_builder-0.1.1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a68a289a4366a5673d2c728c027055daeee678c177c31959abde67e7d33682b6
|
|
| MD5 |
2e47b72cd4ed6ee6973d2ff0d53debdd
|
|
| BLAKE2b-256 |
720e7690064f666d08f0e4e98cd303b80c43a899353e068da9fc6631c876c47d
|
File details
Details for the file py_cxx_builder-0.1.1-py3-none-any.whl.
File metadata
- Download URL: py_cxx_builder-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b27195a5919ea7e6641507f4209a331fd2a249f5a741127e5fc342ef36463c4
|
|
| MD5 |
c19b2ccdb42e9035d2632160beb48601
|
|
| BLAKE2b-256 |
cefa17e2aa43b2e0ec3e8730bff659023038da104405d600413d0a3feaca2fe3
|