diff --git a/eigen/build.sh b/eigen/build.sh new file mode 100755 index 0000000..6a55892 --- /dev/null +++ b/eigen/build.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -e + +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" +cd "$DIR" + +VERSION="3.4.0" +INSTALL_DIR="$DIR/eigen/install" + +# Idempotent: skip if already present +if [ -d "$INSTALL_DIR/eigen3/Eigen" ]; then + echo "eigen already present, skipping download." + exit 0 +fi + +TARBALL="eigen-${VERSION}.tar.gz" +URL="https://gitlab.com/libeigen/eigen/-/archive/${VERSION}/${TARBALL}" + +echo "Downloading Eigen ${VERSION} ..." +curl -fSL -o "$TARBALL" "$URL" + +echo "Extracting headers ..." +rm -rf "$INSTALL_DIR" +mkdir -p "$INSTALL_DIR/eigen3" + +# Extract only the Eigen/ and unsupported/Eigen/ header directories +tar --strip-components=1 -xzf "$TARBALL" -C "$INSTALL_DIR/eigen3" \ + "eigen-${VERSION}/Eigen" \ + "eigen-${VERSION}/unsupported" + +rm -f "$TARBALL" + +echo "Installed eigen to $INSTALL_DIR" +du -sh "$INSTALL_DIR" diff --git a/eigen/eigen/__init__.py b/eigen/eigen/__init__.py new file mode 100644 index 0000000..5b1151e --- /dev/null +++ b/eigen/eigen/__init__.py @@ -0,0 +1,9 @@ +import os + +DIR = os.path.join(os.path.dirname(__file__), "install") +INCLUDE_DIR = DIR +LIB_DIR = DIR # header-only; no libraries + + +def smoketest(): + assert os.path.isdir(os.path.join(DIR, "eigen3", "Eigen")), "Eigen headers not found" diff --git a/eigen/pyproject.toml b/eigen/pyproject.toml new file mode 100644 index 0000000..8928294 --- /dev/null +++ b/eigen/pyproject.toml @@ -0,0 +1,15 @@ +[build-system] +requires = ["setuptools>=64", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "eigen" +version = "3.4.0" +description = "Eigen C++ linear algebra headers" +requires-python = ">=3.8" + +[tool.setuptools.packages.find] +include = ["eigen*"] + +[tool.setuptools.package-data] +eigen = ["install/**/*"] diff --git a/eigen/setup.py b/eigen/setup.py new file mode 100644 index 0000000..de858b5 --- /dev/null +++ b/eigen/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 BuildEigen(build_py): + """Run build.sh to download Eigen headers before collecting package data.""" + + def run(self): + pkg_dir = os.path.dirname(os.path.abspath(__file__)) + marker = os.path.join(pkg_dir, "eigen", "install", "eigen3", "Eigen") + + if not os.path.isdir(marker): + build_script = os.path.join(pkg_dir, "build.sh") + subprocess.check_call(["bash", build_script], cwd=pkg_dir) + + super().run() + + +cmdclass = {"build_py": BuildEigen} + +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()