Repository: spack/spack

Issue:
openssl bootstrap error on Apple M1
### Steps to reproduce

Bootstrapping after initial install on an M1 mac stalls at the openssl install

 ```console
$ spack spec zlib
```

### Error message

```console
==> Installing openssl-1.1.1q-zpzgq65dsbnetetj3epwn2v5j5eudphs
==> No binary for openssl-1.1.1q-zpzgq65dsbnetetj3epwn2v5j5eudphs found: installing from source
==> Fetching https://www.openssl.org/source/openssl-1.1.1q.tar.gz
==> Ran patch() for openssl
==> openssl: Executing phase: 'install'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j10'

3 errors found in build log:
     921    /Users/luke/spack-dev_ARM/lib/spack/env/clang/clang  -I. -Iinclude -arch arm64 -O3 -Wall -D_REENTRANT -DZLIB -DNDEBUG -I/Users/luke/.spack/bootstrap/store/darwin-monterey-aarch64/apple-clang-13.1.6/zlib-1.2.12-sumirksd2mz
            kxllpmtnhwoo5p6yruwls/include -MMD -MF test/tls13encryptiontest.d.tmp -MT test/tls13encryptiontest.o -c -o test/tls13encryptiontest.o test/tls13encryptiontest.c
     922    /Users/luke/spack-dev_ARM/lib/spack/env/clang/clang  -I. -Iinclude -arch arm64 -O3 -Wall -D_REENTRANT -DZLIB -DNDEBUG -I/Users/luke/.spack/bootstrap/store/darwin-monterey-aarch64/apple-clang-13.1.6/zlib-1.2.12-sumirksd2mz
            kxllpmtnhwoo5p6yruwls/include -MMD -MF test/tls13secretstest.d.tmp -MT test/tls13secretstest.o -c -o test/tls13secretstest.o test/tls13secretstest.c
     923    /Users/luke/spack-dev_ARM/lib/spack/env/clang/clang  -I. -Iinclude -Iapps -arch arm64 -O3 -Wall -D_REENTRANT -DZLIB -DNDEBUG -I/Users/luke/.spack/bootstrap/store/darwin-monterey-aarch64/apple-clang-13.1.6/zlib-1.2.12-sumi
            rksd2mzkxllpmtnhwoo5p6yruwls/include -MMD -MF test/uitest.d.tmp -MT test/uitest.o -c -o test/uitest.o test/uitest.c
     924    /Users/luke/spack-dev_ARM/lib/spack/env/clang/clang  -Iinclude -arch arm64 -O3 -Wall -D_REENTRANT -DZLIB -DNDEBUG -I/Users/luke/.spack/bootstrap/store/darwin-monterey-aarch64/apple-clang-13.1.6/zlib-1.2.12-sumirksd2mzkxll
            pmtnhwoo5p6yruwls/include -MMD -MF test/v3ext.d.tmp -MT test/v3ext.o -c -o test/v3ext.o test/v3ext.c
     925    /Users/luke/spack-dev_ARM/lib/spack/env/clang/clang  -Iinclude -arch arm64 -O3 -Wall -D_REENTRANT -DZLIB -DNDEBUG -I/Users/luke/.spack/bootstrap/store/darwin-monterey-aarch64/apple-clang-13.1.6/zlib-1.2.12-sumirksd2mzkxll
            pmtnhwoo5p6yruwls/include -MMD -MF test/v3nametest.d.tmp -MT test/v3nametest.o -c -o test/v3nametest.o test/v3nametest.c
     926    /Users/luke/spack-dev_ARM/lib/spack/env/clang/clang  -Iinclude -arch arm64 -O3 -Wall -D_REENTRANT -DZLIB -DNDEBUG -I/Users/luke/.spack/bootstrap/store/darwin-monterey-aarch64/apple-clang-13.1.6/zlib-1.2.12-sumirksd2mzkxll
            pmtnhwoo5p6yruwls/include -MMD -MF test/verify_extra_test.d.tmp -MT test/verify_extra_test.o -c -o test/verify_extra_test.o test/verify_extra_test.c
  >> 927    test/v3ext.c:201:24: error: implicitly declaring library function 'memcmp' with type 'int (const void *, const void *, unsigned long)' [-Werror,-Wimplicit-function-declaration]
     928            if (!TEST_true(memcmp(ip1->data, ip2->data, ip1->length) <= 0))
     929                           ^
     930    test/v3ext.c:201:24: note: include the header <string.h> or explicitly provide a declaration for 'memcmp'
     931    1 error generated.
  >> 932    make[1]: *** [test/v3ext.o] Error 1
     933    make[1]: *** Waiting for unfinished jobs....
  >> 934    make: *** [all] Error 2

See build log for details:
  /var/folders/wj/f3yb6l4d0c3cf6fvqnv6h9m80000gn/T/luke/spack-stage/spack-stage-openssl-1.1.1q-zpzgq65dsbnetetj3epwn2v5j5eudphs/spack-build-out.txt

==> Warning: Skipping build of cmake-3.23.2-4v2flw4x3p2avdkmhdj2eeeku6yfssg4 since openssl-1.1.1q-zpzgq65dsbnetetj3epwn2v5j5eudphs failed
==> Warning: Skipping build of clingo-bootstrap-spack-y2w7ofzdzzgs6wspnauutx47rgfk3oyt since cmake-3.23.2-4v2flw4x3p2avdkmhdj2eeeku6yfssg4 failed
==> Error: cannot bootstrap the "clingo" Python module from spec "clingo-bootstrap@spack+python %apple-clang target=aarch64" due to the following failures:
github-actions-v0.1 raised ValueError: source is not trusted
spack-install raised InstallError: Terminating after first install failure: ProcessError: Command exited with status 2:
    'make' '-j10'
Run `spack --debug ...` for more detailed errors
```

### Information on your system

* **Spack:** 0.19.0.dev0 (e8d27c6cc4842bb30b6f07a563ed47142abf5d2e)
* **Python:** 3.9.12
* **Platform:** darwin-monterey-m1
* **Concretizer:** clingo


I think this is related to the following bug:

https://github.com/openssl/openssl/issues/18720

I can confirm that adding `#include <string.h>` to `test/v3ext.c` resolves the issue

### 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:
Can you add a patch for it?
Is adding a patch for bootstrapped software any different than other packages? Sorry, I'm kind of unfamiliar with anything outside of basic package building.
Yeah, it's a normal install of the openssl package, and apparently it just needs a one line patch to include string.h somewhere

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/openssl/package.py b/var/spack/repos/builtin/packages/openssl/package.py
--- a/var/spack/repos/builtin/packages/openssl/package.py
+++ b/var/spack/repos/builtin/packages/openssl/package.py
@@ -110,6 +110,10 @@ class Openssl(Package):   # Uses Fake Autotools, should subclass Package
     depends_on('ca-certificates-mozilla', type=('build', 'run'), when='certs=mozilla')
     depends_on('nasm', when='platform=windows')
 
+    patch('https://github.com/openssl/openssl/commit/f9e578e720bb35228948564192adbe3bc503d5fb.patch?full_index=1',
+          sha256='3fdcf2d1e47c34f3a012f23306322c5a35cad55b180c9b6fb34537b55884645c',
+          when='@1.1.1q')
+
     @classmethod
     def determine_version(cls, exe):
         output = Executable(exe)('version', output=str, error=str)


Test patch: