diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 4ff2afe7..ca5365ce 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -49,8 +49,7 @@ jobs: cmake -G "${{ matrix.config.GENERATOR }}" -A x64 ` -D CMAKE_BUILD_TYPE=${{ matrix.config.BUILD_TYPE }} ` -D BUILD_SHARED_LIBS=${{ matrix.config.BUILD_SHARED }} ` - -D SPDLOG_WCHAR_SUPPORT=${{ matrix.config.WCHAR }} ` - -D SPDLOG_WCHAR_FILENAMES=${{ matrix.config.WCHAR_FILES }} ` + -D SPDLOG_WCHAR_SUPPORT=${{ matrix.config.WCHAR }} ` -D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} ` -D SPDLOG_BUILD_TESTS=ON ` -D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} ` @@ -83,7 +82,6 @@ jobs: BUILD_SHARED: 'ON' FATAL_ERRORS: 'ON' WCHAR: 'OFF' - WCHAR_FILES: 'OFF' BUILD_EXAMPLE: 'ON' CXX_STANDARD: 17 - GENERATOR: "Visual Studio 16 2019" @@ -91,7 +89,6 @@ jobs: BUILD_SHARED: 'ON' FATAL_ERRORS: 'ON' WCHAR: 'OFF' - WCHAR_FILES: 'OFF' BUILD_EXAMPLE: 'ON' CXX_STANDARD: 20 @@ -107,8 +104,7 @@ jobs: cmake -G "${{ matrix.config.GENERATOR }}" -A x64 ` -D CMAKE_BUILD_TYPE=${{ matrix.config.BUILD_TYPE }} ` -D BUILD_SHARED_LIBS=${{ matrix.config.BUILD_SHARED }} ` - -D SPDLOG_WCHAR_SUPPORT=${{ matrix.config.WCHAR }} ` - -D SPDLOG_WCHAR_FILENAMES=${{ matrix.config.WCHAR_FILES }} ` + -D SPDLOG_WCHAR_SUPPORT=${{ matrix.config.WCHAR }} ` -D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} ` -D SPDLOG_BUILD_TESTS=ON ` -D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} ` diff --git a/CMakeLists.txt b/CMakeLists.txt index 20f6a7df..8f6ca16d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,13 +78,6 @@ option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT}) option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of of fetching from gitub." OFF) option(SPDLOG_NO_EXCEPTIONS "Compile with -fno-exceptions. Call abort() on any spdlog exceptions" OFF) -# misc tweakme options -if(WIN32) - option(SPDLOG_WCHAR_FILENAMES "Support wchar filenames" OFF) -else() - set(SPDLOG_WCHAR_FILENAMES OFF CACHE BOOL "non supported option" FORCE) -endif() - if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") option(SPDLOG_CLOCK_COARSE "Use CLOCK_REALTIME_COARSE instead of the regular clock," OFF) else() diff --git a/cmake/spdlog_config.h.in b/cmake/spdlog_config.h.in index 4dfdd820..617692e4 100644 --- a/cmake/spdlog_config.h.in +++ b/cmake/spdlog_config.h.in @@ -6,8 +6,6 @@ #pragma once -// Support wchar filenames (Windows only) -#cmakedefine SPDLOG_WCHAR_FILENAMES // No exceptions. Will do std::abort() instead #cmakedefine SPDLOG_NO_EXCEPTIONS diff --git a/include/spdlog/common.h b/include/spdlog/common.h index d076d455..7f489a92 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -39,9 +39,6 @@ #define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string) #define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string) -#if defined(SPDLOG_WCHAR_FILENAMES) - #include "fmt/xchar.h" -#endif #ifndef SPDLOG_FUNCTION #define SPDLOG_FUNCTION static_cast(__FUNCTION__) @@ -71,15 +68,8 @@ namespace sinks { class sink; } -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) -using filename_t = std::wstring; -// allow macro expansion to occur in SPDLOG_FILENAME_T - #define SPDLOG_FILENAME_T_INNER(s) L##s - #define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s) -#else using filename_t = std::string; - #define SPDLOG_FILENAME_T(s) s -#endif +#define SPDLOG_FILENAME_T(s) s using log_clock = std::chrono::system_clock; using sink_ptr = std::shared_ptr; @@ -199,14 +189,6 @@ namespace details { [[nodiscard]] constexpr spdlog::string_view_t to_string_view(spdlog::string_view_t str) noexcept { return str; } -#if defined(SPDLOG_WCHAR_FILENAMES) -[[nodiscard]] constexpr spdlog::wstring_view_t to_string_view(const wmemory_buf_t &buf) noexcept { - return spdlog::wstring_view_t{buf.data(), buf.size()}; -} - -[[nodiscard]] constexpr spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) noexcept { return str; } -#endif - template [[nodiscard]] constexpr fmt::basic_string_view to_string_view(fmt::basic_format_string fmt) noexcept { return fmt; diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 332fb7ff..541acf0a 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -75,12 +75,6 @@ SPDLOG_API bool is_color_terminal() noexcept; // Source: https://github.com/agauniyal/rang/ SPDLOG_API bool in_terminal(FILE *file) noexcept; -#if defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32) -SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target); - -SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target); -#endif - // Return directory name from given path or empty string // "abc/file" => "abc" // "abc/" => "abc" diff --git a/include/spdlog/sinks/daily_file_sink.h b/include/spdlog/sinks/daily_file_sink.h index e15a00da..d8f2a100 100644 --- a/include/spdlog/sinks/daily_file_sink.h +++ b/include/spdlog/sinks/daily_file_sink.h @@ -45,13 +45,9 @@ struct daily_filename_calculator { */ struct daily_filename_format_calculator { static filename_t calc_filename(const filename_t &file_path, const tm &now_tm) { -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) - std::wstringstream stream; -#else - std::stringstream stream; -#endif - stream << std::put_time(&now_tm, file_path.c_str()); - return stream.str(); + std::stringstream stream; + stream << std::put_time(&now_tm, file_path.c_str()); + return stream.str(); } }; diff --git a/src/details/os_windows.cpp b/src/details/os_windows.cpp index 3b689225..8fdcc569 100644 --- a/src/details/os_windows.cpp +++ b/src/details/os_windows.cpp @@ -31,11 +31,6 @@ #include #endif -#if defined(SPDLOG_WCHAR_FILENAMES) - #include - #include -#endif - #include // for _mkdir/_wmkdir // clang-format on @@ -67,11 +62,7 @@ std::tm gmtime() noexcept { } bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) { -#ifdef SPDLOG_WCHAR_FILENAMES - *fp = ::_wfsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); -#else *fp = ::_fsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); -#endif #if defined(SPDLOG_PREVENT_CHILD_FD) if (*fp != nullptr) { auto file_handle = reinterpret_cast(_get_osfhandle(::_fileno(*fp))); @@ -85,31 +76,19 @@ bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) { } int remove(const filename_t &filename) noexcept { -#if defined(SPDLOG_WCHAR_FILENAMES) - return ::_wremove(filename.c_str()); -#else return std::remove(filename.c_str()); -#endif } int remove_if_exists(const filename_t &filename) noexcept { return path_exists(filename) ? remove(filename) : 0; } int rename(const filename_t &filename1, const filename_t &filename2) noexcept { -#if defined(SPDLOG_WCHAR_FILENAMES) - return ::_wrename(filename1.c_str(), filename2.c_str()); -#else return std::rename(filename1.c_str(), filename2.c_str()); -#endif } // Return true if path exists (file or directory) bool path_exists(const filename_t &filename) noexcept { struct _stat buffer; -#ifdef SPDLOG_WCHAR_FILENAMES - return (::_wstat(filename.c_str(), &buffer) == 0); -#else return (::_stat(filename.c_str(), &buffer) == 0); -#endif } #ifdef _MSC_VER @@ -180,16 +159,7 @@ size_t thread_id() noexcept { // See https://github.com/gabime/spdlog/issues/609 void sleep_for_millis(unsigned int milliseconds) noexcept { ::Sleep(milliseconds); } -// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined) -#if defined(SPDLOG_WCHAR_FILENAMES) -std::string filename_to_str(const filename_t &filename) { - memory_buf_t buf; - wstr_to_utf8buf(filename, buf); - return SPDLOG_BUF_TO_STRING(buf); -} -#else std::string filename_to_str(const filename_t &filename) { return filename; } -#endif int pid() noexcept { return static_cast(::GetCurrentProcessId()); } @@ -197,72 +167,9 @@ bool is_color_terminal() noexcept { return true; } // Determine if the terminal attached bool in_terminal(FILE *file) noexcept { return ::_isatty(_fileno(file)) != 0; } - -#if defined(SPDLOG_WCHAR_FILENAMES) -void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target) { - if (wstr.size() > static_cast((std::numeric_limits::max)()) / 4 - 1) { - throw_spdlog_ex("UTF-16 string is too big to be converted to UTF-8"); - } - - int wstr_size = static_cast(wstr.size()); - if (wstr_size == 0) { - target.resize(0); - return; - } - - int result_size = static_cast(target.capacity()); - if ((wstr_size + 1) * 4 > result_size) { - result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, NULL, 0, NULL, NULL); - } - - if (result_size > 0) { - target.resize(result_size); - result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, target.data(), result_size, NULL, NULL); - - if (result_size > 0) { - target.resize(result_size); - return; - } - } - - throw_spdlog_ex(fmt_lib::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError())); -} - -void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) { - if (str.size() > static_cast((std::numeric_limits::max)()) - 1) { - throw_spdlog_ex("UTF-8 string is too big to be converted to UTF-16"); - } - - int str_size = static_cast(str.size()); - if (str_size == 0) { - target.resize(0); - return; - } - - // find the size to allocate for the result buffer - int result_size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, NULL, 0); - - if (result_size > 0) { - target.resize(result_size); - result_size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, target.data(), result_size); - if (result_size > 0) { - assert(result_size == target.size()); - return; - } - } - - throw_spdlog_ex(fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError())); -} -#endif // defined(SPDLOG_WCHAR_FILENAMES) - // return true on success static bool mkdir_(const filename_t &path) { -# -#ifdef SPDLOG_WCHAR_FILENAMES - return ::_wmkdir(path.c_str()) == 0; -#else return ::_mkdir(path.c_str()) == 0; -#endif } // create the given directory - and all directories leading to it diff --git a/tests/test_daily_and_rotation_loggers.cpp b/tests/test_daily_and_rotation_loggers.cpp index 619d95c7..630271dd 100644 --- a/tests/test_daily_and_rotation_loggers.cpp +++ b/tests/test_daily_and_rotation_loggers.cpp @@ -8,17 +8,6 @@ using filename_memory_buf_t = spdlog::memory_buf_t; -// #ifdef SPDLOG_WCHAR_FILENAMES -// std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) { -// spdlog::memory_buf_t buf; -// spdlog::details::os::wstr_to_utf8buf(spdlog::wstring_view_t(w.data(), w.size()), buf); -// return SPDLOG_BUF_TO_STRING(buf); -// } -// #else -// std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) { return SPDLOG_BUF_TO_STRING(w); } -// #endif - -std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) { return SPDLOG_BUF_TO_STRING(w); } TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]") { using sink_type = spdlog::sinks::daily_file_sink; @@ -38,7 +27,7 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]") { } logger->flush(); - require_message_count(filename_buf_to_utf8string(w), 10); + require_message_count(SPDLOG_BUF_TO_STRING(w), 10); } struct custom_daily_file_name_calculator { @@ -69,7 +58,7 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]") { } logger->flush(); - require_message_count(filename_buf_to_utf8string(w), 10); + require_message_count(SPDLOG_BUF_TO_STRING(w), 10); } /*