Skip to content

Commit d62d108

Browse files
committed
add option --search-path-linker to control how linker options at build time
1 parent 485843d commit d62d108

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

easybuild/tools/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def mk_full_default_path(name, prefix=DEFAULT_PREFIX):
262262
'rpath_override_dirs',
263263
'required_linked_shared_libs',
264264
'search_path_cpp_headers',
265+
'search_path_linker',
265266
'skip',
266267
'software_commit',
267268
'stop',

easybuild/tools/options.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@
101101
from easybuild.tools.run import run_shell_cmd
102102
from easybuild.tools.package.utilities import avail_package_naming_schemes
103103
from easybuild.tools.toolchain.compiler import DEFAULT_OPT_LEVEL, OPTARCH_MAP_CHAR, OPTARCH_SEP, Compiler
104-
from easybuild.tools.toolchain.toolchain import SEARCH_PATH_CPP_HEADERS, DEFAULT_SEARCH_PATH_CPP_HEADERS
105-
from easybuild.tools.toolchain.toolchain import SYSTEM_TOOLCHAIN_NAME
104+
from easybuild.tools.toolchain.toolchain import DEFAULT_SEARCH_PATH_CPP_HEADERS, DEFAULT_SEARCH_PATH_LINKER
105+
from easybuild.tools.toolchain.toolchain import SEARCH_PATH_CPP_HEADERS, SEARCH_PATH_LINKER, SYSTEM_TOOLCHAIN_NAME
106106
from easybuild.tools.repository.repository import avail_repositories
107107
from easybuild.tools.systemtools import DARWIN, UNKNOWN, check_python_version, get_cpu_architecture, get_cpu_family
108108
from easybuild.tools.systemtools import get_cpu_features, get_gpu_info, get_os_type, get_system_info
@@ -626,6 +626,8 @@ def config_options(self):
626626
'strlist', 'store', self.default_repositorypath),
627627
'search-path-cpp-headers': ("Search path used at build time for include directories", 'choice',
628628
'store', DEFAULT_SEARCH_PATH_CPP_HEADERS, [*SEARCH_PATH_CPP_HEADERS]),
629+
'search-path-linker': ("Search path used at build time by the linker for libraries", 'choice',
630+
'store', DEFAULT_SEARCH_PATH_LINKER, [*SEARCH_PATH_LINKER]),
629631
'sourcepath': ("Path(s) to where sources should be downloaded (string, colon-separated)",
630632
None, 'store', mk_full_default_path('sourcepath')),
631633
'subdir-modules': ("Installpath subdir for modules", None, 'store', DEFAULT_PATH_SUBDIRS['subdir_modules']),

easybuild/tools/toolchain/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class Compiler(Toolchain):
9494
'packed-linker-options': (False, "Pack the linker options as comma separated list"), # ScaLAPACK mainly
9595
'rpath': (True, "Use RPATH wrappers when --rpath is enabled in EasyBuild configuration"),
9696
'search-path-cpp-headers': (None, "Search path used at build time for include directories"),
97+
'search-path-linker': (None, "Search path used at build time by the linker for libraries"),
9798
'extra_cflags': (None, "Specify extra CFLAGS options."),
9899
'extra_cxxflags': (None, "Specify extra CXXFLAGS options."),
99100
'extra_fflags': (None, "Specify extra FFLAGS options."),

easybuild/tools/toolchain/constants.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@
5858
('PRECFLAGS', 'FP precision flags'),
5959
] + COMPILER_FLAGS,
6060
LibraryList: [
61-
('LIBS', 'Libraries'), # TODO: where are these used? ld?
62-
('FLIBS', 'Fortran libraries'), # TODO: where are these used? gfortran only?
61+
('LIBS', 'Libraries'), # -l options to pass to the linker (C/C++/Fortran)
62+
('FLIBS', 'Fortran libraries'), # linker flags (e.g. -L and -l) for Fortran libraries
6363
],
6464
LinkLibraryPaths: [
65-
('LDFLAGS', 'Flags passed to linker'), # TODO: overridden by command line?
65+
('LDFLAGS', 'Linker flags'),
6666
],
6767
IncludePaths: [
6868
('CPPFLAGS', 'Preprocessor flags'),
@@ -72,6 +72,7 @@
7272
('C_INCLUDE_PATH', 'Location of C header files'),
7373
('CPLUS_INCLUDE_PATH', 'Location of C++ header files'),
7474
('OBJC_INCLUDE_PATH', 'Location of Objective C header files'),
75+
('LIBRARY_PATH', 'Location of linker files'),
7576
],
7677
CommandFlagList: COMPILER_VARIABLES,
7778
}

