Repository: spack/spack

Issue:
Cray compilers detected with `compiler:target:any` not working
### Steps to reproduce

On a Cray system, using a simple environment just for "scoping" the configuration (see `::` for `compilers` section)

```yaml
spack:
  # add package specs to the `specs` list
  specs: []
  view: true
  concretizer:
    unify: true
  compilers::
  - compiler:
      spec: gcc@11.2.0
      paths:
        cc: cc
        cxx: CC
        f77: ftn
        fc: ftn
      flags: {}
      operating_system: cnl7
      target: any
      modules:
      - PrgEnv-gnu
      - gcc/11.2.0
      environment: {}
      extra_rpaths: []
```

```console
$ spack -e . config get compilers
compilers:
- compiler:
    spec: gcc@11.2.0
    paths:
      cc: cc
      cxx: CC
      f77: ftn
      fc: ftn
    flags: {}
    operating_system: cnl7
    target: any
    modules:
    - PrgEnv-gnu
    - gcc/11.2.0
    environment: {}
    extra_rpaths: []
```

Trying to concretise a simple package

```console
$ spack -e . spec zlib
```

### Error message

```console
$ spack -e . spec zlib
==> Error: concretization failed for the following reasons:

   1. zlib compiler 'gcc@11.2.0' incompatible with 'target=x86_64'
```

### Information on your system

* **Spack:** 0.20.0.dev0 (712b30c9c5883b7682954fcc18d7b2ef35411a8e)
* **Python:** 3.6.15
* **Platform:** cray-sles15-haswell
* **Concretizer:** clingo

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:
I can confirm that manually changing
```diff
-    target: any
+    target: x86_64
```
fixes the problem for me, but spack automatically detects the compiler as `target: any`.  Also, it didn't use to error in this way in previous versions.
Regressed in 8517a74f3792bb87f754c6fd363d820104643d9e (https://github.com/spack/spack/pull/35989) @alalazo can you have a look?
> I can confirm that manually changing
> 
> ```diff
> -    target: any
> +    target: x86_64
> ```
> 
> fixes the problem for me, but spack automatically detects the compiler as `target: any`. Also, it didn't use to error in this way in previous versions.

Exactly, temporarily I workaround it in the same way.

The problem about how to actually fix it is that I'm not sure if `any` is semantically valid for the ASP solver or not. AFAIK `any` is an hard-coded value which I was able to spot just in the Cray compiler detection function.
There used to be direct compat rules

```
compiler_supports_target("apple-clang","14.0.0","m1").
```

now there's one step of indirection

```
compiler_supports_target(0,"any").
target_compatible("m1","m1").
```

So, a rule is missing that makes `any` compatible with ... any?

I'll leave it to @alalazo 
@albestro Can you check this diff:
```diff
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
index 8e843d60eb..7c5d409ca0 100644
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -968,6 +968,9 @@ def compiler_facts(self):
             if compiler.operating_system:
                 self.gen.fact(fn.compiler_os(compiler_id, compiler.operating_system))
 
+            if compiler.target == "any":
+                compiler.target = None
+
             if compiler.target is not None:
                 self.gen.fact(fn.compiler_target(compiler_id, compiler.target))

```
? I'll try to write a unit-test to be sure we won't have regressions on this in the future, but on the reproducer you gave this should be equivalent to what we had before #35989
Thanks for the fix @alalazo!

```console
$ spack spec -I zlib
==> Error: concretization failed for the following reasons:

   1. zlib compiler 'gcc@11.2.0' incompatible with 'target=x86_64'
$ git apply < patch
$ git --no-pager diff
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
index 8e843d60eb..7c5d409ca0 100644
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -968,6 +968,9 @@ def compiler_facts(self):
             if compiler.operating_system:
                 self.gen.fact(fn.compiler_os(compiler_id, compiler.operating_system))

+            if compiler.target == "any":
+                compiler.target = None
+
             if compiler.target is not None:
                 self.gen.fact(fn.compiler_target(compiler_id, compiler.target))

$ spack spec -I zlib
Input spec
--------------------------------
 -   zlib

Concretized
--------------------------------
 -   zlib@1.2.13%gcc@11.2.0+optimize+pic+shared build_system=makefile arch=cray-cnl7-haswell
```

Resolving patch:
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -968,6 +968,9 @@ def compiler_facts(self):
             if compiler.operating_system:
                 self.gen.fact(fn.compiler_os(compiler_id, compiler.operating_system))
 
+            if compiler.target == "any":
+                compiler.target = None
+
             if compiler.target is not None:
                 self.gen.fact(fn.compiler_target(compiler_id, compiler.target))
 


Test patch:
diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py
--- a/lib/spack/spack/test/concretize.py
+++ b/lib/spack/spack/test/concretize.py
@@ -2150,3 +2150,29 @@ def test_compiler_with_custom_non_numeric_version(self, mock_executable):
         spack.config.set("compilers", compiler_configuration)
         s = spack.spec.Spec("a %gcc@foo").concretized()
         assert s.compiler.version == ver("foo")
+
+    @pytest.mark.regression("36628")
+    def test_concretization_with_compilers_supporting_target_any(self):
+        """Tests that a compiler with 'target: any' can satisfy any target, and is a viable
+        candidate for concretization.
+        """
+        compiler_configuration = [
+            {
+                "compiler": {
+                    "spec": "gcc@12.1.0",
+                    "paths": {
+                        "cc": "/some/path/gcc",
+                        "cxx": "/some/path/g++",
+                        "f77": None,
+                        "fc": None,
+                    },
+                    "operating_system": "debian6",
+                    "target": "any",
+                    "modules": [],
+                }
+            }
+        ]
+
+        with spack.config.override("compilers", compiler_configuration):
+            s = spack.spec.Spec("a").concretized()
+        assert s.satisfies("%gcc@12.1.0")