From 192f4171d8a9cb7f2e675b4b96f16770bcf2bd15 Mon Sep 17 00:00:00 2001
From: Jan Tojnar <jtojnar@gmail.com>
Date: Mon, 24 Dec 2018 15:38:52 +0100
Subject: [PATCH 1/2] llvm: allow passing arbitrary targets

Mesa requires AMDGPU target but previously, we only allowed a pre-defined set
of targets.
---
 pkgs/development/compilers/llvm/common.nix | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/pkgs/development/compilers/llvm/common.nix b/pkgs/development/compilers/llvm/common.nix
index e4f55963a6fb..27f48ff3f113 100644
--- a/pkgs/development/compilers/llvm/common.nix
+++ b/pkgs/development/compilers/llvm/common.nix
@@ -2,7 +2,9 @@
 
 rec {
   llvmBackend = platform:
-    if platform.parsed.cpu.family == "x86" then
+    if builtins.typeOf platform == "string" then
+      platform
+    else if platform.parsed.cpu.family == "x86" then
       "X86"
     else if platform.parsed.cpu.name == "aarch64" then
       "AArch64"

From ff22d90308d404dede8319fa6e22502ea058d3aa Mon Sep 17 00:00:00 2001
From: Jan Tojnar <jtojnar@gmail.com>
Date: Mon, 24 Dec 2018 15:39:49 +0100
Subject: [PATCH 2/2] mesa_noglu: fix build
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

LLVM’s `LLVM_TARGETS_TO_BUILD` build flag defauls to `all`, which contains
`AMDGPU` among others. [1] Changes in llvm [2] switched to explicitly listing
host and target platforms, excluding the AMDGPU target, which is required
for Mesa to build.

[1]: https://github.com/llvm-mirror/llvm/blob/db50b6fe399b8ad8caef80fd8ee77607fb051fa5/CMakeLists.txt#L286-L302
[2]: https://github.com/NixOS/nixpkgs/pull/52031
---
 pkgs/development/compilers/llvm/6/llvm.nix | 3 ++-
 pkgs/development/compilers/llvm/7/llvm.nix | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/pkgs/development/compilers/llvm/6/llvm.nix b/pkgs/development/compilers/llvm/6/llvm.nix
index 328f95f11b34..54617a075734 100644
--- a/pkgs/development/compilers/llvm/6/llvm.nix
+++ b/pkgs/development/compilers/llvm/6/llvm.nix
@@ -13,7 +13,8 @@
 , fetchpatch
 , debugVersion ? false
 , enableManpages ? false
-, enableTargets ? [ stdenv.hostPlatform stdenv.targetPlatform ]
+# Mesa requires AMDGPU target
+, enableTargets ? [ stdenv.hostPlatform stdenv.targetPlatform "AMDGPU" ]
 , enableSharedLibraries ? true
 }:
 
diff --git a/pkgs/development/compilers/llvm/7/llvm.nix b/pkgs/development/compilers/llvm/7/llvm.nix
index 2ef6b147214c..a852822cddc4 100644
--- a/pkgs/development/compilers/llvm/7/llvm.nix
+++ b/pkgs/development/compilers/llvm/7/llvm.nix
@@ -14,7 +14,8 @@
 , debugVersion ? false
 , enableManpages ? false
 , enableSharedLibraries ? true
-, enableTargets ? [ stdenv.hostPlatform stdenv.targetPlatform ]
+# Mesa requires AMDGPU target
+, enableTargets ? [ stdenv.hostPlatform stdenv.targetPlatform "AMDGPU" ]
 , enablePFM ? !stdenv.isDarwin
 }: