wesnoth: fix LLVM 19 compatibility

This commit is contained in:
Niklas Korz
2025-05-05 14:44:10 +02:00
parent 17a47125fa
commit effa279e04
2 changed files with 87 additions and 0 deletions
+28
View File
@@ -21,6 +21,7 @@
icu,
lua,
curl,
fetchpatch,
}:
stdenv.mkDerivation rec {
@@ -34,6 +35,33 @@ stdenv.mkDerivation rec {
hash = "sha256-c3BoTFnSUqtp71QeSCsC2teVuzsQwV8hOJtIcZdP+1E=";
};
# LLVM 19 removed support for types not officially supported by `std::char_traits`:
# https://libcxx.llvm.org/ReleaseNotes/19.html#deprecations-and-removals
# Wesnoth <1.19 relies on this previously supported non-standard behavior for
# some types that should either have been a vector or span:
# https://github.com/wesnoth/wesnoth/issues/9546
# Wesnoth moved to a `std::span` wrapper for byte views in the 1.19 branch, which we apply as
# patches until 1.20 is released.
patches = lib.optionals (stdenv.cc.isClang && lib.versionAtLeast stdenv.cc.version "19") [
# The next two patches are cherry-picked from https://github.com/wesnoth/wesnoth/pull/10102,
# which is already included in the 1.19 branch.
# Introduces the `std::span` wrapper based on `boost::span`.
(fetchpatch {
url = "https://github.com/wesnoth/wesnoth/commit/63266cc2c88fefa7e0792ac59d14c14e3711440c.patch";
hash = "sha256-3Zi/njG7Kovmyd7yiKUoeu4u0QPQxxw+uLz+k9isOLU=";
})
# Replace all string views with spans.
(fetchpatch {
url = "https://github.com/wesnoth/wesnoth/commit/d3daa161eb2c02670b5ffbcf86cd0ec787f6b9ee.patch";
hash = "sha256-9DCeZQZKE6fN91T5DCpNJsKGXbv5ihZC8UpuNkiA9zc=";
})
# Wesnoth <1.19 uses `std::basic_string` for lightmap computations, which is not standard compliant
# and incompatible to LLVM 19.
# While this was fixed in https://github.com/wesnoth/wesnoth/pull/10128, the fix is not
# trivially backportable to 1.18 so we apply a simpler fix instead.
./llvm19-lightmap.patch
];
nativeBuildInputs = [
cmake
pkg-config
+59
View File
@@ -0,0 +1,59 @@
diff --git a/src/display.cpp b/src/display.cpp
index 0f6552222b7..9d50046de2f 100644
--- a/src/display.cpp
+++ b/src/display.cpp
@@ -1082,7 +1082,8 @@ void display::get_terrain_images(const map_location& loc, const std::string& tim
// add the directional transitions
tod_color acol = atod1.color + color_adjust_;
- lt += image::get_light_string(d + 1, acol.r, acol.g, acol.b);
+ auto new_lt = image::get_light_string(d + 1, acol.r, acol.g, acol.b);
+ lt.insert(lt.end(), new_lt.begin(), new_lt.end());
}
for(int d = 0; d < 6; ++d) {
@@ -1114,7 +1115,8 @@ void display::get_terrain_images(const map_location& loc, const std::string& tim
// add the directional transitions
tod_color acol = atod1.color + color_adjust_;
- lt += image::get_light_string(d + 7, acol.r, acol.g, acol.b);
+ auto new_lt = image::get_light_string(d + 7, acol.r, acol.g, acol.b);
+ lt.insert(lt.end(), new_lt.begin(), new_lt.end());
}
for(int d = 0; d < 6; ++d) {
@@ -1146,7 +1148,8 @@ void display::get_terrain_images(const map_location& loc, const std::string& tim
// add the directional transitions
tod_color acol = atod2.color + color_adjust_;
- lt += image::get_light_string(d + 13, acol.r, acol.g, acol.b);
+ auto new_lt = image::get_light_string(d + 13, acol.r, acol.g, acol.b);
+ lt.insert(lt.end(), new_lt.begin(), new_lt.end());
}
if(lt.empty()){
diff --git a/src/picture.cpp b/src/picture.cpp
index e7aeddaa821..5ad1ebcbcbc 100644
--- a/src/picture.cpp
+++ b/src/picture.cpp
@@ -526,7 +526,9 @@ static surface apply_light(surface surf, const light_string& ls)
// decompose into atomic lightmap operations (4 chars)
for(std::size_t c = 0; c + 3 < ls.size(); c += 4) {
- light_string sls = ls.substr(c, 4);
+ auto start = ls.begin() + c;
+ auto end = start + 4;
+ light_string sls(start, end);
// get the corresponding image and apply the lightmap operation to it
// This allows to also cache lightmap parts.
diff --git a/src/picture.hpp b/src/picture.hpp
index 85a3b3a15a1..a26e1e27bc7 100644
--- a/src/picture.hpp
+++ b/src/picture.hpp
@@ -120,7 +120,7 @@ std::ostream& operator<<(std::ostream&, const locator&);
* 7-12: convex half-corners 1
* 13-19: convex half-corners 2
*/
-typedef std::basic_string<signed char> light_string;
+typedef std::vector<signed char> light_string;