easybuild/tools/toolchain/toolchain.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
]
9898
# modes to handle CPP header search paths
9999
# see: https://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html
100+
# supported on Linux by: GCC, GFortran, oneAPI C/C++ Compilers, oneAPI Fortran Compiler
100101
SEARCH_PATH_CPP_HEADERS_FLAGS = "CPPFLAGS"
101102
SEARCH_PATH_CPP_HEADERS_CPATH = "CPATH"
102103
SEARCH_PATH_CPP_HEADERS_INCLUDE = "INCLUDE_PATHS"
@@ -107,6 +108,16 @@
107108
}
108109
DEFAULT_SEARCH_PATH_CPP_HEADERS = SEARCH_PATH_CPP_HEADERS_FLAGS
109110

111+
# modes to handle linker search paths
112+
# see: https://gcc.gnu.org/onlinedocs/cpp/Environment-Variables.html
113+
# supported on Linux by: GCC, GFortran, oneAPI C/C++ Compilers, oneAPI Fortran Compiler
114+
SEARCH_PATH_LINKER_FLAGS = "LDFLAGS"
115+
SEARCH_PATH_LINKER_LIBPATH = "LIBRARY_PATH"
116+
SEARCH_PATH_LINKER = {
117+
SEARCH_PATH_LINKER_FLAGS: ["LDFLAGS"],
118+
SEARCH_PATH_LINKER_LIBPATH: ["LIBRARY_PATH"],
119+
}
120+
DEFAULT_SEARCH_PATH_LINKER = SEARCH_PATH_LINKER_FLAGS
110121

111122
def is_system_toolchain(tc_name):
112123
"""Return whether toolchain with specified name is a system toolchain or not."""
@@ -1122,9 +1133,26 @@ def _add_dependency_linker_paths(self, dep_root, extra_dirs=None):
11221133
lib_dirs = ["lib64", "lib"]
11231134
lib_dirs = unique_ordered_extend(lib_dirs, extra_dirs)
11241135

1125-
env_var = "LDFLAGS"
1126-
self.log.debug("Adding lib paths to toolchain variable '%s': %s", env_var, dep_root)
1127-
self.variables.append_subdirs(env_var, dep_root, subdirs=lib_dirs)
1136+
# mode of operation is defined by search-path-linker option
1137+
# toolchain option has precedence over build option
1138+
linker_mode = DEFAULT_SEARCH_PATH_LINKER
1139+
build_opt = build_option("search_path_linker")
1140+
if self.options.get("search-path-linker") is not None:
1141+
linker_mode = self.options.option("search-path-linker")
1142+
self.log.debug("search-path-linker set by toolchain option: %s", linker_mode)
1143+
elif build_opt is not None:
1144+
linker_mode = build_opt
1145+
self.log.debug("search-path-linker set by build option: %s", linker_mode)
1146+
1147+
if linker_mode not in SEARCH_PATH_LINKER:
1148+
raise EasyBuildError(
1149+
"Unknown value selected for option search-path-linker: %s. Choose one of: %s",
1150+
linker_mode, ", ".join(SEARCH_PATH_LINKER)
1151+
)
1152+
1153+
for env_var in SEARCH_PATH_LINKER[linker_mode]:
1154+
self.log.debug("Adding lib paths to toolchain variable '%s': %s", env_var, dep_root)
1155+
self.variables.append_subdirs(env_var, dep_root, subdirs=lib_dirs)
11281156

11291157
def _setenv_variables(self, donotset=None, verbose=True):
11301158
"""Actually set the environment variables"""

0 commit comments

Comments
 (0)