Repository: spack/spack

Issue:
glibc dependency on MacOS M1
### Steps to reproduce

Building any spack package with gcc now pulls in glibc (I think as of 34146c19?). This fails on darwin-sonoma-m1 architectures where glibc cannot be built. If I understand correctly, this is an upstream limitation and not something wrong with Spack's glibc package.

In earlier commits, e.g. e8c41cdbcb:

```console
$ spack spec m4 %gcc@12                                                                                                                                                                                                                                                                [10:46:32]
Input spec
--------------------------------
 -   m4%gcc@12

Concretized
--------------------------------
 -   m4@1.4.19%gcc@12.3.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=darwin-sonoma-m1
[+]      ^diffutils@3.10%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]          ^libiconv@1.17%apple-clang@15.0.0 build_system=autotools libs=shared,static arch=darwin-sonoma-m1
 -       ^gcc-runtime@12.3.0%gcc@12.3.0 build_system=generic arch=darwin-sonoma-m1
[+]      ^gmake@4.4.1%apple-clang@15.0.0~guile build_system=generic arch=darwin-sonoma-m1
[+]      ^gnuconfig@2022-09-17%apple-clang@15.0.0 build_system=generic arch=darwin-sonoma-m1
[+]      ^libsigsegv@2.14%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
```

In later commits, e.g. d6baae525f:

```console
$ spack spec m4 %gcc@12                                                                                                                                                                                                                                                                [10:47:25]
Input spec
--------------------------------
 -   m4%gcc@12

Concretized
--------------------------------
 -   m4@1.4.19%gcc@12.3.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=darwin-sonoma-m1
[+]      ^diffutils@3.10%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]          ^libiconv@1.17%apple-clang@15.0.0 build_system=autotools libs=shared,static arch=darwin-sonoma-m1
 -       ^gcc-runtime@12.3.0%gcc@12.3.0 build_system=generic arch=darwin-sonoma-m1
 -           ^glibc@2.39%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]              ^bison@3.8.2%apple-clang@15.0.0~color build_system=autotools arch=darwin-sonoma-m1
[+]                  ^m4@1.4.19%apple-clang@15.0.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=darwin-sonoma-m1
[+]              ^gawk@5.3.0%apple-clang@15.0.0~nls build_system=autotools arch=darwin-sonoma-m1
[+]                  ^gmp@6.2.1%apple-clang@15.0.0+cxx build_system=autotools libs=shared,static patches=69ad2e2 arch=darwin-sonoma-m1
[+]                      ^autoconf@2.72%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]                      ^automake@1.16.5%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]                      ^libtool@2.4.7%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]                          ^findutils@4.9.0%apple-clang@15.0.0 build_system=autotools patches=440b954 arch=darwin-sonoma-m1
[+]                  ^mpfr@4.2.1%apple-clang@15.0.0 build_system=autotools libs=shared,static arch=darwin-sonoma-m1
[+]                      ^autoconf-archive@2023.02.20%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]                  ^readline@8.2%apple-clang@15.0.0 build_system=autotools patches=bbf97f1 arch=darwin-sonoma-m1
[+]              ^gettext@0.22.4%apple-clang@15.0.0+bzip2+curses+git~libunistring+libxml2+pic+shared+tar+xz build_system=autotools arch=darwin-sonoma-m1
[+]                  ^bzip2@1.0.8%apple-clang@15.0.0~debug~pic+shared build_system=generic arch=darwin-sonoma-m1
[+]                  ^libxml2@2.10.3%apple-clang@15.0.0+pic~python+shared build_system=autotools arch=darwin-sonoma-m1
[+]                  ^ncurses@6.4%apple-clang@15.0.0~symlinks+termlib abi=none build_system=autotools patches=7a351bc arch=darwin-sonoma-m1
[+]                  ^tar@1.34%apple-clang@15.0.0 build_system=autotools zip=pigz arch=darwin-sonoma-m1
[+]                      ^pigz@2.8%apple-clang@15.0.0 build_system=makefile arch=darwin-sonoma-m1
[+]                      ^zstd@1.5.6%apple-clang@15.0.0+programs build_system=makefile compression=none libs=shared,static arch=darwin-sonoma-m1
[+]                  ^xz@5.4.6%apple-clang@15.0.0~pic build_system=autotools libs=shared,static arch=darwin-sonoma-m1
[+]              ^linux-headers@6.5.2%apple-clang@15.0.0 build_system=generic arch=darwin-sonoma-m1
[+]              ^perl@5.38.0%apple-clang@15.0.0+cpanm+opcode+open+shared+threads build_system=generic patches=714e4d1 arch=darwin-sonoma-m1
[+]                  ^berkeley-db@18.1.40%apple-clang@15.0.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=darwin-sonoma-m1
[+]                  ^gdbm@1.23%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]                  ^zlib-ng@2.1.6%apple-clang@15.0.0+compat+new_strategies+opt+pic+shared build_system=autotools arch=darwin-sonoma-m1
[+]              ^python@3.11.7%apple-clang@15.0.0+bz2+crypt+ctypes+dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tkinter+uuid+zlib build_system=generic patches=13fa8bf,b0615b2,ebdca64,f2fd060 arch=darwin-sonoma-m1
[e]                  ^apple-libuuid@1353.100.2%apple-clang@15.0.0 build_system=bundle arch=darwin-sonoma-m1
[+]                  ^expat@2.6.2%apple-clang@15.0.0~libbsd build_system=autotools arch=darwin-sonoma-m1
[+]                  ^libffi@3.4.6%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]                  ^libxcrypt@4.4.35%apple-clang@15.0.0~obsolete_api build_system=autotools patches=4885da3 arch=darwin-sonoma-m1
[+]                  ^openssl@3.2.1%apple-clang@15.0.0~docs+shared build_system=generic certs=mozilla arch=darwin-sonoma-m1
[+]                      ^ca-certificates-mozilla@2023-05-30%apple-clang@15.0.0 build_system=generic arch=darwin-sonoma-m1
[+]                  ^pkgconf@1.9.5%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]                  ^sqlite@3.43.2%apple-clang@15.0.0+column_metadata+dynamic_extensions+fts~functions+rtree build_system=autotools arch=darwin-sonoma-m1
[+]              ^sed@4.9%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]              ^texinfo@7.0.3%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
[+]      ^gmake@4.4.1%apple-clang@15.0.0~guile build_system=generic arch=darwin-sonoma-m1
[+]      ^gnuconfig@2022-09-17%apple-clang@15.0.0 build_system=generic arch=darwin-sonoma-m1
[+]      ^libsigsegv@2.14%apple-clang@15.0.0 build_system=autotools arch=darwin-sonoma-m1
```

### Error message

Once building glibc:

```console
$ spack install m4 %gcc@12                                                                                                                                                                                                                                                                [10:48:05]
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/libiconv-1.17-jdatb7h4dm2xqfmljmajidyjetzojvtz
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/libsigsegv-2.14-5562oo7o6aruemtkv2imcxzg6fkbywgc
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/gmp-6.2.1-x23zqpqkx25spusepf6m4yluar7pee62
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/ncurses-6.4-orzxnp5neeakl5l6wh5il2jyifbfmmxq
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/bzip2-1.0.8-qvjhz4t4zrtpbw3cprdeqc3rfq55ufw6
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/xz-5.4.6-dgyhv3cantmlgc4efuo7acygzflhqhh3
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/zlib-ng-2.1.6-xddcyzogw74zho7sunpw3kulhxqjcax3
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/zstd-1.5.6-nayoxlwthcp3gghsovvbhcjx22x6cj5b
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/gmake-4.4.1-yg5a2ohrgzyd532q2wnw5agfpzqgqfsb
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/gnuconfig-2022-09-17-7gytrfuudfw2tpponhl5i4x4xtmbb6wc
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/linux-headers-6.5.2-qbxoevgkxtaznooknmbmmb43spybwknj
[+] /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk (external apple-libuuid-1353.100.2-3wsgpvuiofcdze56kfqpjrqe45h4iww3)
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/pigz-2.8-spff7uy2trvknvbf2wrbyw33o3fesqps
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/openssl-3.2.1-crpvo5tg6bndwtpaxx44ncr65tubpi46
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/libxml2-2.10.3-t2p6ewkcvfqrve7pravrq2i3zez7dle6
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/diffutils-3.10-zkhxkvauckfmhbnvsow2qp4nyt3q5c26
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/libffi-3.4.6-cka4y6ubgsmdcubipem4ct7cazb37ihs
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/berkeley-db-18.1.40-rukdmkg53xoetm4pv7czjpa7duwp2ydl
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/readline-8.2-ovanre44rztodqlprnrfl6yfcrkdthbq
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/sed-4.9-6p5yzsocauthtvcuqbce6hw7ihai3cpw
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/libxcrypt-4.4.35-x2ksrgg4zkyyob5giqq6yg6uejwdaojt
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/mpfr-4.2.1-wuobngdwdebxz3s3mns22ivd5ypenty4
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/expat-2.6.2-oujmzkvkulww6mz6avjnhqknjf64x5oj
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/tar-1.34-y3ztwjlcydz2fpzb6nthrnbmzt64anyt
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/m4-1.4.19-hatzckezdkhtgr67btdapf2bovizc5s3
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/sqlite-3.43.2-ateskz3s6oayhg72lttgigpgdv7zqlaq
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/gdbm-1.23-73gr67gxklzd4szoexm4p5pyx4oxviyf
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/gawk-5.3.0-zihyq4esmo3veysw5ktomcawynzjni4m
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/gettext-0.22.4-hieilopljubfwpljhnfjqhtlbwbowszv
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/bison-3.8.2-bksqfbfdvyq2bldr3hxttaoc3np2bbem
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/perl-5.38.0-kfqtfyn4hu765w5p2whmo3hkb3onmjv2
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/python-3.11.7-g6qcoukv4k4emoygj4zxqsig2zqs3wlj
[+] /Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/texinfo-7.0.3-cfgzz6psqh4qvwpeexhiyimp5np4ijzm
==> Installing glibc-2.39-isjvx3aoxdpydtbzqs5xsyjvekv4mplx [34/36]
==> No binary for glibc-2.39-isjvx3aoxdpydtbzqs5xsyjvekv4mplx found: installing from source
==> Using cached archive: /Users/zjibben/codes/spack/var/spack/cache/_source-cache/archive/97/97f84f3b7588cd54093a6f6389b0c1a81e70d99708d74963a2e3eab7c7dc942d.tar.gz
==> Ran patch() for glibc
==> glibc: Executing phase: 'autoreconf'
==> glibc: Executing phase: 'configure'
==> Error: ProcessError: Command exited with status 1:
    '/var/folders/ys/bw9_q0fj5rl49b1h_6v0gvjm000pwc/T/zjibben/spack-stage/spack-stage-glibc-2.39-isjvx3aoxdpydtbzqs5xsyjvekv4mplx/spack-src/configure' '--prefix=/Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/glibc-2.39-isjvx3aoxdpydtbzqs5xsyjvekv4mplx' '--enable-kernel=4.4.1' '--with-headers=/Users/zjibben/codes/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/linux-headers-6.5.2-qbxoevgkxtaznooknmbmmb43spybwknj/include' '--without-selinux'

1 error found in build log:
     18    checking whether /Users/zjibben/codes/spack/lib/spack/env/clang/clang++ -std=gnu++11 can link programs... no
     19    checking for sysdeps preconfigure fragments... aarch64 alpha arc arm csky hppa i386 loongarch m68k microblaze checking for grep that handles long lines and -e... /usr/bin/grep
     20    checking for egrep... /usr/bin/grep -E
     21    mips nios2 or1k powerpc riscv s390 sh checking for grep that handles long lines and -e... (cached) /usr/bin/grep
     22    checking for egrep... (cached) /usr/bin/grep -E
     23    sparc x86_64
  >> 24    configure: error:
     25    *** The GNU C library is currently unavailable for this platform.
     26    *** If you are interested in seeing glibc on this platform visit
     27    *** the "How to submit a new port" in the wiki:
     28    ***   https://sourceware.org/glibc/wiki/#Development
     29    *** and join the community!

See build log for details:
  /var/folders/ys/bw9_q0fj5rl49b1h_6v0gvjm000pwc/T/zjibben/spack-stage/spack-stage-glibc-2.39-isjvx3aoxdpydtbzqs5xsyjvekv4mplx/spack-build-out.txt

==> Warning: Skipping build of gcc-runtime-12.3.0-bwwaoojkquoexumxw4gpaqnnzbcniyvr since glibc-2.39-isjvx3aoxdpydtbzqs5xsyjvekv4mplx failed
==> Warning: Skipping build of m4-1.4.19-z25ahjqpfffaoqjnugvmncivfov7gqe6 since gcc-runtime-12.3.0-bwwaoojkquoexumxw4gpaqnnzbcniyvr failed
==> Error: m4-1.4.19-z25ahjqpfffaoqjnugvmncivfov7gqe6: Package was not installed
==> Error: Installation request failed.  Refer to reported errors for failing package(s).
```

### Information on your system

M3 Macbook Pro

* **Spack:** 0.22.0.dev0 (77a8a4fe085aa1ebf20175dffd56d422d5d7e3d5)
* **Python:** 3.12.3
* **Platform:** darwin-sonoma-m1
* **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'm trying to reproduce the issue. Will report here what I find.
I can reproduce this:
![Screenshot from 2024-05-03 12-18-17](https://github.com/spack/spack/assets/4199709/67505322-1a50-442a-aceb-3af34743ded5)


Resolving patch:
diff --git a/var/spack/repos/builtin/packages/gcc-runtime/package.py b/var/spack/repos/builtin/packages/gcc-runtime/package.py
--- a/var/spack/repos/builtin/packages/gcc-runtime/package.py
+++ b/var/spack/repos/builtin/packages/gcc-runtime/package.py
@@ -53,7 +53,8 @@ class GccRuntime(Package):
     provides("libgfortran@4", when="%gcc@7")
     provides("libgfortran@5", when="%gcc@8:")
 
-    depends_on("libc", type="link")
+    depends_on("libc", type="link", when="platform=linux")
+    depends_on("libc", type="link", when="platform=cray")
 
     def install(self, spec, prefix):
         if spec.platform in ["linux", "cray", "freebsd"]:
diff --git a/var/spack/repos/builtin/packages/intel-oneapi-runtime/package.py b/var/spack/repos/builtin/packages/intel-oneapi-runtime/package.py
--- a/var/spack/repos/builtin/packages/intel-oneapi-runtime/package.py
+++ b/var/spack/repos/builtin/packages/intel-oneapi-runtime/package.py
@@ -45,7 +45,8 @@ class IntelOneapiRuntime(Package):
     conflicts("platform=windows", msg="IntelOneAPI can only be installed on Linux, and FreeBSD")
     conflicts("platform=darwin", msg="IntelOneAPI can only be installed on Linux, and FreeBSD")
 
-    depends_on("libc", type="link")
+    depends_on("libc", type="link", when="platform=linux")
+    depends_on("libc", type="link", when="platform=cray")
 
     def install(self, spec, prefix):
         libraries = get_elf_libraries(compiler=self.compiler, libraries=self.LIBRARIES)


Test patch: