From 5c71d363302488f361462101d90df6123c708dfd Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Thu, 3 Apr 2025 11:23:08 +0200 Subject: [PATCH] compiler-wrapper: set SPACK_COMPILER_EXTRA_RPATHS (#49828) Signed-off-by: Massimiliano Culpo --- lib/spack/spack/test/build_environment.py | 51 +++++++++++++++++++ .../packages/compiler-wrapper/package.py | 10 ++++ 2 files changed, 61 insertions(+) diff --git a/lib/spack/spack/test/build_environment.py b/lib/spack/spack/test/build_environment.py index ed8bcbd86dc..db76cd0cabd 100644 --- a/lib/spack/spack/test/build_environment.py +++ b/lib/spack/spack/test/build_environment.py @@ -777,3 +777,54 @@ def test_optimization_flags_are_using_node_target(default_mock_concretization, m assert len(actions) == 1 and isinstance(actions[0], spack.util.environment.SetEnv) assert actions[0].value == "-march=x86-64 -mtune=generic" + + +@pytest.mark.regression("49827") +@pytest.mark.parametrize( + "gcc_config,expected_rpaths", + [ + ( + """\ +gcc: + externals: + - spec: gcc@14.2.0 languages=c + prefix: /fake/path1 + extra_attributes: + compilers: + c: /fake/path1 + extra_rpaths: + - /extra/rpaths1 + - /extra/rpaths2 +""", + "/extra/rpaths1:/extra/rpaths2", + ), + ( + """\ +gcc: + externals: + - spec: gcc@14.2.0 languages=c + prefix: /fake/path1 + extra_attributes: + compilers: + c: /fake/path1 +""", + None, + ), + ], +) +@pytest.mark.not_on_windows("Windows doesn't use the compiler-wrapper") +def test_extra_rpaths_is_set( + working_env, mutable_config, mock_packages, gcc_config, expected_rpaths +): + """Tests that using a compiler with an 'extra_rpaths' section will set the corresponding + SPACK_COMPILER_EXTRA_RPATHS variable for the wrapper. + """ + cfg_data = syaml.load_config(gcc_config) + spack.config.set("packages", cfg_data) + mpich = spack.concretize.concretize_one("mpich %gcc@14") + spack.build_environment.setup_package(mpich.package, dirty=False) + + if expected_rpaths is not None: + assert os.environ["SPACK_COMPILER_EXTRA_RPATHS"] == expected_rpaths + else: + assert "SPACK_COMPILER_EXTRA_RPATHS" not in os.environ diff --git a/var/spack/repos/builtin/packages/compiler-wrapper/package.py b/var/spack/repos/builtin/packages/compiler-wrapper/package.py index 6b134c2caca..e4a5e77abcd 100644 --- a/var/spack/repos/builtin/packages/compiler-wrapper/package.py +++ b/var/spack/repos/builtin/packages/compiler-wrapper/package.py @@ -162,6 +162,7 @@ def setup_dependent_build_environment(self, env, dependent_spec): bin_dir = self.bin_dir() implicit_rpaths, env_paths = [], [] + extra_rpaths = [] for language, attr_name, wrapper_var_name, spack_var_name in _var_list: compiler_pkg = dependent_spec[language].package if not hasattr(compiler_pkg, attr_name): @@ -215,12 +216,21 @@ def setup_dependent_build_environment(self, env, dependent_spec): # Check if this compiler has implicit rpaths implicit_rpaths.extend(_implicit_rpaths(pkg=compiler_pkg)) + # Add extra rpaths, if they are defined in an external spec + extra_rpaths.extend( + getattr(compiler_pkg.spec, "extra_attributes", {}).get("extra_rpaths", []) + ) + if implicit_rpaths: # Implicit rpaths are accumulated across all compilers so, whenever they are mixed, # the compiler used in ccld mode will account for rpaths from other compilers too. implicit_rpaths = lang.dedupe(implicit_rpaths) env.set("SPACK_COMPILER_IMPLICIT_RPATHS", ":".join(implicit_rpaths)) + if extra_rpaths: + extra_rpaths = lang.dedupe(extra_rpaths) + env.set("SPACK_COMPILER_EXTRA_RPATHS", ":".join(extra_rpaths)) + env.set("SPACK_ENABLE_NEW_DTAGS", self.enable_new_dtags) env.set("SPACK_DISABLE_NEW_DTAGS", self.disable_new_dtags)