Repository: mesonbuild/meson

Issue:
llvm dependency fails to locate llvm-config on fedora 30
```
llvm-config found: NO need '>= 3.5'
Dependency LLVM found: NO (tried config-tool)

src/plugins/clang/meson.build:47:0: ERROR: Dependency "llvm" not found, tried config-tool
```

Apparently, the tool has been named something rather odd now, 'llvm-config-64', which seems to differ from other naming schemes in `dependencies.py`.

```
rpm -q --whatprovides /usr/bin/llvm-config-64 
llvm-devel-8.0.0-0.4.rc3.fc30.x86_64
```


Discussion:
Furthermore, older llvm-config have been renamed wackier.

```
rpm -q --whatprovides /usr/bin/llvm-config-7.0-64 
llvm7.0-7.0.1-4.fc30.x86_64
llvm7.0-devel-7.0.1-4.fc30.x86_64
```
sigh, I really wish people would stop being clever.
@chergert aside from this autodetection (which will be fixed), you can also set `llvm-config` in the native file.

Resolving patch:
diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py
--- a/mesonbuild/dependencies/dev.py
+++ b/mesonbuild/dependencies/dev.py
@@ -1,4 +1,4 @@
-# Copyright 2013-2017 The Meson development team
+# Copyright 2013-2019 The Meson development team
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
 import re
 
 from .. import mesonlib
-from ..mesonlib import version_compare, stringlistify, extract_as_list
+from ..mesonlib import version_compare, stringlistify, extract_as_list, MachineChoice
 from .base import (
     DependencyException, DependencyMethods, ExternalDependency, PkgConfigDependency,
     strip_system_libdirs, ConfigToolDependency,
@@ -203,30 +203,40 @@ class LLVMDependency(ConfigToolDependency):
     LLVM uses a special tool, llvm-config, which has arguments for getting
     c args, cxx args, and ldargs as well as version.
     """
-
-    # Ordered list of llvm-config binaries to try. Start with base, then try
-    # newest back to oldest (3.5 is arbitrary), and finally the devel version.
-    # Please note that llvm-config-6.0 is a development snapshot and it should
-    # not be moved to the beginning of the list.
-    tools = [
-        'llvm-config', # base
-        'llvm-config-8',   'llvm-config80',
-        'llvm-config-7',   'llvm-config70',
-        'llvm-config-6.0', 'llvm-config60',
-        'llvm-config-5.0', 'llvm-config50',
-        'llvm-config-4.0', 'llvm-config40',
-        'llvm-config-3.9', 'llvm-config39',
-        'llvm-config-3.8', 'llvm-config38',
-        'llvm-config-3.7', 'llvm-config37',
-        'llvm-config-3.6', 'llvm-config36',
-        'llvm-config-3.5', 'llvm-config35',
-        'llvm-config-9',     # Debian development snapshot
-        'llvm-config-devel', # FreeBSD development snapshot
-    ]
     tool_name = 'llvm-config'
     __cpp_blacklist = {'-DNDEBUG'}
 
     def __init__(self, environment, kwargs):
+        # Ordered list of llvm-config binaries to try. Start with base, then try
+        # newest back to oldest (3.5 is arbitrary), and finally the devel version.
+        # Please note that llvm-config-6.0 is a development snapshot and it should
+        # not be moved to the beginning of the list.
+        self.tools = [
+            'llvm-config', # base
+            'llvm-config-8',   'llvm-config80',
+            'llvm-config-7',   'llvm-config70',
+            'llvm-config-6.0', 'llvm-config60',
+            'llvm-config-5.0', 'llvm-config50',
+            'llvm-config-4.0', 'llvm-config40',
+            'llvm-config-3.9', 'llvm-config39',
+            'llvm-config-3.8', 'llvm-config38',
+            'llvm-config-3.7', 'llvm-config37',
+            'llvm-config-3.6', 'llvm-config36',
+            'llvm-config-3.5', 'llvm-config35',
+            'llvm-config-9',     # Debian development snapshot
+            'llvm-config-devel', # FreeBSD development snapshot
+        ]
+
+        # Fedora starting with Fedora 30 adds a suffix of the number
+        # of bits in the isa that llvm targets, for example, on x86_64
+        # and aarch64 the name will be llvm-config-64, on x86 and arm
+        # it will be llvm-config-32.
+        m = MachineChoice.BUILD if environment.is_cross_build() and kwargs.get('native', True) else MachineChoice.HOST
+        if environment.machines[m].is_64_bit:
+            self.tools.append('llvm-config-64')
+        else:
+            self.tools.append('llvm-config-32')
+
         # It's necessary for LLVM <= 3.8 to use the C++ linker. For 3.9 and 4.0
         # the C linker works fine if only using the C API.
         super().__init__('LLVM', environment, 'cpp', kwargs)
diff --git a/mesonbuild/envconfig.py b/mesonbuild/envconfig.py
--- a/mesonbuild/envconfig.py
+++ b/mesonbuild/envconfig.py
@@ -55,6 +55,18 @@
     'x86_64'
 )
 
+# It would feel more natural to call this "64_BIT_CPU_FAMILES", but
+# python identifiers cannot start with numbers
+CPU_FAMILES_64_BIT = [
+    'aarch64',
+    'ia64',
+    'mips64',
+    'ppc64',
+    'riscv64',
+    'sparc64',
+    'x86_64',
+]
+
 class MesonConfigFile:
     @classmethod
     def parse_datafile(cls, filename):
@@ -150,6 +162,7 @@ def __init__(self, system, cpu_family, cpu, endian):
         self.cpu_family = cpu_family
         self.cpu = cpu
         self.endian = endian
+        self.is_64_bit = cpu_family in CPU_FAMILES_64_BIT
 
     def __eq__(self, other):
         if self.__class__ is not other.__class__:


Test patch: