Repository: spack/spack

Issue:
Installation issue: legion on macos
<!-- Thanks for taking the time to report this build failure. To proceed with the report please:

1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively! -->

### Steps to reproduce the issue

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console
$ spack install legion
...
==> Installing legion-20.03.0-ht5mlq3kb4zk65j3qdhefwzxxeqlikyu
==> No binary for legion-20.03.0-ht5mlq3kb4zk65j3qdhefwzxxeqlikyu found: installing from source
/Users/ptb/gitrepos/spack/lib/spack/spack/architecture.py:203: UserWarning: microarchitecture specific optimizations are not supported yet on mixed compiler toolchains [check apple-clang@11.0.3 for further details]
  warnings.warn(msg.format(compiler))
==> Using cached archive: /Users/ptb/gitrepos/spack/var/spack/cache/_source-cache/archive/ae/ae5feedb5ed9f357b56424b9d73cea4f224a61e291e022556f796d1ff24d1244.tar.gz
==> legion: Executing phase: 'cmake'
==> legion: Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j12'

4 errors found in build log:
     634        /Users/ptb/gitrepos/spack/opt/spack/darwin-catalina-skylake/apple-clang-11.0.3/gasnet-2020.3.0-eb4avhu4wcxla3mqn6bu5hu
            ec5it6gge/lib/libgasnet-mpi-par.a(gasnet_tools.o)
     635        /Users/ptb/gitrepos/spack/opt/spack/darwin-catalina-skylake/apple-clang-11.0.3/gasnet-2020.3.0-eb4avhu4wcxla3mqn6bu5hu
            ec5it6gge/lib/libgasnet_tools-par.a(gasnet_tools.o)
     636    duplicate symbol '_gasnett_linkconfig_idiotcheck_RELEASE_MAJOR_2020' in:
     637        /Users/ptb/gitrepos/spack/opt/spack/darwin-catalina-skylake/apple-clang-11.0.3/gasnet-2020.3.0-eb4avhu4wcxla3mqn6bu5hu
            ec5it6gge/lib/libgasnet-mpi-par.a(gasnet_tools.o)
     638        /Users/ptb/gitrepos/spack/opt/spack/darwin-catalina-skylake/apple-clang-11.0.3/gasnet-2020.3.0-eb4avhu4wcxla3mqn6bu5hu
            ec5it6gge/lib/libgasnet_tools-par.a(gasnet_tools.o)
     639    ld: 128 duplicate symbols for architecture x86_64
  >> 640    clang: error: linker command failed with exit code 1 (use -v to see invocation)
  >> 641    make[2]: *** [lib/librealm.1.dylib] Error 1
  >> 642    make[1]: *** [runtime/CMakeFiles/RealmRuntime.dir/all] Error 2
  >> 643    make: *** [all] Error 2
```

### Information on your system

<!-- Please include the output of `spack debug report` -->
```console
$ spack debug report
* **Spack:** 0.16.0-908-85ea52acd
* **Python:** 3.9.1
* **Platform:** darwin-catalina-skylake
* **Concretizer:** original
```
<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->

### Additional information

<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists. -->
* [spack-build-out.txt](https://github.com/spack/spack/files/5868839/spack-build-out.txt)
* [spack-build-env.txt](https://github.com/spack/spack/files/5868834/spack-build-env.txt)


<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [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

spack maintainer: @streichler


Discussion:
I'm getting different errors now using apple-clang@12:

```shell
 >> 134    /var/folders/ck/bwzqcv_s1pz1t9fc86731shh0000gq/T/ptb/spack-stage/sp
            ack-stage-legion-21.03.0-ofxwpmeej2wjbrvmjrmnugskhwztwp54/spack-src
            /runtime/realm/transfer/lowlevel_dma.cc:107:26: error: expected exp
            ression
     135          it = queues.insert({ tgt_mem, PerMemory { 0 } }).first;
     136                             ^
  >> 137    /var/folders/ck/bwzqcv_s1pz1t9fc86731shh0000gq/T/ptb/spack-stage/sp
            ack-stage-legion-21.03.0-ofxwpmeej2wjbrvmjrmnugskhwztwp54/spack-src
            /runtime/realm/transfer/lowlevel_dma.cc:109:50: error: expected '('
             for function-style cast or type construction
     138        it->second.requests.push_back(IBAllocRequest { req_node, req_op
            , ib_index, size });
     139                                      ~~~~~~~~~~~~~~ ^
  >> 140    /var/folders/ck/bwzqcv_s1pz1t9fc86731shh0000gq/T/ptb/spack-stage/sp
            ack-stage-legion-21.03.0-ofxwpmeej2wjbrvmjrmnugskhwztwp54/spack-src
            /runtime/realm/transfer/channel.cc:3603:34: error: expected express
            ion
     141                        src_1d_maxbytes = std::min({ dst_1d_maxbytes,
     142                                                   ^
  >> 143    /var/folders/ck/bwzqcv_s1pz1t9fc86731shh0000gq/T/ptb/spack-stage/sp
            ack-stage-legion-21.03.0-ofxwpmeej2wjbrvmjrmnugskhwztwp54/spack-src
            /runtime/realm/transfer/channel.cc:3619:34: error: expected express
            ion
```

The default c++ standard for apple-clang12 is c++14 which makes me think this might be due to missing headers.

@pbrady -- not yet exactly sure what is going on here.  The apple-clang-12 docs do state the default is c++14 (actually `gnu++14`) but if we add `-std=c++11` to the cxx flags these issues go away; as is also the case with `-std=c++14`.  

We're working on a patch for you -- stay tuned... 
Thanks @pmccormick.  Having just upgraded to BigSur and now encountering #26669 I can't help but think that apple is actively trying to sabotage developers

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/legion/package.py b/var/spack/repos/builtin/packages/legion/package.py
--- a/var/spack/repos/builtin/packages/legion/package.py
+++ b/var/spack/repos/builtin/packages/legion/package.py
@@ -62,6 +62,13 @@ class Legion(CMakePackage):
     depends_on('papi', when='+papi')
     depends_on('zlib', when='+zlib')
 
+    # A C++ standard variant to work-around some odd behaviors with apple-clang
+    # but this might be helpful for other use cases down the road.  Legion's
+    # current development policy is C++11 or greater so we capture that aspect
+    # here.
+    cpp_stds = ["11", "14", "17", "20"]
+    variant('cxxstd', default="11", values=cpp_stds, multi=False)
+
     # TODO: Need a AMD/HIP variant to match support landing in 21.03.0.
 
     # Network transport layer: the underlying data transport API should be used for
@@ -201,7 +208,10 @@ def validate_gasnet_root(value):
     def cmake_args(self):
         spec = self.spec
         cmake_cxx_flags = []
-        options = []
+        from_variant = self.define_from_variant
+        options = [
+            from_variant("CMAKE_CXX_STANDARD", "cxxstd")
+        ]
 
         if 'network=gasnet' in spec:
             options.append('-DLegion_NETWORKS=gasnetex')


Test patch: