Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 31 May 2026 14:49:13 +0000
From:      Dimitry Andric <dim@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: e45b1bd3027b - main - graphics/mesa-dri: fix builds against llvm 20 and 21
Message-ID:  <6a1c4a69.27397.6c875ecc@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by dim:

URL: https://cgit.FreeBSD.org/ports/commit/?id=e45b1bd3027b31845938ab6c7a5adc28c87d7ece

commit e45b1bd3027b31845938ab6c7a5adc28c87d7ece
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2026-05-31 14:48:32 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2026-05-31 14:49:03 +0000

    graphics/mesa-dri: fix builds against llvm 20 and 21
    
    Add several upstream patches, as patch-llvm-20-* and patch-llvm-21-*, to
    make mesa build against llvm 20 and 21. Whenever mesa gets updated to a
    new version which includes those changes, the patches can easily be
    removed.
    
    PR:             290809, 290874
    MFH:            2026Q2
---
 graphics/mesa-dri/files/patch-llvm20-1 | 44 ++++++++++++++++++
 graphics/mesa-dri/files/patch-llvm20-2 | 82 ++++++++++++++++++++++++++++++++++
 graphics/mesa-dri/files/patch-llvm21-1 | 36 +++++++++++++++
 graphics/mesa-dri/files/patch-llvm21-2 | 42 +++++++++++++++++
 graphics/mesa-dri/files/patch-llvm21-3 | 46 +++++++++++++++++++
 graphics/mesa-dri/files/patch-llvm21-4 | 49 ++++++++++++++++++++
 6 files changed, 299 insertions(+)

diff --git a/graphics/mesa-dri/files/patch-llvm20-1 b/graphics/mesa-dri/files/patch-llvm20-1
new file mode 100644
index 000000000000..8031a3fb0c03
--- /dev/null
+++ b/graphics/mesa-dri/files/patch-llvm20-1
@@ -0,0 +1,44 @@
+From 14ebecd78711804bc60f56cc53632bfab9d375df Mon Sep 17 00:00:00 2001
+From: Karol Herbst <kherbst@redhat.com>
+Date: Mon, 2 Sep 2024 16:57:08 +0200
+Subject: [PATCH] clc: fix compilation error with llvm-20
+
+LLVM commit:
+https://github.com/llvm/llvm-project/commit/924a7d83b4287b3b85dd1ca29d2d3e1f0a10ea68
+
+Cc: mesa-stable
+Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11814
+Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
+Reviewed-by: David Heidelberg <david@ixit.cz>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30980>;
+---
+ src/compiler/clc/clc_helpers.cpp | 12 +++++++++---
+ 1 file changed, 9 insertions(+), 3 deletions(-)
+
+diff --git src/compiler/clc/clc_helpers.cpp src/compiler/clc/clc_helpers.cpp
+index 8da3a8fc5e85..24bc7914a13f 100644
+--- src/compiler/clc/clc_helpers.cpp
++++ src/compiler/clc/clc_helpers.cpp
+@@ -886,10 +886,16 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx,
+       return {};
+    }
+ 
+-   // GetResourcePath is a way to retrive the actual libclang resource dir based on a given binary
++   // GetResourcePath is a way to retrieve the actual libclang resource dir based on a given binary
+    // or library.
+-   auto clang_res_path =
+-      fs::path(Driver::GetResourcesPath(std::string(clang_path), CLANG_RESOURCE_DIR)) / "include";
++   auto tmp_res_path =
++#if LLVM_VERSION_MAJOR >= 20
++      Driver::GetResourcesPath(std::string(clang_path));
++#else
++      Driver::GetResourcesPath(std::string(clang_path), CLANG_RESOURCE_DIR);
++#endif
++   auto clang_res_path = fs::path(tmp_res_path) / "include";
++
+    free(clang_path);
+ 
+    c->getHeaderSearchOpts().UseBuiltinIncludes = true;
+-- 
+GitLab
+
diff --git a/graphics/mesa-dri/files/patch-llvm20-2 b/graphics/mesa-dri/files/patch-llvm20-2
new file mode 100644
index 000000000000..b23b4bd84c96
--- /dev/null
+++ b/graphics/mesa-dri/files/patch-llvm20-2
@@ -0,0 +1,82 @@
+From 8a453669e2bd44651cacdeac1c372d6e80cab0a7 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Kai=20Wasserb=C3=A4ch?= <kai@dev.carbon-project.org>
+Date: Mon, 2 Dec 2024 18:29:19 +0100
+Subject: [PATCH] fix(FTBFS): clc/clover: pass a VFS instance explicitly
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This just replicates what upstream did before breaking mesa with commit
+df9a14d7bbf and requiring a VFS instance.
+
+Reported-by: @Lone_Wolf
+Reference: <https://github.com/llvm/llvm-project/commit/df9a14d7bbf1180e4f1474254c9d7ed6bcb4ce55>;
+Closes: <https://gitlab.freedesktop.org/mesa/mesa/-/issues/12223>;
+Signed-off-by: Kai Wasserbäch <kai@dev.carbon-project.org>
+Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de>
+Reviewed-by: Karol Herbst <kherbst@redhat.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32439>;
+---
+ src/compiler/clc/clc_helpers.cpp                 | 10 +++++++++-
+ src/gallium/frontends/clover/llvm/invocation.cpp | 10 +++++++++-
+ 2 files changed, 18 insertions(+), 2 deletions(-)
+
+diff --git src/compiler/clc/clc_helpers.cpp src/compiler/clc/clc_helpers.cpp
+index f3f884b21809..ce0563d7f4fd 100644
+--- src/compiler/clc/clc_helpers.cpp
++++ src/compiler/clc/clc_helpers.cpp
+@@ -56,6 +56,10 @@
+ #include <spirv-tools/linker.hpp>
+ #include <spirv-tools/optimizer.hpp>
+ 
++#if LLVM_VERSION_MAJOR >= 20
++#include <llvm/Support/VirtualFileSystem.h>
++#endif
++
+ #include "util/macros.h"
+ #include "glsl_types.h"
+ 
+@@ -841,7 +845,11 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx,
+    // http://www.llvm.org/bugs/show_bug.cgi?id=19735
+    c->getDiagnosticOpts().ShowCarets = false;
+ 
+-   c->createDiagnostics(new clang::TextDiagnosticPrinter(
++   c->createDiagnostics(
++#if LLVM_VERSION_MAJOR >= 20
++                   *llvm::vfs::getRealFileSystem(),
++#endif
++                   new clang::TextDiagnosticPrinter(
+                            diag_log_stream,
+                            &c->getDiagnosticOpts()));
+ 
+diff --git src/gallium/frontends/clover/llvm/invocation.cpp src/gallium/frontends/clover/llvm/invocation.cpp
+index d2e238c880bd..3cbb05baecf6 100644
+--- src/gallium/frontends/clover/llvm/invocation.cpp
++++ src/gallium/frontends/clover/llvm/invocation.cpp
+@@ -40,6 +40,10 @@
+ #include <clang/Frontend/TextDiagnosticPrinter.h>
+ #include <clang/Basic/TargetInfo.h>
+ 
++#if LLVM_VERSION_MAJOR >= 20
++#include <llvm/Support/VirtualFileSystem.h>
++#endif
++
+ // We need to include internal headers last, because the internal headers
+ // include CL headers which have #define's like:
+ //
+@@ -305,7 +309,11 @@ namespace {
+                                 ::llvm::Triple(target.triple),
+                                 get_language_version(opts, device_clc_version));
+ 
+-      c->createDiagnostics(new clang::TextDiagnosticPrinter(
++      c->createDiagnostics(
++#if LLVM_VERSION_MAJOR >= 20
++                           *llvm::vfs::getRealFileSystem(),
++#endif
++                           new clang::TextDiagnosticPrinter(
+                               *new raw_string_ostream(r_log),
+                               &c->getDiagnosticOpts(), true));
+ 
+-- 
+GitLab
+
diff --git a/graphics/mesa-dri/files/patch-llvm21-1 b/graphics/mesa-dri/files/patch-llvm21-1
new file mode 100644
index 000000000000..39d6a0d50f39
--- /dev/null
+++ b/graphics/mesa-dri/files/patch-llvm21-1
@@ -0,0 +1,36 @@
+From 0e7c94b2b369ac0bf4439e207bc9047f2cd44ead Mon Sep 17 00:00:00 2001
+From: Natalie Vock <natalie.vock@gmx.de>
+Date: Mon, 10 Mar 2025 16:18:24 +0100
+Subject: [PATCH] ac/llvm: Don't use getTriple() on LLVM21+
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+setTargetTriple() takes a Triple now.
+
+Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
+Reviewed-by: Marek Olšák <marek.olsak@amd.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33981>;
+---
+ src/amd/llvm/ac_llvm_helper.cpp | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git src/amd/llvm/ac_llvm_helper.cpp src/amd/llvm/ac_llvm_helper.cpp
+index 1b6c955caa41..cb59123dacae 100644
+--- src/amd/llvm/ac_llvm_helper.cpp
++++ src/amd/llvm/ac_llvm_helper.cpp
+@@ -97,7 +97,11 @@ LLVMModuleRef ac_create_module(LLVMTargetMachineRef tm, LLVMContextRef ctx)
+    TargetMachine *TM = reinterpret_cast<TargetMachine *>(tm);
+    LLVMModuleRef module = LLVMModuleCreateWithNameInContext("mesa-shader", ctx);
+ 
++#if LLVM_VERSION_MAJOR >= 21
++   unwrap(module)->setTargetTriple(TM->getTargetTriple());
++#else
+    unwrap(module)->setTargetTriple(TM->getTargetTriple().getTriple());
++#endif
+    unwrap(module)->setDataLayout(TM->createDataLayout());
+    return module;
+ }
+-- 
+GitLab
+
diff --git a/graphics/mesa-dri/files/patch-llvm21-2 b/graphics/mesa-dri/files/patch-llvm21-2
new file mode 100644
index 000000000000..e2c27f9d4758
--- /dev/null
+++ b/graphics/mesa-dri/files/patch-llvm21-2
@@ -0,0 +1,42 @@
+From 531c6696d42953cd642dea7bf70153285c7949ae Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Kai=20Wasserb=C3=A4ch?= <kai@dev.carbon-project.org>
+Date: Tue, 6 May 2025 14:36:57 +0200
+Subject: [PATCH] fix(FTBFS): clc: switch to new non-owned `TargetOptions` for
+ LLVM 21
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Upstream hid the `TargetOptions` in commit 985410f87f2d19910a8d327527fd30062b042b63
+
+Use the new `getTargetOpts()` to obtain the `TargetOptions` for
+`setTarget()`.
+
+Signed-off-by: Kai Wasserbäch <kai@dev.carbon-project.org>
+Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13079
+Reference: https://github.com/llvm/llvm-project/commit/985410f87f2d19910a8d327527fd30062b042b63
+Reviewed-by: Karol Herbst <kherbst@redhat.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34835>;
+---
+ src/compiler/clc/clc_helpers.cpp | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git src/compiler/clc/clc_helpers.cpp src/compiler/clc/clc_helpers.cpp
+index 41d4c4baf995..5744d7b48296 100644
+--- src/compiler/clc/clc_helpers.cpp
++++ src/compiler/clc/clc_helpers.cpp
+@@ -864,7 +864,11 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx,
+                            &c->getDiagnosticOpts()));
+ 
+    c->setTarget(clang::TargetInfo::CreateTargetInfo(
++#if LLVM_VERSION_MAJOR >= 21
++                   c->getDiagnostics(), c->getInvocation().getTargetOpts()));
++#else
+                    c->getDiagnostics(), c->getInvocation().TargetOpts));
++#endif
+ 
+    c->getFrontendOpts().ProgramAction = clang::frontend::EmitLLVMOnly;
+ 
+-- 
+GitLab
+
diff --git a/graphics/mesa-dri/files/patch-llvm21-3 b/graphics/mesa-dri/files/patch-llvm21-3
new file mode 100644
index 000000000000..56c80b43b9c4
--- /dev/null
+++ b/graphics/mesa-dri/files/patch-llvm21-3
@@ -0,0 +1,46 @@
+From 392ad203ebc2060ccc83022d03f76a8d7bb2f614 Mon Sep 17 00:00:00 2001
+From: Karol Herbst <kherbst@redhat.com>
+Date: Sat, 7 Jun 2025 09:51:00 +0200
+Subject: [PATCH] clc: use new createTargetMachine overload with llvm-21
+
+The old one is deprecated, so let's move and silence the warning.
+
+Cc: mesa-stable
+Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35399>;
+---
+ src/compiler/clc/clc_helpers.cpp | 11 ++++++++++-
+ 1 file changed, 10 insertions(+), 1 deletion(-)
+
+diff --git src/compiler/clc/clc_helpers.cpp src/compiler/clc/clc_helpers.cpp
+index cbf46ce7aa49..2920f7325ed3 100644
+--- src/compiler/clc/clc_helpers.cpp
++++ src/compiler/clc/clc_helpers.cpp
+@@ -60,6 +60,10 @@
+ #include <spirv-tools/linker.hpp>
+ #include <spirv-tools/optimizer.hpp>
+ 
++#if LLVM_VERSION_MAJOR >= 16
++#include <llvm/TargetParser/Triple.h>
++#endif
++
+ #if LLVM_VERSION_MAJOR >= 20
+ #include <llvm/Support/VirtualFileSystem.h>
+ #endif
+@@ -1139,7 +1143,12 @@ llvm_mod_to_spirv(std::unique_ptr<::llvm::Module> mod,
+       auto target = TargetRegistry::lookupTarget(triple, error_msg);
+       if (target) {
+          auto TM = target->createTargetMachine(
+-            triple, "", "", {}, std::nullopt, std::nullopt,
++#if LLVM_VERSION_MAJOR >= 21
++            llvm::Triple(triple),
++#else
++            triple,
++#endif
++            "", "", {}, std::nullopt, std::nullopt,
+ #if LLVM_VERSION_MAJOR >= 18
+             ::llvm::CodeGenOptLevel::None
+ #else
+-- 
+GitLab
+
diff --git a/graphics/mesa-dri/files/patch-llvm21-4 b/graphics/mesa-dri/files/patch-llvm21-4
new file mode 100644
index 000000000000..f118959d499e
--- /dev/null
+++ b/graphics/mesa-dri/files/patch-llvm21-4
@@ -0,0 +1,49 @@
+From a482ec7f05d2aeac29dc696cbd17e12693ad1393 Mon Sep 17 00:00:00 2001
+From: Karol Herbst <kherbst@redhat.com>
+Date: Sat, 7 Jun 2025 10:13:06 +0200
+Subject: [PATCH] clc: fix DiagnosticOptions related build failure with llvm-21
+
+Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13257
+Cc: mesa-stable
+Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35399>;
+---
+ src/compiler/clc/clc_helpers.cpp | 12 +++++++++---
+ 1 file changed, 9 insertions(+), 3 deletions(-)
+
+diff --git src/compiler/clc/clc_helpers.cpp src/compiler/clc/clc_helpers.cpp
+index 2920f7325ed3..d3629ceccebd 100644
+--- src/compiler/clc/clc_helpers.cpp
++++ src/compiler/clc/clc_helpers.cpp
+@@ -804,11 +804,17 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx,
+       c->addDependencyCollector(dep);
+    }
+ 
++#if LLVM_VERSION_MAJOR >= 21
++   auto diag_opts = c->getDiagnosticOpts();
++#else
++   auto diag_opts = &c->getDiagnosticOpts();
++#endif
++
+    clang::DiagnosticsEngine diag {
+       new clang::DiagnosticIDs,
+-      new clang::DiagnosticOptions,
++      diag_opts,
+       new clang::TextDiagnosticPrinter(diag_log_stream,
+-                                       &c->getDiagnosticOpts())
++                                       diag_opts)
+    };
+ 
+ #if LLVM_VERSION_MAJOR >= 17
+@@ -865,7 +871,7 @@ clc_compile_to_llvm_module(LLVMContext &llvm_ctx,
+ #endif
+                    new clang::TextDiagnosticPrinter(
+                            diag_log_stream,
+-                           &c->getDiagnosticOpts()));
++                           diag_opts));
+ 
+    c->setTarget(clang::TargetInfo::CreateTargetInfo(
+ #if LLVM_VERSION_MAJOR >= 21
+-- 
+GitLab
+


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a1c4a69.27397.6c875ecc>