Repository: easybuilders/easybuild-easyblocks

Issue:
MESA on arm/aarch64 lacks gallium drivers and fails to build with -Dlibunwind=true
`easybuild/easyblocks/m/mesa.py` specifies the following:
```
        if not gallium_drivers:
            # Add appropriate Gallium drivers for current architecture
            arch = get_cpu_architecture()
            arch_gallium_drivers = {
                'x86_64': ['swrast', 'swr'],
                'POWER': ['swrast'],
            }
```
this leads to:
```
== processing EasyBuild easyconfig /home/terjekv/easybuild/software/EasyBuild/4.2.2/easybuild/easyconfigs/m/Mesa/Mesa-20.0.2-GCCcore-9.3.0.eb
ERROR: Traceback (most recent call last):
  File "/home/terjekv/easybuild/software/EasyBuild/4.2.2/lib/python3.6/site-packages/easybuild/main.py", line 115, in build_and_install_software
    (ec_res['success'], app_log, err) = build_and_install_one(ec, init_env)
  File "/home/terjekv/easybuild/software/EasyBuild/4.2.2/lib/python3.6/site-packages/easybuild/framework/easyblock.py", line 3264, in build_and_install_one
    app = app_class(ecdict['ec'])
  File "/home/terjekv/easybuild/software/EasyBuild/4.2.2/lib/python3.6/site-packages/easybuild/easyblocks/m/mesa.py", line 66, in __init__
    self.log.debug('Gallium driver(s) included in the installation: %s' % ', '.join(gallium_drivers))
TypeError: can only join an iterable
```
Adding `'aarch64': ['swrast']` should be enough. Will patch and test.


Discussion:
Well, adding AARCH64 helps, but building still fails:

```
[886/1032] Compiling C object 'src/gallium/auxiliary/eb820e8@@gallium@sta/util_u_debug_stack.c.o'.
FAILED: src/gallium/auxiliary/eb820e8@@gallium@sta/util_u_debug_stack.c.o
gcc -Isrc/gallium/auxiliary/eb820e8@@gallium@sta -Isrc/gallium/auxiliary -I../mesa-20.0.2/src/gallium/auxiliary -Isrc/loader -I../mesa-20.0.2/src/loader -I../mesa-20.0.2/src/gall
ium/include -Isrc -I../mesa-20.0.2/src -Iinclude -I../mesa-20.0.2/include -I../mesa-20.0.2/src/gallium/auxiliary/util -Isrc/compiler/nir -I../mesa-20.0.2/src/compiler/nir -Isrc/u
til -I../mesa-20.0.2/src/util -I/home/terjekv/.local/easybuild/software/libdrm/2.4.100-GCCcore-9.3.0/include/libdrm -I/home/terjekv/.local/easybuild/software/LLVM/9.0.1-GCCcore-9
.3.0/include -I/home/terjekv/.local/easybuild/software/X11/20200222-GCCcore-9.3.0/include -I/home/terjekv/.local/easybuild/software/libunwind/1.3.1-GCCcore-9.3.0/include -I/home/
terjekv/.local/easybuild/software/libglvnd/1.2.0-GCCcore-9.3.0/include -I/home/terjekv/.local/easybuild/software/libdrm/2.4.100-GCCcore-9.3.0/include -I/home/terjekv/.local/easyb
uild/software/zstd/1.4.4-GCCcore-9.3.0/include -I/home/terjekv/.local/easybuild/software/zlib/1.2.11-GCCcore-9.3.0/include -I/home/terjekv/.local/easybuild/software/gettext/0.20.
1-GCCcore-9.3.0/include -I/home/terjekv/.local/easybuild/software/expat/2.2.9-GCCcore-9.3.0/include -I/home/terjekv/.local/easybuild/software/libxml2/2.9.10-GCCcore-9.3.0/include
 -I/home/terjekv/.local/easybuild/software/flex/2.6.4-GCCcore-9.3.0/include -I/home/terjekv/.local/easybuild/software/binutils/2.34-GCCcore-9.3.0/include -fdiagnostics-color=alwa
ys -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c99 -O2 -g '-DPACKAGE_VERSION="20.0.2"' '-DPACKAGE_BUGREPORT="https://gitlab.freedesktop.org/mesa/mesa/issues"' -DUSE_ELF
_TLS -DENABLE_ST_OMX_BELLAGIO=0 -DENABLE_ST_OMX_TIZONIA=0 -DHAVE_X11_PLATFORM -DGLX_INDIRECT_RENDERING -DGLX_DIRECT_RENDERING -DGLX_USE_DRM -DENABLE_SHADER_CACHE -DHAVE___BUILTIN
_BSWAP32 -DHAVE___BUILTIN_BSWAP64 -DHAVE___BUILTIN_CLZ -DHAVE___BUILTIN_CLZLL -DHAVE___BUILTIN_CTZ -DHAVE___BUILTIN_EXPECT -DHAVE___BUILTIN_FFS -DHAVE___BUILTIN_FFSLL -DHAVE___BU
ILTIN_POPCOUNT -DHAVE___BUILTIN_POPCOUNTLL -DHAVE___BUILTIN_UNREACHABLE -DHAVE_FUNC_ATTRIBUTE_CONST -DHAVE_FUNC_ATTRIBUTE_FLATTEN -DHAVE_FUNC_ATTRIBUTE_MALLOC -DHAVE_FUNC_ATTRIBU
TE_PURE -DHAVE_FUNC_ATTRIBUTE_UNUSED -DHAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT -DHAVE_FUNC_ATTRIBUTE_WEAK -DHAVE_FUNC_ATTRIBUTE_FORMAT -DHAVE_FUNC_ATTRIBUTE_PACKED -DHAVE_FUNC_ATT
RIBUTE_RETURNS_NONNULL -DHAVE_FUNC_ATTRIBUTE_VISIBILITY -DHAVE_FUNC_ATTRIBUTE_ALIAS -DHAVE_FUNC_ATTRIBUTE_NORETURN -DHAVE_UINT128 -DUSE_GCC_ATOMIC_BUILTINS -DUSE_AARCH64_ASM -DMA
JOR_IN_SYSMACROS -DHAVE_SYS_SYSCTL_H -DHAVE_LINUX_FUTEX_H -DHAVE_ENDIAN_H -DHAVE_DLFCN_H -DHAVE_EXECINFO_H -DHAVE_SYS_SHM_H -DHAVE_STRTOF -DHAVE_MKOSTEMP -DHAVE_TIMESPEC_GET -DHA
VE_MEMFD_CREATE -DHAVE_RANDOM_R -DHAVE_FLOCK -DHAVE_STRTOK_R -DHAVE_PROGRAM_INVOCATION_NAME -DHAVE_POSIX_MEMALIGN -DHAVE_DIRENT_D_TYPE -DHAVE_STRTOD_L -DHAVE_DLADDR -DHAVE_DL_ITE
RATE_PHDR -DHAVE_ZLIB -DHAVE_ZSTD -DHAVE_PTHREAD -DHAVE_PTHREAD_SETAFFINITY -DHAVE_LIBDRM -DLLVM_AVAILABLE '-DMESA_LLVM_VERSION_STRING="9.0.1"' -DUSE_LIBGLVND=1 -DHAVE_LIBUNWIND
-DHAVE_DRI3 -DHAVE_DRI3_MODIFIERS -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=return-type -Werror=empty-body -Werror=incompatible-pointer-types -Werr
or=int-conversion -Wno-missing-field-initializers -Wno-format-truncation -fno-math-errno -fno-trapping-math -Werror=format -Wformat-security -O2 -ftree-vectorize -mcpu=native -fn
o-math-errno -fPIC -pthread -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D_GNU_SOURCE -D__STDC_FORMAT_MACROS -fvisibility=hidden -Werror=pointer-arith -Werror=vla -MD -MQ 'src
/gallium/auxiliary/eb820e8@@gallium@sta/util_u_debug_stack.c.o' -MF 'src/gallium/auxiliary/eb820e8@@gallium@sta/util_u_debug_stack.c.o.d' -o 'src/gallium/auxiliary/eb820e8@@galli
um@sta/util_u_debug_stack.c.o' -c ../mesa-20.0.2/src/gallium/auxiliary/util/u_debug_stack.c
In file included from /home/terjekv/.local/easybuild/software/libunwind/1.3.1-GCCcore-9.3.0/include/libunwind.h:7,
                 from ../mesa-20.0.2/src/gallium/auxiliary/util/u_debug_stack.h:35,
                 from ../mesa-20.0.2/src/gallium/auxiliary/util/u_debug_stack.c:37:
../mesa-20.0.2/src/gallium/auxiliary/util/u_debug_stack.c: In function debug_backtrace_capture:
/home/terjekv/.local/easybuild/software/libunwind/1.3.1-GCCcore-9.3.0/include/libunwind-aarch64.h:180:31: error: expected =, ,, ;, asm or __attribute__ before asm
  180 |   register uint64_t *unw_base asm ("x0") = (uint64_t*) unw_ctx->uc_mcontext.regs;  \
      |                               ^~~
```

Removing unwind support worked. Hm.

Resolving patch:
diff --git a/easybuild/easyblocks/m/mesa.py b/easybuild/easyblocks/m/mesa.py
--- a/easybuild/easyblocks/m/mesa.py
+++ b/easybuild/easyblocks/m/mesa.py
@@ -35,7 +35,8 @@
 
 from easybuild.easyblocks.generic.mesonninja import MesonNinja
 from easybuild.tools.filetools import copy_dir
-from easybuild.tools.systemtools import POWER, X86_64, get_cpu_architecture, get_cpu_features, get_shared_lib_ext
+from easybuild.tools.systemtools import POWER, X86_64, AARCH64
+from easybuild.tools.systemtools import get_cpu_architecture, get_cpu_features, get_shared_lib_ext
 
 
 class EB_Mesa(MesonNinja):
@@ -48,6 +49,16 @@ def __init__(self, *args, **kwargs):
 
         self.gallium_configopts = []
 
+        # Mesa fails to build with libunwind on aarch64
+        # See https://github.com/easybuilders/easybuild-easyblocks/issues/2150
+        if get_cpu_architecture() == AARCH64:
+            given_config_opts = self.cfg.get('configopts')
+            if "-Dlibunwind=true" in given_config_opts:
+                self.log.warning('libunwind not supported on aarch64, stripping from configopts!')
+                configopts_libunwind_stripped = given_config_opts.replace('-Dlibunwind=true', '-Dlibunwind=false')
+                self.cfg.set_keys({'configopts': configopts_libunwind_stripped})
+                self.log.warning('New configopts after stripping: ' + self.cfg.get('configopts'))
+
         # Check user-defined Gallium drivers
         gallium_drivers = self.get_configopt_value('gallium-drivers')
 
@@ -57,6 +68,7 @@ def __init__(self, *args, **kwargs):
             arch_gallium_drivers = {
                 X86_64: ['swrast', 'swr'],
                 POWER: ['swrast'],
+                AARCH64: ['swrast'],
             }
             if arch in arch_gallium_drivers:
                 gallium_drivers = arch_gallium_drivers[arch]


Test patch: