Building from Source¶
This guide covers building libpresign from source for development or when pre-built wheels are not available for your platform.
Prerequisites¶
All Platforms¶
- Python 3.8 or higher with development headers
- CMake 3.15 or higher
- C++ compiler with C++11 support
- OpenSSL 3.x development files
Platform-Specific Requirements¶
- Install Visual Studio 2019 or later with C++ support
- Install CMake from https://cmake.org/download/
- Install OpenSSL:
- Set environment variables:
Building with pip¶
The simplest way to build from source:
# Clone the repository
git clone https://github.com/myk0la-b/libpresign.git
cd libpresign
# Build and install
pip install .
# Or for development (editable install)
pip install -e .
Building with uv¶
Using uv for faster builds:
# Clone the repository
git clone https://github.com/myk0la-b/libpresign.git
cd libpresign
# Create virtual environment
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Build and install
uv pip install -e .
Manual Build with CMake¶
For more control over the build process:
# Clone the repository
git clone https://github.com/myk0la-b/libpresign.git
cd libpresign
# Create build directory
mkdir build
cd build
# Configure
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_PYTHON_MODULE=ON
# Build
cmake --build . --config Release
# Install
cmake --install .
CMake Options¶
Option | Default | Description |
---|---|---|
BUILD_PYTHON_MODULE |
ON | Build Python extension module |
BUILD_SHARED_LIB |
OFF | Build shared library |
BUILD_STATIC_LIB |
OFF | Build static library |
CMAKE_BUILD_TYPE |
Release | Build type (Debug/Release) |
Building Wheels¶
Using cibuildwheel¶
Build wheels for multiple Python versions:
# Install cibuildwheel
pip install cibuildwheel
# Build for current platform
cibuildwheel --platform auto
# Build for specific platform
cibuildwheel --platform linux
cibuildwheel --platform macos
cibuildwheel --platform windows
Using build¶
Build a wheel for current Python:
# Install build
pip install build
# Build wheel and sdist
python -m build
# Wheels will be in dist/
ls dist/
Platform-Specific Notes¶
Linux¶
manylinux Builds¶
For maximum compatibility, build in manylinux containers:
# Build manylinux wheels
docker run --rm -v $(pwd):/io quay.io/pypa/manylinux2014_x86_64 \
/io/build-wheels-linux.sh
# For ARM64
docker run --rm -v $(pwd):/io quay.io/pypa/manylinux2014_aarch64 \
/io/build-wheels-linux.sh
Custom OpenSSL Location¶
If OpenSSL is installed in a non-standard location:
macOS¶
Universal2 Builds¶
Build for both Intel and Apple Silicon:
# Set architectures
export ARCHFLAGS="-arch x86_64 -arch arm64"
# Build universal2 wheel
pip install . --no-binary :all:
Code Signing¶
For distribution, sign the binary:
Windows¶
Debug Builds¶
For debugging on Windows:
# Configure for Debug
cmake .. -DCMAKE_BUILD_TYPE=Debug
# Build with debug symbols
cmake --build . --config Debug
Static Runtime¶
To link the C++ runtime statically:
Troubleshooting¶
OpenSSL Not Found¶
Python Headers Not Found¶
# Find Python include directory
python -c "import sysconfig; print(sysconfig.get_path('include'))"
# Install development headers
# Ubuntu/Debian
sudo apt-get install python3-dev
# RHEL/CentOS
sudo yum install python3-devel
# macOS (usually included)
# Windows (included with Python)
Compiler Errors¶
C++11 Support¶
Ensure your compiler supports C++11:
# GCC/Clang
g++ --version # Should be 4.8.1 or later
clang++ --version # Should be 3.3 or later
# Force C++11
export CXXFLAGS="-std=c++11"
Missing Dependencies¶
Testing Your Build¶
After building, verify the installation:
# Test import
import libpresign
print(f"Version: {libpresign.__version__}")
# Test functionality
url = libpresign.get(
access_key_id="test",
secret_access_key="test",
region="us-east-1",
bucket="test-bucket",
key="test.txt"
)
print(f"Generated URL: {url[:50]}...")
# Run test suite
pytest tests/
Advanced Building¶
Cross-Compilation¶
For cross-compiling to different architectures:
# Example: Build for ARM64 on x86_64
cmake .. \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++
Custom Build Scripts¶
The repository includes helper scripts:
build-cmake.sh
- Quick CMake buildbuild-wheels.sh
- Build wheels for all platformsbuild-macos.sh
- macOS-specific buildinstall-deps.sh
- Install build dependencies
Performance Optimizations¶
For maximum performance:
# Enable all optimizations
export CXXFLAGS="-O3 -march=native -mtune=native"
# Link-time optimization
cmake .. -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON
# Profile-guided optimization
cmake .. -DCMAKE_BUILD_TYPE=Release
make
./run_benchmarks # Generate profile data
cmake .. -DCMAKE_CXX_FLAGS="-fprofile-use"
make
Next Steps¶
After building libpresign: