Compiler.default_libc: early exit on darwin/win (#47554)

* Compiler.default_libc: early exit on darwin/win

* use .cc when testing c++ compiler if c compiler is missing
This commit is contained in:
Harmen Stoppels 2024-11-11 23:12:43 +01:00 committed by GitHub
parent a55073e7b0
commit 4691301eba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -428,6 +428,11 @@ def default_dynamic_linker(self) -> Optional[str]:
@property @property
def default_libc(self) -> Optional["spack.spec.Spec"]: def default_libc(self) -> Optional["spack.spec.Spec"]:
"""Determine libc targeted by the compiler from link line""" """Determine libc targeted by the compiler from link line"""
# technically this should be testing the target platform of the compiler, but we don't have
# that, so stick to host platform for now.
if sys.platform in ("darwin", "win32"):
return None
dynamic_linker = self.default_dynamic_linker dynamic_linker = self.default_dynamic_linker
if not dynamic_linker: if not dynamic_linker:
@ -449,14 +454,20 @@ def compiler_verbose_output(self) -> Optional[str]:
return self.cache.get(self).c_compiler_output return self.cache.get(self).c_compiler_output
def _compile_dummy_c_source(self) -> Optional[str]: def _compile_dummy_c_source(self) -> Optional[str]:
cc = self.cc if self.cc else self.cxx if self.cc:
cc = self.cc
ext = "c"
else:
cc = self.cxx
ext = "cc"
if not cc or not self.verbose_flag: if not cc or not self.verbose_flag:
return None return None
try: try:
tmpdir = tempfile.mkdtemp(prefix="spack-implicit-link-info") tmpdir = tempfile.mkdtemp(prefix="spack-implicit-link-info")
fout = os.path.join(tmpdir, "output") fout = os.path.join(tmpdir, "output")
fin = os.path.join(tmpdir, "main.c") fin = os.path.join(tmpdir, f"main.{ext}")
with open(fin, "w") as csource: with open(fin, "w") as csource:
csource.write( csource.write(