Skip to content

Commit

Permalink
MacOS Semolina CLT 15 potential fix (#3171)
Browse files Browse the repository at this point in the history
Pass the right linker flags to command line tools V15 on Mac.
  • Loading branch information
JDBetteridge authored and pbrubeck committed Oct 25, 2023
1 parent 09e2492 commit 23892f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
13 changes: 8 additions & 5 deletions docs/source/download.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ current directory. Run::

python3 firedrake-install --help

for a full list of install options. In particular, you may
wish to customise the set of options used to build PETSc. To do so,
set the environment variable ``PETSC_CONFIGURE_OPTIONS`` before
running ``firedrake-install``. You can see the set of options passed
to PETSc by providing the flag ``--show-petsc-configure-options``.
for a full list of install options. In particular, you may wish to
customise PETSc by adding packages (for instance ``--download-fftw``).
To do so, set the environment variable ``PETSC_CONFIGURE_OPTIONS``
before running ``firedrake-install``. However, some configuration
options (for instance ``--LDFLAGS`` and ``--CFLAGS``) should not be set
in ``PETSC_CONFIGURE_OPTIONS`` as they are set by the install script.
You can see the set of options passed to PETSc by providing the flag
``--show-petsc-configure-options``.

You will need to activate the venv in each shell from which you
use Firedrake::
Expand Down
19 changes: 17 additions & 2 deletions scripts/firedrake-install
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ def get_minimal_petsc_packages():


def get_petsc_options(minimal=False):
# The logic in this function is getting out of hand...
petsc_options = {"--with-fortran-bindings=0",
"--with-debugging=0",
"--with-shared-libraries=1",
Expand All @@ -726,6 +727,10 @@ def get_petsc_options(minimal=False):
petsc_options.add("--download-" + pkg)
if osname == "Darwin":
petsc_options.add("--with-x=0")
# These three lines are used to inspect the MacOS Command Line Tools (CLT) version
cmd = ["pkgutil", "--pkg-info=com.apple.pkg.CLTools_Executables"]
output = subprocess.run(cmd, stdout=subprocess.PIPE, encoding="UTF-8")
clt = {k.strip(): v.strip() for k, v in [line.split(':') for line in output.stdout.split('\n') if line]}
elif osname == "Linux":
# PETSc requires cmake version 3.18.1 or higher.
petsc_options.add("--download-cmake")
Expand Down Expand Up @@ -776,18 +781,28 @@ def get_petsc_options(minimal=False):
petsc_options.add("--download-openblas-make-options='USE_THREAD=0 USE_LOCKING=1 USE_OPENMP=0'")
if osname == "Darwin":
petsc_options.add("--CFLAGS=-Wno-implicit-function-declaration")
if Version(clt["version"]) >= Version("15"):
# CLT >= 15 requires legacy linking behaviour
petsc_options.add("--LDFLAGS=-Wl,-ld_classic")
elif options.get("with_blas") is not None:
petsc_options.add("--with-blaslapack-dir={}".format(options["with_blas"]))
petsc_options.add("--LDFLAGS=-Wl,-rpath,{0}/lib -L{0}/lib".format(options["with_blas"]))
if osname == "Darwin":
petsc_options.add("--CFLAGS=-I{}/include -Wno-implicit-function-declaration".format(options["with_blas"]))
if Version(clt["version"]) >= Version("15"):
# CLT >= 15 requires legacy linking behaviour
petsc_options.add("--LDFLAGS=-Wl,-ld_classic,-rpath,{0}/lib -L{0}/lib".format(options["with_blas"]))
else:
petsc_options.add("--CFLAGS=-I{}/include".format(options["with_blas"]))
petsc_options.add("--LDFLAGS=-Wl,-rpath,{0}/lib -L{0}/lib".format(options["with_blas"]))
elif osname == "Darwin":
brew_blas_prefix = check_output(["brew", "--prefix", "openblas"])[:-1]
petsc_options.add("--with-blaslapack-dir={}".format(brew_blas_prefix))
petsc_options.add("--CFLAGS=-I{}/include -Wno-implicit-function-declaration".format(brew_blas_prefix))
petsc_options.add("--LDFLAGS=-Wl,-rpath,{0}/lib -L{0}/lib -L{1}".format(brew_blas_prefix, brew_gcc_libdir()))
if Version(clt["version"]) >= Version("15"):
# CLT >= 15 requires legacy linking behaviour
petsc_options.add("--LDFLAGS=-Wl,-ld_classic,-rpath,{0}/lib -L{0}/lib -L{1}".format(brew_blas_prefix, brew_gcc_libdir()))
else:
petsc_options.add("--LDFLAGS=-Wl,-rpath,{0}/lib -L{0}/lib -L{1}".format(brew_blas_prefix, brew_gcc_libdir()))

if not minimal:
for option in shlex.split(os.environ.get("PETSC_CONFIGURE_OPTIONS", "")):
Expand Down

0 comments on commit 23892f7

Please sign in to comment.