wesnoth: fix LLVM 19 compatibility

+87
+28
pkgs/games/wesnoth/default.nix
··· 21 21 icu, 22 22 lua, 23 23 curl, 24 + fetchpatch, 24 25 }: 25 26 26 27 stdenv.mkDerivation rec { ··· 33 34 repo = "wesnoth"; 34 35 hash = "sha256-c3BoTFnSUqtp71QeSCsC2teVuzsQwV8hOJtIcZdP+1E="; 35 36 }; 37 + 38 + # LLVM 19 removed support for types not officially supported by `std::char_traits`: 39 + # https://libcxx.llvm.org/ReleaseNotes/19.html#deprecations-and-removals 40 + # Wesnoth <1.19 relies on this previously supported non-standard behavior for 41 + # some types that should either have been a vector or span: 42 + # https://github.com/wesnoth/wesnoth/issues/9546 43 + # Wesnoth moved to a `std::span` wrapper for byte views in the 1.19 branch, which we apply as 44 + # patches until 1.20 is released. 45 + patches = lib.optionals (stdenv.cc.isClang && lib.versionAtLeast stdenv.cc.version "19") [ 46 + # The next two patches are cherry-picked from https://github.com/wesnoth/wesnoth/pull/10102, 47 + # which is already included in the 1.19 branch. 48 + # Introduces the `std::span` wrapper based on `boost::span`. 49 + (fetchpatch { 50 + url = "https://github.com/wesnoth/wesnoth/commit/63266cc2c88fefa7e0792ac59d14c14e3711440c.patch"; 51 + hash = "sha256-3Zi/njG7Kovmyd7yiKUoeu4u0QPQxxw+uLz+k9isOLU="; 52 + }) 53 + # Replace all string views with spans. 54 + (fetchpatch { 55 + url = "https://github.com/wesnoth/wesnoth/commit/d3daa161eb2c02670b5ffbcf86cd0ec787f6b9ee.patch"; 56 + hash = "sha256-9DCeZQZKE6fN91T5DCpNJsKGXbv5ihZC8UpuNkiA9zc="; 57 + }) 58 + # Wesnoth <1.19 uses `std::basic_string` for lightmap computations, which is not standard compliant 59 + # and incompatible to LLVM 19. 60 + # While this was fixed in https://github.com/wesnoth/wesnoth/pull/10128, the fix is not 61 + # trivially backportable to 1.18 so we apply a simpler fix instead. 62 + ./llvm19-lightmap.patch 63 + ]; 36 64 37 65 nativeBuildInputs = [ 38 66 cmake
+59
pkgs/games/wesnoth/llvm19-lightmap.patch
··· 1 + diff --git a/src/display.cpp b/src/display.cpp 2 + index 0f6552222b7..9d50046de2f 100644 3 + --- a/src/display.cpp 4 + +++ b/src/display.cpp 5 + @@ -1082,7 +1082,8 @@ void display::get_terrain_images(const map_location& loc, const std::string& tim 6 + 7 + // add the directional transitions 8 + tod_color acol = atod1.color + color_adjust_; 9 + - lt += image::get_light_string(d + 1, acol.r, acol.g, acol.b); 10 + + auto new_lt = image::get_light_string(d + 1, acol.r, acol.g, acol.b); 11 + + lt.insert(lt.end(), new_lt.begin(), new_lt.end()); 12 + } 13 + 14 + for(int d = 0; d < 6; ++d) { 15 + @@ -1114,7 +1115,8 @@ void display::get_terrain_images(const map_location& loc, const std::string& tim 16 + 17 + // add the directional transitions 18 + tod_color acol = atod1.color + color_adjust_; 19 + - lt += image::get_light_string(d + 7, acol.r, acol.g, acol.b); 20 + + auto new_lt = image::get_light_string(d + 7, acol.r, acol.g, acol.b); 21 + + lt.insert(lt.end(), new_lt.begin(), new_lt.end()); 22 + } 23 + 24 + for(int d = 0; d < 6; ++d) { 25 + @@ -1146,7 +1148,8 @@ void display::get_terrain_images(const map_location& loc, const std::string& tim 26 + 27 + // add the directional transitions 28 + tod_color acol = atod2.color + color_adjust_; 29 + - lt += image::get_light_string(d + 13, acol.r, acol.g, acol.b); 30 + + auto new_lt = image::get_light_string(d + 13, acol.r, acol.g, acol.b); 31 + + lt.insert(lt.end(), new_lt.begin(), new_lt.end()); 32 + } 33 + 34 + if(lt.empty()){ 35 + diff --git a/src/picture.cpp b/src/picture.cpp 36 + index e7aeddaa821..5ad1ebcbcbc 100644 37 + --- a/src/picture.cpp 38 + +++ b/src/picture.cpp 39 + @@ -526,7 +526,9 @@ static surface apply_light(surface surf, const light_string& ls) 40 + 41 + // decompose into atomic lightmap operations (4 chars) 42 + for(std::size_t c = 0; c + 3 < ls.size(); c += 4) { 43 + - light_string sls = ls.substr(c, 4); 44 + + auto start = ls.begin() + c; 45 + + auto end = start + 4; 46 + + light_string sls(start, end); 47 + 48 + // get the corresponding image and apply the lightmap operation to it 49 + // This allows to also cache lightmap parts. 50 + diff --git a/src/picture.hpp b/src/picture.hpp 51 + index 85a3b3a15a1..a26e1e27bc7 100644 52 + --- a/src/picture.hpp 53 + +++ b/src/picture.hpp 54 + @@ -120,7 +120,7 @@ std::ostream& operator<<(std::ostream&, const locator&); 55 + * 7-12: convex half-corners 1 56 + * 13-19: convex half-corners 2 57 + */ 58 + -typedef std::basic_string<signed char> light_string; 59 + +typedef std::vector<signed char> light_string;