44# Python bindings directory
55PYTHON_DIR := bindings/python
66
7+ # Auto-detect CPU cores and cap at reasonable limit to avoid thread exhaustion
8+ # Can be overridden: make python-dev JOBS=4
9+ NPROC := $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 8)
10+ JOBS ?= $(shell echo $$(($(NPROC ) > 16 ? 16 : $(NPROC ) ) ) )
11+
712# Check if sccache is available and set RUSTC_WRAPPER accordingly
813SCCACHE := $(shell which sccache 2>/dev/null)
914ifdef SCCACHE
@@ -88,12 +93,12 @@ sccache-stop: ## Stop the sccache server
8893
8994# Python bindings (maturin) targets
9095python-dev : # # Build Python bindings in development mode (fast, debug build)
91- @echo " Building Python bindings in development mode..."
92- @cd $(PYTHON_DIR ) && maturin develop
96+ @echo " Building Python bindings in development mode (using $( JOBS ) parallel jobs with sccache) ..."
97+ @cd $(PYTHON_DIR ) && CARGO_BUILD_JOBS= $( JOBS ) maturin develop
9398
9499python-build : # # Build Python wheel (release mode with vendored OpenSSL)
95- @echo " Building Python wheel (release, vendored OpenSSL)..."
96- @cd $(PYTHON_DIR ) && maturin build --release --out dist --features vendored-openssl
100+ @echo " Building Python wheel (release, vendored OpenSSL, using $( JOBS ) parallel jobs with sccache )..."
101+ @cd $(PYTHON_DIR ) && CARGO_BUILD_JOBS= $( JOBS ) maturin build --release --out dist --features vendored-openssl
97102
98103python-build-release : python-build # # Alias for python-build
99104
@@ -118,7 +123,7 @@ python-test: ## Run Python tests
118123
119124python-check : # # Check Python package with twine
120125 @echo " Checking Python package..."
121- @cd $(PYTHON_DIR ) && maturin build --release --out dist --features vendored-openssl
126+ @cd $(PYTHON_DIR ) && CARGO_BUILD_JOBS= $( JOBS ) maturin build --release --out dist --features vendored-openssl
122127 @pip install twine 2> /dev/null || true
123128 @twine check $(PYTHON_DIR ) /dist/*
124129 @echo " Python package check passed!"
0 commit comments