mysql80: fix darwin and LLVM 19 build (#374591)

authored by Florian and committed by GitHub 772732cd 04bc698e

+195 -5
+12 -5
pkgs/servers/sql/mysql/8.0.x.nix
··· 2 2 lib, 3 3 stdenv, 4 4 fetchurl, 5 + fetchpatch, 5 6 bison, 6 7 cmake, 7 8 pkg-config, ··· 47 48 48 49 patches = [ 49 50 ./no-force-outline-atomics.patch # Do not force compilers to turn on -moutline-atomics switch 51 + # Fix compilation with LLVM 19, adapted from https://github.com/mysql/mysql-server/commit/3a51d7fca76e02257f5c42b6a4fc0c5426bf0421 52 + # in https://github.com/NixOS/nixpkgs/pull/374591#issuecomment-2615855076 53 + ./libcpp-fixes.patch 54 + (fetchpatch { 55 + url = "https://github.com/mysql/mysql-server/commit/4a5c00d26f95faa986ffed7a15ee15e868e9dcf2.patch"; 56 + hash = "sha256-MEl1lQlDYtFjHk0+S02RQFnxMr+YeFxAyNjpDtVHyeE="; 57 + }) 50 58 ]; 51 59 52 60 ## NOTE: MySQL upstream frequently twiddles the invocations of libtool. When updating, you might proactively grep for libtool references. 53 - postPatch = '' 54 - substituteInPlace cmake/libutils.cmake --replace /usr/bin/libtool libtool 55 - substituteInPlace cmake/os/Darwin.cmake --replace /usr/bin/libtool libtool 61 + postPatch = lib.optionalString stdenv.hostPlatform.isDarwin '' 62 + substituteInPlace cmake/libutils.cmake --replace-fail /usr/bin/libtool ${cctools}/bin/libtool 63 + substituteInPlace cmake/os/Darwin.cmake --replace-fail /usr/bin/libtool ${cctools}/bin/libtool 64 + substituteInPlace cmake/package_name.cmake --replace-fail "COMMAND sw_vers" "COMMAND ${DarwinTools}/bin/sw_vers" 56 65 ''; 57 66 58 67 buildInputs = ··· 77 86 libtirpc 78 87 ] 79 88 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 80 - cctools 81 89 CoreServices 82 90 developer_cmds 83 - DarwinTools 84 91 ]; 85 92 86 93 strictDeps = true;
+183
pkgs/servers/sql/mysql/libcpp-fixes.patch
··· 1 + diff --git a/include/my_char_traits.h b/include/my_char_traits.h 2 + new file mode 100644 3 + index 00000000..6336bc03 4 + --- /dev/null 5 + +++ b/include/my_char_traits.h 6 + @@ -0,0 +1,65 @@ 7 + +/* Copyright (c) 2024, Oracle and/or its affiliates. 8 + + 9 + + This program is free software; you can redistribute it and/or modify 10 + + it under the terms of the GNU General Public License, version 2.0, 11 + + as published by the Free Software Foundation. 12 + + 13 + + This program is designed to work with certain software (including 14 + + but not limited to OpenSSL) that is licensed under separate terms, 15 + + as designated in a particular file or component or in included license 16 + + documentation. The authors of MySQL hereby grant you an additional 17 + + permission to link the program and your derivative works with the 18 + + separately licensed software that they have either included with 19 + + the program or referenced in the documentation. 20 + + 21 + + This program is distributed in the hope that it will be useful, 22 + + but WITHOUT ANY WARRANTY; without even the implied warranty of 23 + + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 + + GNU General Public License, version 2.0, for more details. 25 + + 26 + + You should have received a copy of the GNU General Public License 27 + + along with this program; if not, write to the Free Software 28 + + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 29 + + 30 + +#ifndef MY_CHAR_TRAITS_INCLUDED 31 + +#define MY_CHAR_TRAITS_INCLUDED 32 + + 33 + +#include <cstring> 34 + + 35 + +template <class CharT> 36 + +struct my_char_traits; 37 + + 38 + +/* 39 + + This is a standards-compliant, drop-in replacement for 40 + + std::char_traits<unsigned char> 41 + + We need this because clang libc++ is removing support for it in clang 19. 42 + + It is not a complete implementation. Rather we implement just enough to 43 + + compile any usage of char_traits<uchar> we have in our codebase. 44 + + */ 45 + +template <> 46 + +struct my_char_traits<unsigned char> { 47 + + using char_type = unsigned char; 48 + + using int_type = unsigned int; 49 + + 50 + + static void assign(char_type &c1, const char_type &c2) { c1 = c2; } 51 + + 52 + + static char_type *assign(char_type *s, std::size_t n, char_type a) { 53 + + return static_cast<char_type *>(memset(s, a, n)); 54 + + } 55 + + 56 + + static int compare(const char_type *s1, const char_type *s2, std::size_t n) { 57 + + return memcmp(s1, s2, n); 58 + + } 59 + + 60 + + static char_type *move(char_type *s1, const char_type *s2, std::size_t n) { 61 + + if (n == 0) return s1; 62 + + return static_cast<char_type *>(memmove(s1, s2, n)); 63 + + } 64 + + 65 + + static char_type *copy(char_type *s1, const char_type *s2, std::size_t n) { 66 + + if (n == 0) return s1; 67 + + return static_cast<char_type *>(memcpy(s1, s2, n)); 68 + + } 69 + +}; 70 + + 71 + +#endif // MY_CHAR_TRAITS_INCLUDED 72 + diff --git a/sql/mdl_context_backup.h b/sql/mdl_context_backup.h 73 + index 89e7e23d..cf9c307e 100644 74 + --- a/sql/mdl_context_backup.h 75 + +++ b/sql/mdl_context_backup.h 76 + @@ -28,6 +28,7 @@ 77 + #include <map> 78 + #include <memory> 79 + 80 + +#include "my_char_traits.h" 81 + #include "sql/malloc_allocator.h" 82 + #include "sql/mdl.h" 83 + 84 + @@ -47,7 +48,8 @@ class MDL_context_backup_manager { 85 + /** 86 + Key for uniquely identifying MDL_context in the MDL_context_backup map. 87 + */ 88 + - typedef std::basic_string<uchar> MDL_context_backup_key; 89 + + using MDL_context_backup_key = 90 + + std::basic_string<uchar, my_char_traits<uchar>>; 91 + 92 + class MDL_context_backup; 93 + 94 + diff --git a/sql/stream_cipher.h b/sql/stream_cipher.h 95 + index 606d4064..358fbb41 100644 96 + --- a/sql/stream_cipher.h 97 + +++ b/sql/stream_cipher.h 98 + @@ -28,6 +28,8 @@ 99 + #include <memory> 100 + #include <string> 101 + 102 + +#include "my_char_traits.h" 103 + + 104 + /** 105 + @file stream_cipher.h 106 + 107 + @@ -35,7 +37,8 @@ 108 + binary log files. 109 + */ 110 + 111 + -typedef std::basic_string<unsigned char> Key_string; 112 + +using Key_string = 113 + + std::basic_string<unsigned char, my_char_traits<unsigned char>>; 114 + 115 + /** 116 + @class Stream_cipher 117 + diff --git a/unittest/gunit/binlogevents/transaction_compression-t.cc b/unittest/gunit/binlogevents/transaction_compression-t.cc 118 + index ba13f979..01af0e3a 100644 119 + --- a/unittest/gunit/binlogevents/transaction_compression-t.cc 120 + +++ b/unittest/gunit/binlogevents/transaction_compression-t.cc 121 + @@ -23,6 +23,7 @@ 122 + */ 123 + 124 + #include <array> 125 + +#include <string> 126 + 127 + #include <gtest/gtest.h> 128 + #include "libbinlogevents/include/binary_log.h" 129 + @@ -51,14 +52,13 @@ class TransactionPayloadCompressionTest : public ::testing::Test { 130 + using Managed_buffer_t = Decompressor_t::Managed_buffer_t; 131 + using Size_t = Decompressor_t::Size_t; 132 + using Char_t = Decompressor_t::Char_t; 133 + - using String_t = std::basic_string<Char_t>; 134 + using Decompress_status_t = 135 + binary_log::transaction::compression::Decompress_status; 136 + using Compress_status_t = 137 + binary_log::transaction::compression::Compress_status; 138 + 139 + - static String_t constant_data(Size_t size) { 140 + - return String_t(size, (Char_t)'a'); 141 + + static std::string constant_data(Size_t size) { 142 + + return std::string(size, (Char_t)'a'); 143 + } 144 + 145 + protected: 146 + @@ -69,7 +69,7 @@ class TransactionPayloadCompressionTest : public ::testing::Test { 147 + void TearDown() override {} 148 + 149 + static void compression_idempotency_test(Compressor_t &c, Decompressor_t &d, 150 + - String_t data) { 151 + + const std::string &data) { 152 + auto debug_string = concat( 153 + binary_log::transaction::compression::type_to_string(c.get_type_code()), 154 + " ", data.size()); 155 + @@ -104,8 +104,8 @@ class TransactionPayloadCompressionTest : public ::testing::Test { 156 + 157 + // Check decompressed data 158 + ASSERT_EQ(managed_buffer.read_part().size(), data.size()) << debug_string; 159 + - ASSERT_EQ(data, String_t(managed_buffer.read_part().begin(), 160 + - managed_buffer.read_part().end())) 161 + + ASSERT_EQ(data, std::string(managed_buffer.read_part().begin(), 162 + + managed_buffer.read_part().end())) 163 + << debug_string; 164 + 165 + // Check that we reached EOF 166 + @@ -118,7 +118,7 @@ TEST_F(TransactionPayloadCompressionTest, CompressDecompressZstdTest) { 167 + for (auto size : buffer_sizes) { 168 + binary_log::transaction::compression::Zstd_dec d; 169 + binary_log::transaction::compression::Zstd_comp c; 170 + - String_t data{TransactionPayloadCompressionTest::constant_data(size)}; 171 + + std::string data{TransactionPayloadCompressionTest::constant_data(size)}; 172 + TransactionPayloadCompressionTest::compression_idempotency_test(c, d, data); 173 + c.set_compression_level(22); 174 + TransactionPayloadCompressionTest::compression_idempotency_test(c, d, data); 175 + @@ -129,7 +129,7 @@ TEST_F(TransactionPayloadCompressionTest, CompressDecompressNoneTest) { 176 + for (auto size : buffer_sizes) { 177 + binary_log::transaction::compression::None_dec d; 178 + binary_log::transaction::compression::None_comp c; 179 + - String_t data{TransactionPayloadCompressionTest::constant_data(size)}; 180 + + std::string data{TransactionPayloadCompressionTest::constant_data(size)}; 181 + TransactionPayloadCompressionTest::compression_idempotency_test(c, d, data); 182 + } 183 + }