From a240aec21332a94574c9fef9c4b08e2d5f948c1d Mon Sep 17 00:00:00 2001 From: Connor Ward Date: Wed, 11 Dec 2024 14:26:21 +0000 Subject: [PATCH] Use a pip-installed libsupermesh --- firedrake/supermeshing.py | 6 ++++-- pyproject.toml | 2 ++ setup.py | 21 +++++++++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/firedrake/supermeshing.py b/firedrake/supermeshing.py index a1ce2cde17..14da853c55 100644 --- a/firedrake/supermeshing.py +++ b/firedrake/supermeshing.py @@ -1,7 +1,8 @@ # Code for projections and other fun stuff involving supermeshes. import firedrake import ctypes -import sys +import pathlib +import libsupermesh from firedrake.cython.supermeshimpl import assemble_mixed_mass_matrix as ammm, intersection_finder from firedrake.mg.utils import get_level from firedrake.petsc import PETSc @@ -428,7 +429,8 @@ def likely(cell_A): "complex_mode": 1 if complex_mode else 0 } - dirs = get_petsc_dir() + (sys.prefix, ) + libsupermesh_dir = pathlib.Path(libsupermesh.__path__._path[0]).absolute() + dirs = get_petsc_dir() + (libsupermesh_dir,) includes = ["-I%s/include" % d for d in dirs] libs = ["-L%s/lib" % d for d in dirs] libs = libs + ["-Wl,-rpath,%s/lib" % d for d in dirs] + ["-lpetsc", "-lsupermesh"] diff --git a/pyproject.toml b/pyproject.toml index fe15d8e7c1..f849865b38 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,7 @@ dependencies = [ "fenics-fiat @ git+https://github.com/firedrakeproject/fiat.git", "pyadjoint-ad @ git+https://github.com/dolfin-adjoint/pyadjoint.git", "loopy @ git+https://github.com/firedrakeproject/loopy.git@main", + "libsupermesh @ git+https://github.com/firedrakeproject/libsupermesh.git@connorjward/pip-install2", ] classifiers = [ "Development Status :: 5 - Production/Stable", @@ -98,6 +99,7 @@ requires = [ "mpi4py; python_version < '3.13'", "petsc4py", "rtree>=1.2", + "libsupermesh @ git+https://github.com/firedrakeproject/libsupermesh.git@connorjward/pip-install2", ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index cf970c1712..b30abd4b49 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ import pybind11 import petsc4py import rtree +import libsupermesh import pkgconfig from dataclasses import dataclass, field from setuptools import setup, find_packages, Extension @@ -145,6 +146,9 @@ def __getitem__(self, key): # In the next 2 linkages we are using `site.getsitepackages()[0]`, which isn't # guaranteed to be the correct place we could also use "$ORIGIN/../../lib_dir", # but that definitely doesn't work with editable installs. +# This is necessary because Python build isolation means that the compile-time +# library dirs (in the isolated build env) are different to the run-time +# library dirs (in the venv). # libspatialindex # example: @@ -159,15 +163,16 @@ def __getitem__(self, key): # libsupermesh # example: -# gcc -I/supermesh/include -# gcc /supermesh/supermesh.cpython-311-x86_64-linux-gnu.so \ +# gcc -Ipath/to/libsupermesh/include +# gcc path/to/libsupermesh/libsupermesh.cpython-311-x86_64-linux-gnu.so \ # -lsupermesh \ -# -Wl,-rpath,$ORIGIN/../../supermesh -supermesh_ = ExternalDependency( - include_dirs=[f"{sys.prefix}/include"], - library_dirs=[f"{sys.prefix}/lib"], +# -Wl,-rpath,$ORIGIN/../../libsupermesh +libsupermesh_dir = Path(libsupermesh.__path__._path[0]).absolute() +libsupermesh_ = ExternalDependency( + include_dirs=[str(libsupermesh_dir.joinpath("include"))], + library_dirs=[str(libsupermesh_dir.joinpath("lib"))], + runtime_library_dirs=[os.path.join(site.getsitepackages()[0], "libsupermesh", "lib")], libraries=["supermesh"], - runtime_library_dirs=[f"{sys.prefix}/lib"], ) # The following extensions need to be linked accordingly: @@ -221,7 +226,7 @@ def extensions(): name="firedrake.cython.supermeshimpl", language="c", sources=[os.path.join("firedrake", "cython", "supermeshimpl.pyx")], - **(petsc_ + numpy_ + supermesh_) + **(petsc_ + numpy_ + libsupermesh_) )) # pyop2/sparsity.pyx: petsc, numpy, cython_list.append(Extension(