Repository: spack/spack

Issue:
py-numcodecs@0.11.0 fails build on ARM64 and PPC64: gcc: error: unrecognized command line option '-mno-avx2'
### Steps to reproduce the issue

`py-numcodecs@0.11.0` fails build using:
* `spack@develop` (81172f9251ff0b3409b07d5b9d13b214766ff1b1 from `Thu Oct 26 21:11:43 2023 +0200`)
* Python 3.11.6
* fails on:
  * GGC 9.4.0, PPC64, Ubuntu 20.04
  * GCC 11.4.0, ARM64, Ubuntu 20.04

This error is affecting our ability to install `libpressio` as part of E4S.

It seems like the error is related to changes introduced by https://github.com/spack/spack/commit/9889a0cac608b412a0dbd32b96dcb4e60f76e6e4
* https://github.com/spack/spack/commit/9889a0cac608b412a0dbd32b96dcb4e60f76e6e4#diff-d7efbc72e63355f91421b0d92d105f46471f98b19a18d54e4c2f1abb7a2794c3R48-R55

@haampie @adamjstewart 

Spack environment: [spack.yaml.txt](https://github.com/spack/spack/files/13190689/spack.yaml.txt)

<details><summary>Concretization</summary>

<pre>
 -   py-numcodecs@0.11.0%gcc@9.4.0~msgpack build_system=python_pip arch=linux-ubuntu20.04-ppc64le
[+]      ^py-cython@0.29.36%gcc@9.4.0 build_system=python_pip patches=c4369ad arch=linux-ubuntu20.04-ppc64le
[+]      ^py-entrypoints@0.4%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-ppc64le
[+]          ^py-flit-core@3.9.0%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-ppc64le
[+]      ^py-numpy@1.25.2%gcc@9.4.0+blas+lapack build_system=python_pip patches=873745d arch=linux-ubuntu20.04-ppc64le
[+]          ^openblas@0.3.24%gcc@9.4.0~bignuma~consistent_fpcsr+fortran~ilp64+locking+pic+shared build_system=makefile symbol_suffix=none threads=openmp arch=linux-ubuntu20.04-ppc64le
[+]              ^gmake@4.4.1%gcc@9.4.0~guile build_system=generic arch=linux-ubuntu20.04-ppc64le
[+]              ^perl@5.38.0%gcc@9.4.0+cpanm+opcode+open+shared+threads build_system=generic patches=714e4d1 arch=linux-ubuntu20.04-ppc64le
[+]                  ^berkeley-db@18.1.40%gcc@9.4.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-ubuntu20.04-ppc64le
[+]          ^py-setuptools@63.4.3%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-ppc64le
[+]      ^py-pip@23.1.2%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-ppc64le
[+]      ^py-py-cpuinfo@9.0.0%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-ppc64le
[+]      ^py-setuptools@68.0.0%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-ppc64le
[+]      ^py-setuptools-scm@7.1.0%gcc@9.4.0+toml build_system=python_pip arch=linux-ubuntu20.04-ppc64le
[+]          ^git@2.42.0%gcc@9.4.0+man+nls+perl+subtree~svn~tcltk build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]              ^autoconf@2.69%gcc@9.4.0 build_system=autotools patches=35c4492,7793209,a49dd5b arch=linux-ubuntu20.04-ppc64le
[+]              ^automake@1.16.5%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]              ^curl@8.4.0%gcc@9.4.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2+nghttp2 build_system=autotools libs=shared,static tls=openssl arch=linux-ubuntu20.04-ppc64le
[+]                  ^nghttp2@1.57.0%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]              ^gnuconfig@2022-09-17%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-ppc64le
[+]              ^libiconv@1.17%gcc@9.4.0 build_system=autotools libs=shared,static arch=linux-ubuntu20.04-ppc64le
[+]              ^libidn2@2.3.4%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]                  ^libunistring@1.1%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]              ^libtool@2.4.7%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]              ^m4@1.4.19%gcc@9.4.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=linux-ubuntu20.04-ppc64le
[+]                  ^libsigsegv@2.14%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]              ^openssh@9.5p1%gcc@9.4.0+gssapi build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]                  ^krb5@1.20.1%gcc@9.4.0+shared build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]                      ^bison@3.8.2%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]                      ^findutils@4.9.0%gcc@9.4.0 build_system=autotools patches=440b954 arch=linux-ubuntu20.04-ppc64le
[+]                  ^libedit@3.1-20210216%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]              ^pcre2@10.42%gcc@9.4.0~jit+multibyte build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]          ^py-packaging@23.1%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-ppc64le
[+]          ^py-tomli@2.0.1%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-ppc64le
[+]          ^py-typing-extensions@4.8.0%gcc@9.4.0 build_system=python_pip arch=linux-ubuntu20.04-ppc64le
[+]      ^py-wheel@0.41.2%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-ppc64le
[+]      ^python@3.11.6%gcc@9.4.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=linux-ubuntu20.04-ppc64le
[+]          ^bzip2@1.0.8%gcc@9.4.0~debug~pic+shared build_system=generic arch=linux-ubuntu20.04-ppc64le
[+]              ^diffutils@3.9%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]          ^expat@2.5.0%gcc@9.4.0+libbsd build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]              ^libbsd@0.11.7%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]                  ^libmd@1.0.4%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]          ^gdbm@1.23%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]          ^gettext@0.22.3%gcc@9.4.0+bzip2+curses+git~libunistring+libxml2+pic+shared+tar+xz build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]              ^libxml2@2.10.3%gcc@9.4.0+pic~python+shared build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]              ^tar@1.34%gcc@9.4.0 build_system=autotools zip=pigz arch=linux-ubuntu20.04-ppc64le
[+]                  ^pigz@2.7%gcc@9.4.0 build_system=makefile arch=linux-ubuntu20.04-ppc64le
[+]                  ^zstd@1.5.5%gcc@9.4.0+programs build_system=makefile compression=none libs=shared,static arch=linux-ubuntu20.04-ppc64le
[+]          ^libffi@3.4.4%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]          ^libxcrypt@4.4.35%gcc@9.4.0~obsolete_api build_system=autotools patches=4885da3 arch=linux-ubuntu20.04-ppc64le
[+]          ^ncurses@6.3%gcc@9.4.0~symlinks+termlib abi=none build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]          ^openssl@3.1.3%gcc@9.4.0~docs+shared build_system=generic certs=mozilla arch=linux-ubuntu20.04-ppc64le
[+]              ^ca-certificates-mozilla@2023-05-30%gcc@9.4.0 build_system=generic arch=linux-ubuntu20.04-ppc64le
[+]          ^pkgconf@1.9.5%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]          ^readline@8.2%gcc@9.4.0 build_system=autotools patches=bbf97f1 arch=linux-ubuntu20.04-ppc64le
[+]          ^sqlite@3.43.2%gcc@9.4.0+column_metadata+dynamic_extensions+fts~functions+rtree build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]          ^util-linux-uuid@2.38.1%gcc@9.4.0 build_system=autotools arch=linux-ubuntu20.04-ppc64le
[+]          ^xz@5.4.1%gcc@9.4.0+pic build_system=autotools libs=shared,static arch=linux-ubuntu20.04-ppc64le
[+]          ^zlib-ng@2.1.4%gcc@9.4.0+compat+opt build_system=autotools arch=linux-ubuntu20.04-ppc64le
</pre></details>

