Repository: spack/spack

Issue:
Installation issue: `seacas 2022-10-14:2023-05-30` with `fmt@9` when `gcc` mixed with `apple-clang`
### Steps to reproduce the issue

When `fmt%gcc` is mixed with  `seacas@2022-10-14%apple-clang`, `fmt@9` is used which triggers an `apple-clang` compiler bug in symbol mangling.

See:
https://github.com/llvm/llvm-project/issues/62765
https://github.com/fmtlib/fmt/issues/2967#issuecomment-2118051027

To reproduce
```
spack install seacas@2022-10-14%apple-clang ^fmt%gcc
```


### Error message

<details><summary>Error message</summary>

<pre>
  >> 2350    Undefined symbols for architecture arm64:
     2351      "fmt::v9::vformat(fmt::v9::basic_string_view<char>, fmt::v9::basic_format_args<fmt::v9::basic_format_context<fmt::v9::appender, char>>)", referenced from:
     2352          copyright(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) in copyright.C.o
     2353          format_time(double) in format_time.C.o
     2354          sys_info(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) in sys_info.C.o
     2355          time_stamp(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) in time_stamp.C.o
     2356      "std::__1::locale fmt::v9::detail::locale_ref::get<std::__1::locale>() const", referenced from:
     2357          decltype(fp0.out()) fmt::v9::formatter<tm, char, void>::format<fmt::v9::basic_format_context<fmt::v9::appender, char>>(tm const&, fmt::v9::basic_format_context<fmt::v9::appender, char>&) const in time_stamp.C.o
     2358    ld: symbol(s) not found for architecture arm64
</pre></details>


### Information on your system

* **Spack:** 0.23.0.dev0 (3f472039c55cd7a5d73fb0b0bf63317669733e8a)
* **Python:** 3.12.3
* **Platform:** darwin-sonoma-m1
* **Concretizer:** clingo

### Additional information

@gsjaardema 

[spack-build-env.txt](https://github.com/spack/spack/files/15410713/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/15410714/spack-build-out.txt)


### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:
The above linked fmt git issue suggests removing `FMT_ENABLE_IF` to solve it. However my patches around that have been unsuccessful.

Because it is the mismatch between `seacas%apple-clang` and `fmt%gcc`, my initial reaction is to conflict on `^fmt%gcc`. Would this be an ok addition to `seacas`?

Hm, maybe Spack got a bit too greedy with reuse, and it needs a more generic fix.
Is this specific to seacas, or would any client of fmt have the same issue when using different compilers?  In other words, does the seacas package.py need a fix, or does the fmt package.py need a fix?
In this case, this is a specific dependency of seacans that in a mixed toolchain will reliably fail. I think that seacans package.py should protect against this case. 

More broadly, I think this absolutely happens throughout spack when mixing the two -- I might be seeing this in vtk but I need to investigate more.
I am fine with the suggested change.  Please feel free to submit a PR if you ahve time.  Thanks for taking the time to look into this.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/seacas/package.py b/var/spack/repos/builtin/packages/seacas/package.py
--- a/var/spack/repos/builtin/packages/seacas/package.py
+++ b/var/spack/repos/builtin/packages/seacas/package.py
@@ -231,6 +231,17 @@ class Seacas(CMakePackage):
     depends_on("fmt@9.1.0", when="@2022-10-14:2023-05-30")
     depends_on("fmt@8.1.0:9", when="@2022-03-04:2022-05-16")
 
+    # if fmt@9.1.0%gcc is mixed with an %apple-clang seacas build
+    # it triggers a bug in apple-clang w.r.t how symbols are mangled
+    # https://github.com/spack/spack/issues/44330
+    conflicts(
+        "^fmt@9%gcc",
+        msg="""Cannot mix gcc/apple-clang toolchains
+              for this library combination.
+              See https://github.com/spack/spack/issues/44330""",
+        when="%apple-clang",
+    )
+
     depends_on("catch2@3:", when="@2024-03-11:+tests")
 
     depends_on("matio", when="+matio")


Test patch: