Skip to content

Commit

Permalink
Merge pull request #9 from MetOffice/linker_wrapper
Browse files Browse the repository at this point in the history
Linker wrapper
  • Loading branch information
jasonjunweilyu authored Feb 3, 2025
2 parents 97e9cf5 + 75184cc commit 5bcc19d
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 313 deletions.
2 changes: 1 addition & 1 deletion fab
50 changes: 0 additions & 50 deletions infrastructure/build/fab/default/setup_cray.py

This file was deleted.

52 changes: 19 additions & 33 deletions infrastructure/build/fab/default/setup_gnu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@
'''

from fab.build_config import BuildConfig
from fab.tools import Category, Tool, ToolRepository


class Shell(Tool):
'''A simple wrapper that runs a shell script.
:name: the path to the script to run.
'''
def __init__(self, name: str):
super().__init__(name=name, exec_name=name,
category=Category.MISC)

def check_available(self):
return True
from fab.tools import Category, ToolRepository


def setup_gnu(build_config: BuildConfig):
Expand All @@ -38,24 +26,22 @@ def setup_gnu(build_config: BuildConfig):
]
gfortran.add_flags(flags)

# ATM a linker is not using a compiler wrapper, and so
# linker-mpif90-gfortran does not inherit from linker-gfortran.
# For now set the flags in both linkers:
bash = Shell("bash")
# ATM we don't use a shell when running a tool, and as such
# we can't directly use "$()" as parameter. So query these values using
# Fab's shell tool (doesn't really matter which shell we get, so just
# ask for the default):
shell = tr.get_default(Category.SHELL)
# We must remove the trailing new line, and create a list:
nc_flibs = bash.run(additional_parameters=["-c", "nf-config --flibs"],
capture_output=True).strip().split()

for linker_name in ["linker-gfortran", "linker-mpif90-gfortran"]:
linker = tr.get_tool(Category.LINKER, linker_name)
# ATM we don't use a shell when starting a tool, and as such
# we can't directly use "$()". So query these values using
# a dummy shell tool:

linker.add_lib_flags("netcdf", nc_flibs, silent_replace=True)
linker.add_lib_flags("yaxt", ["-lyaxt", "-lyaxt_c"])
linker.add_lib_flags("xios", ["-lxios"])
linker.add_lib_flags("hdf5", ["-lhdf5"])

# Always link with C++ libs
linker.add_post_lib_flags(["-lstdc++"])
nc_flibs = shell.run(additional_parameters=["-c", "nf-config --flibs"],
capture_output=True).strip().split()

# This will implicitly affect all gfortran based linkers, e.g.
# linker-mpif90-gfortran will use these flags as well.
linker = tr.get_tool(Category.LINKER, "linker-gfortran")
linker.add_lib_flags("netcdf", nc_flibs)
linker.add_lib_flags("yaxt", ["-lyaxt", "-lyaxt_c"])
linker.add_lib_flags("xios", ["-lxios"])
linker.add_lib_flags("hdf5", ["-lhdf5"])

# Always link with C++ libs
linker.add_post_lib_flags(["-lstdc++"])
48 changes: 19 additions & 29 deletions infrastructure/build/fab/default/setup_intel_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@
'''

from fab.build_config import BuildConfig
from fab.tools import Category, Tool, ToolRepository


class Shell(Tool):
'''A simple wrapper that runs a shell script.
:name: the path to the script to run.
'''
def __init__(self, name: str):
super().__init__(name=name, exec_name=name,
category=Category.MISC)

def check_available(self):
return True
from fab.tools import Category, ToolRepository


def setup_intel_classic(build_config: BuildConfig):
Expand Down Expand Up @@ -81,20 +69,22 @@ def setup_intel_classic(build_config: BuildConfig):

ifort.add_flags(compiler_flag_group)

# ATM a linker is not using a compiler wrapper, and so
# linker-mpif90-gfortran does not inherit from linker-gfortran.
# For now set the flags in both linkers:
bash = Shell("bash")
# ATM we don't use a shell when running a tool, and as such
# we can't directly use "$()" as parameter. So query these values using
# Fab's shell tool (doesn't really matter which shell we get, so just
# ask for the default):
shell = tr.get_default(Category.SHELL)
# We must remove the trailing new line, and create a list:
nc_flibs = bash.run(additional_parameters=["-c", "nf-config --flibs"],
capture_output=True).strip().split()

for linker_name in ["linker-ifort", "linker-mpif90-ifort"]:
linker = tr.get_tool(Category.LINKER, linker_name)
linker.add_lib_flags("netcdf", nc_flibs, silent_replace=True)
linker.add_lib_flags("yaxt", ["-lyaxt", "-lyaxt_c"])
linker.add_lib_flags("xios", ["-lxios"])
linker.add_lib_flags("hdf5", ["-lhdf5"])

# Always link with C++ libs
linker.add_post_lib_flags(["-lstdc++"])
nc_flibs = shell.run(additional_parameters=["-c", "nf-config --flibs"],
capture_output=True).strip().split()

# This will implicitly affect all ifort based linkers, e.g.
# linker-mpif90-ifort will use these flags as well.
linker = tr.get_tool(Category.LINKER, "linker-ifort")
linker.add_lib_flags("netcdf", nc_flibs)
linker.add_lib_flags("yaxt", ["-lyaxt", "-lyaxt_c"])
linker.add_lib_flags("xios", ["-lxios"])
linker.add_lib_flags("hdf5", ["-lhdf5"])

# Always link with C++ libs
linker.add_post_lib_flags(["-lstdc++"])
100 changes: 0 additions & 100 deletions infrastructure/build/fab/default/setup_intel_llvm.py

This file was deleted.

57 changes: 0 additions & 57 deletions infrastructure/build/fab/default/setup_nvidia.py

This file was deleted.

25 changes: 1 addition & 24 deletions infrastructure/build/fab/joerg_default/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python3

from fab.tools import Category, ToolRepository
from fab.tools import ToolRepository

from default.config import Config as DefaultConfig

Expand All @@ -15,26 +15,3 @@ def __init__(self):
super().__init__()
tr = ToolRepository()
tr.set_default_compiler_suite("gnu")

def setup_gnu(self, build_config):
'''Define default compiler flags for GNU.
'''

super().setup_gnu(build_config)
gfortran = ToolRepository().get_tool(Category.FORTRAN_COMPILER,
"gfortran")
gfortran.add_flags(
[
# The lib directory contains mpi.mod
'-I', ('/home/joerg/work/spack/var/spack/environments/'
'lfric-v0/.spack-env/view/lib'),
# mod_wait.mod
'-I', ('/home/joerg/work/spack/var/spack/environments/'
'lfric-v0/.spack-env/view/include'),
'-DITSUPERWORKS'
])
for linker_name in ["linker-gfortran", "linker-mpif90-gfortran"]:
gfortran = ToolRepository().get_tool(Category.LINKER, linker_name)
gfortran.add_post_lib_flags(
['-L', ('/home/joerg/work/spack/var/spack/'
'environments/lfric-v0/.spack-env/view/lib')])
Loading

0 comments on commit 5bcc19d

Please sign in to comment.