Error reproduced below using spack.yaml from above and Docker container image:
* `ecpe4s/ubuntu20.04-runner-ppc64-gcc-11.4-mpi-base:2023.08.20`

```
$> spack -e . install /4ssb5a
...
==> Installing py-numcodecs-0.11.0-4ssb5a5eicmjwvx55omsugtaio2xjzkk [46/46]
==> No binary for py-numcodecs-0.11.0-4ssb5a5eicmjwvx55omsugtaio2xjzkk found: installing from source
==> Using cached archive: /spack/var/spack/cache/_source-cache/archive/6c/6c058b321de84a1729299b0eae4d652b2e48ea1ca7f9df0da65cb13470e635eb.tar.gz
==> No patches needed for py-numcodecs
==> py-numcodecs: Executing phase: 'install'
==> Error: ProcessError: Command exited with status 1:

6 errors found in build log:
     11     Created temporary directory: /tmp/pip-ephem-wheel-cache-xs9jg0b2
     12     Processing /tmp/root/spack-stage/spack-stage-py-numcodecs-0.11.0-4ssb5a5eicmjwvx55omsugtaio2xjzkk/spack-src
     13       Added file:///tmp/root/spack-stage/spack-stage-py-numcodecs-0.11.0-4ssb5a5eicmjwvx55omsugtaio2xjzkk/spack-src to build tracker '/tmp/pip-build-tracker-wx3gg3ei'
     14       Created temporary directory: /tmp/pip-modern-metadata-irmlmfqf
     15       Preparing metadata (pyproject.toml): started
     16       Running command Preparing metadata (pyproject.toml)
  >> 17     /spack/opt/spack/linux-ubuntu20.04-ppc64le/gcc-9.4.0/py-setuptools-63.4.3-mbykritsmmhgvvf2ver6yb2faqxsdnio/lib/python3.11/site-packages/setuptools/config/pyprojecttoml.py:
            108: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
     18         warnings.warn(msg, _BetaConfiguration)
     19       [numcodecs] setting up Blosc extension
     20       [numcodecs] compiling Blosc extension without SSE2 support
     21       [numcodecs] compiling Blosc extension without AVX2 support
     22       [numcodecs] setting up Zstandard extension
     23       [numcodecs] setting up LZ4 extension
     24       [numcodecs] setting up compat extension
     25       [numcodecs] setting up shuffle extension
     26       [numcodecs] setting up vlen extension
     27       running dist_info
     28       creating /tmp/pip-modern-metadata-irmlmfqf/numcodecs.egg-info
     29       writing /tmp/pip-modern-metadata-irmlmfqf/numcodecs.egg-info/PKG-INFO
  >> 30     /spack/opt/spack/linux-ubuntu20.04-ppc64le/gcc-9.4.0/py-setuptools-63.4.3-mbykritsmmhgvvf2ver6yb2faqxsdnio/lib/python3.11/site-packages/setuptools/dist.py:160: UserWarning
            : newlines not allowed and will break in the future
     31         warnings.warn("newlines not allowed and will break in the future")
     32       writing dependency_links to /tmp/pip-modern-metadata-irmlmfqf/numcodecs.egg-info/dependency_links.txt
     33       writing requirements to /tmp/pip-modern-metadata-irmlmfqf/numcodecs.egg-info/requires.txt
     34       writing top-level names to /tmp/pip-modern-metadata-irmlmfqf/numcodecs.egg-info/top_level.txt
     35       writing manifest file '/tmp/pip-modern-metadata-irmlmfqf/numcodecs.egg-info/SOURCES.txt'
     36       [1/6] Cythonizing numcodecs/_shuffle.pyx

     ...

     51     Created temporary directory: /tmp/pip-unpack-16ahaysr
     52     Building wheels for collected packages: numcodecs
     53       Created temporary directory: /tmp/pip-wheel-afj84kd3
     54       Destination directory: /tmp/pip-wheel-afj84kd3
     55       Building wheel for numcodecs (pyproject.toml): started
     56       Running command Building wheel for numcodecs (pyproject.toml)
  >> 57     /spack/opt/spack/linux-ubuntu20.04-ppc64le/gcc-9.4.0/py-setuptools-63.4.3-mbykritsmmhgvvf2ver6yb2faqxsdnio/lib/python3.11/site-packages/setuptools/config/pyprojecttoml.py:
            108: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
     58         warnings.warn(msg, _BetaConfiguration)
     59       [numcodecs] setting up Blosc extension
     60       [numcodecs] compiling Blosc extension without SSE2 support
     61       [numcodecs] compiling Blosc extension without AVX2 support
     62       [numcodecs] setting up Zstandard extension
     63       [numcodecs] setting up LZ4 extension

     ...

     124      copying ./numcodecs/tests/test_blosc.py -> build/lib.linux-ppc64le-cpython-311/numcodecs/tests
     125      copying ./numcodecs/tests/test_lz4.py -> build/lib.linux-ppc64le-cpython-311/numcodecs/tests
     126      copying ./numcodecs/tests/test_vlen_utf8.py -> build/lib.linux-ppc64le-cpython-311/numcodecs/tests
     127      copying ./numcodecs/tests/test_entrypoints.py -> build/lib.linux-ppc64le-cpython-311/numcodecs/tests
     128      running egg_info
     129      writing numcodecs.egg-info/PKG-INFO
  >> 130    /spack/opt/spack/linux-ubuntu20.04-ppc64le/gcc-9.4.0/py-setuptools-63.4.3-mbykritsmmhgvvf2ver6yb2faqxsdnio/lib/python3.11/site-packages/setuptools/dist.py:160: UserWarning
            : newlines not allowed and will break in the future
     131        warnings.warn("newlines not allowed and will break in the future")
     132      writing dependency_links to numcodecs.egg-info/dependency_links.txt
     133      writing requirements to numcodecs.egg-info/requires.txt
     134      writing top-level names to numcodecs.egg-info/top_level.txt
     135      [1/6] Cythonizing numcodecs/_shuffle.pyx
     136      [2/6] Cythonizing numcodecs/blosc.pyx

     ...

     155      creating build/temp.linux-ppc64le-cpython-311/c-blosc/internal-complibs/zstd-1.4.8/common
     156      creating build/temp.linux-ppc64le-cpython-311/c-blosc/internal-complibs/zstd-1.4.8/compress
     157      creating build/temp.linux-ppc64le-cpython-311/c-blosc/internal-complibs/zstd-1.4.8/decompress
     158      creating build/temp.linux-ppc64le-cpython-311/c-blosc/internal-complibs/zstd-1.4.8/dictBuilder
     159      creating build/temp.linux-ppc64le-cpython-311/numcodecs
     160      /spack/lib/spack/env/gcc/gcc -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -fPIC -DHAVE_LZ4=1 -DHAVE_ZLIB=1 -DHAVE_ZSTD=1 -Ic-blosc/blosc -Ic-blosc/internal-complibs/zlib-1.2.8 -I
            c-blosc/internal-complibs/zstd-1.4.8 -Ic-blosc/internal-complibs/lz4-1.9.3 -Ic-blosc/internal-complibs/zstd-1.4.8/deprecated -Ic-blosc/internal-complibs/zstd-1.4.8/compres
            s -Ic-blosc/internal-complibs/zstd-1.4.8/dll -Ic-blosc/internal-complibs/zstd-1.4.8/decompress -Ic-blosc/internal-complibs/zstd-1.4.8/common -Ic-blosc/internal-complibs/zs
            td-1.4.8/legacy -Ic-blosc/internal-complibs/zstd-1.4.8/dictBuilder -Ic-blosc/internal-complibs/zstd-1.4.8/dll/example -I/spack/opt/spack/linux-ubuntu20.04-ppc64le/gcc-9.4.
            0/python-3.11.6-ghm4v2sxvxv7cvblmyvwjklodrypfky5/include/python3.11 -c c-blosc/blosc/bitshuffle-generic.c -o build/temp.linux-ppc64le-cpython-311/c-blosc/blosc/bitshuffle-
            generic.o -mno-sse2 -mno-avx2
  >> 161    gcc: error: unrecognized command line option '-mno-sse2'; did you mean '-mno-isel'?
  >> 162      gcc: error: unrecognized command line option '-mno-avx2'
     163      [numcodecs] command '/spack/lib/spack/env/gcc/gcc' failed with exit code 1
     164      Traceback (most recent call last):
     165        File "/spack/opt/spack/linux-ubuntu20.04-ppc64le/gcc-9.4.0/py-setuptools-63.4.3-mbykritsmmhgvvf2ver6yb2faqxsdnio/lib/python3.11/site-packages/setuptools/_distutils/uni
            xccompiler.py", line 186, in _compile
     166          self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
     167        File "/spack/opt/spack/linux-ubuntu20.04-ppc64le/gcc-9.4.0/py-setuptools-63.4.3-mbykritsmmhgvvf2ver6yb2faqxsdnio/lib/python3.11/site-packages/setuptools/_distutils/cco
            mpiler.py", line 986, in spawn
     168          spawn(cmd, dry_run=self.dry_run, **kwargs)
```

