Skip to main content

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.json for 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 macro
  • add_files(files, directory=None, kind=None): Add source files to compile
  • remove_files(files, directory=None): Remove source files from the build
  • set_main_file(fn, directory=None): Set the main extension source file
  • detect(hdr, lib, macros=None): Detect if a header exists and add library
  • build(name, nprocess=None): Build the extension module

Attributes

  • include_dirs: List of include directories
  • libdirs: List of library directories
  • macros: List of preprocessor macros
  • libs: List of libraries to link
  • extra_compile_args: Extra compiler arguments
  • extra_link_args: Extra linker arguments

Platform-Specific Notes

Windows (MSVC)

The builder automatically configures:

  • /O2 optimization
  • /std:c++20 standard
  • Debug symbols with PDB files
  • UTF-8 source encoding

Linux/macOS (GCC)

The builder automatically configures:

  • -O2 optimization
  • -std=c++20 standard
  • 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

py_cxx_builder-0.1.2.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_cxx_builder-0.1.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file py_cxx_builder-0.1.2.tar.gz.

File metadata

  • Download URL: py_cxx_builder-0.1.2.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

Hashes for py_cxx_builder-0.1.2.tar.gz
Algorithm Hash digest
SHA256 94fd6459f9fa4cf7e2c42cd498c04791839a1c26fc117eedf47054d89cca85d8
MD5 1fc1dff48fdf602b66e31e7d81e239c3
BLAKE2b-256 9d1699d7e3f531140bfc7c8168ec8abd3415a4ea226a64d4778b3fa3f8008101

See more details on using hashes here.

File details

Details for the file py_cxx_builder-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: py_cxx_builder-0.1.2-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

Hashes for py_cxx_builder-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b81e1802c9e144d30beee29314a97c9ee6853ddd556e04772d6d919b770b0b86
MD5 b1e7eb82eb5d75c3bf32fe73c17d79b9
BLAKE2b-256 a7d61aa631c6e73d3a27472a8e441893da85b4c8538a6d5b93c2f4220a256909

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page