add bzip2 package (#28)
Static build of bzip2 1.0.8 (libbz2.a + bzlib.h) for use as a vendored dependency in openpilot replay/cabana tools. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
45
bzip2/build.sh
Executable file
45
bzip2/build.sh
Executable file
@@ -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"
|
||||
10
bzip2/bzip2/__init__.py
Normal file
10
bzip2/bzip2/__init__.py
Normal file
@@ -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"
|
||||
15
bzip2/pyproject.toml
Normal file
15
bzip2/pyproject.toml
Normal file
@@ -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/**/*"]
|
||||
61
bzip2/setup.py
Normal file
61
bzip2/setup.py
Normal file
@@ -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()
|
||||
@@ -1,5 +1,6 @@
|
||||
[tool.uv.workspace]
|
||||
members = [
|
||||
"bzip2",
|
||||
"capnproto",
|
||||
"cppcheck",
|
||||
"eigen",
|
||||
|
||||
Reference in New Issue
Block a user