diff --git a/bzip2/build.sh b/bzip2/build.sh new file mode 100755 index 0000000..75ab2c7 --- /dev/null +++ b/bzip2/build.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -e + +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" +cd "$DIR" + +VERSION="1.0.8" +INSTALL_DIR="$DIR/bzip2/install" + +# Idempotent: skip if already built +if [ -f "$INSTALL_DIR/lib/libbz2.a" ]; then + echo "bzip2 already present, skipping build." + exit 0 +fi + +NJOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)" + +# Download +if [ ! -d "bzip2-src" ]; then + curl -L "https://sourceware.org/pub/bzip2/bzip2-${VERSION}.tar.gz" -o bzip2.tar.gz + mkdir -p bzip2-src + tar xzf bzip2.tar.gz -C bzip2-src --strip-components=1 + rm bzip2.tar.gz +fi + +# Build static library with -fPIC +cd bzip2-src +make -j"$NJOBS" libbz2.a CC="${CC:-cc}" CFLAGS="-Wall -Winline -O2 -fPIC -D_FILE_OFFSET_BITS=64" +cd "$DIR" + +# Copy to package install dir +rm -rf "$INSTALL_DIR" +mkdir -p "$INSTALL_DIR"/{lib,include} + +# Library +cp bzip2-src/libbz2.a "$INSTALL_DIR/lib/" + +# Headers +cp bzip2-src/bzlib.h "$INSTALL_DIR/include/" + +# Clean up +rm -rf bzip2-src + +echo "Installed bzip2 to $INSTALL_DIR" +du -sh "$INSTALL_DIR" diff --git a/bzip2/bzip2/__init__.py b/bzip2/bzip2/__init__.py new file mode 100644 index 0000000..49c7fbd --- /dev/null +++ b/bzip2/bzip2/__init__.py @@ -0,0 +1,10 @@ +import os + +DIR = os.path.join(os.path.dirname(__file__), "install") +LIB_DIR = os.path.join(DIR, "lib") +INCLUDE_DIR = os.path.join(DIR, "include") + + +def smoketest(): + assert os.path.isfile(os.path.join(LIB_DIR, "libbz2.a")), "libbz2.a not found" + assert os.path.isfile(os.path.join(INCLUDE_DIR, "bzlib.h")), "bzlib.h not found" diff --git a/bzip2/pyproject.toml b/bzip2/pyproject.toml new file mode 100644 index 0000000..b7bbaa6 --- /dev/null +++ b/bzip2/pyproject.toml @@ -0,0 +1,15 @@ +[build-system] +requires = ["setuptools>=64", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "bzip2" +version = "1.0.8" +description = "bzip2 compression library (static build)" +requires-python = ">=3.8" + +[tool.setuptools.packages.find] +include = ["bzip2*"] + +[tool.setuptools.package-data] +bzip2 = ["install/**/*"] diff --git a/bzip2/setup.py b/bzip2/setup.py new file mode 100644 index 0000000..7dd2b7b --- /dev/null +++ b/bzip2/setup.py @@ -0,0 +1,61 @@ +import os +import platform +import subprocess + +from setuptools.command.build_py import build_py + +try: + from wheel.bdist_wheel import bdist_wheel +except ImportError: + bdist_wheel = None + + +class BuildBzip2(build_py): + """Run build.sh to compile bzip2 before collecting package data.""" + + def run(self): + pkg_dir = os.path.dirname(os.path.abspath(__file__)) + marker = os.path.join(pkg_dir, "bzip2", "install", "lib", "libbz2.a") + + if not os.path.exists(marker): + build_script = os.path.join(pkg_dir, "build.sh") + subprocess.check_call(["bash", build_script], cwd=pkg_dir) + + super().run() + + +cmdclass = {"build_py": BuildBzip2} + +if bdist_wheel is not None: + + class PlatformWheel(bdist_wheel): + """Produce a platform-specific, Python-version-agnostic wheel.""" + + def finalize_options(self): + super().finalize_options() + self.root_is_pure = False + + def get_tag(self): + system = platform.system() + machine = platform.machine() + + if system == "Linux": + plat = f"linux_{machine}" + elif system == "Darwin": + plat = "macosx_11_0_arm64" + else: + plat = f"{system.lower()}_{machine}" + + return "py3", "none", plat + + cmdclass["bdist_wheel"] = PlatformWheel + + +def setup(): + from setuptools import setup as _setup + + _setup(cmdclass=cmdclass) + + +if __name__ == "__main__": + setup() diff --git a/pyproject.toml b/pyproject.toml index eaea3f3..7f3f202 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,6 @@ [tool.uv.workspace] members = [ + "bzip2", "capnproto", "cppcheck", "eigen",