### Error message

<details><summary>Error message</summary>

<pre>
... see above
</pre></details>


### Information on your system

* **Spack:** 0.21.0.dev0 (81172f9251ff0b3409b07d5b9d13b214766ff1b1)
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.04-power9le
* **Concretizer:** clingo

### Additional information

[spack-build-env.txt](https://github.com/spack/spack/files/13190671/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/13190672/spack-build-out.txt)

### General information

- [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


Discussion:
I agree, looks like this was introduced by #40183. Could we instead set `CFLAGS` so the whole `base_compile_args` elif statement is skipped? Then we aren't adding any flags. If not, we'll have to patch `setup.py`.
Can be made conditional on target=x86.

The whole package is a giant mess... Looks like they're open to not vendor blocs + super old zstd etc. See https://github.com/zarr-developers/numcodecs/issues/464.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-numcodecs/package.py b/var/spack/repos/builtin/packages/py-numcodecs/package.py
--- a/var/spack/repos/builtin/packages/py-numcodecs/package.py
+++ b/var/spack/repos/builtin/packages/py-numcodecs/package.py
@@ -49,10 +49,11 @@ def setup_build_environment(self, env):
         # This package likes to compile natively by checking cpu features and then setting flags
         # -msse2 and -mavx2, which we want to avoid in Spack. This could go away if the package
         # supports external libraries.
-        if "avx2" not in self.spec.target.features:
-            env.set("DISABLE_NUMCODECS_AVX2", "1")
-        if "sse2" not in self.spec.target.features:
-            env.set("DISABLE_NUMCODECS_SSE2", "1")
+        if self.spec.satisfies("target=x86_64:"):
+            if "avx2" not in self.spec.target.features:
+                env.set("DISABLE_NUMCODECS_AVX2", "1")
+            if "sse2" not in self.spec.target.features:
+                env.set("DISABLE_NUMCODECS_SSE2", "1")
 
     def flag_handler(self, name, flags):
         if name == "cflags":


Test patch: