From 3a795fcf8b18163d8e823f8aa8553f98fcafde2a Mon Sep 17 00:00:00 2001 From: Maufeat Date: Mon, 21 Jul 2025 17:10:25 +0200 Subject: [PATCH] add: terminal output option and moltenvk header for mac --- CMakeLists.txt | 2 +- src/video_core/vulkan_common/vulkan.h | 4 ++ src/yuzu/debugger/console.cpp | 92 +++++++++++++++++++++++++-- 3 files changed, 90 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 124a5ac80a..75a46316a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,7 @@ option(YUZU_ENABLE_PORTABLE "Allow yuzu to enable portable mode if a user folder CMAKE_DEPENDENT_OPTION(YUZU_USE_FASTER_LD "Check if a faster linker is available" ON "NOT WIN32" OFF) -CMAKE_DEPENDENT_OPTION(USE_SYSTEM_MOLTENVK "Use the system MoltenVK lib (instead of the bundled one)" OFF "APPLE" OFF) +CMAKE_DEPENDENT_OPTION(USE_SYSTEM_MOLTENVK "Use the system MoltenVK lib (instead of the bundled one)" OFF "APPLE" ON) set(DEFAULT_ENABLE_OPENSSL ON) if (ANDROID OR WIN32 OR APPLE) diff --git a/src/video_core/vulkan_common/vulkan.h b/src/video_core/vulkan_common/vulkan.h index 62aa132915..26b9054886 100644 --- a/src/video_core/vulkan_common/vulkan.h +++ b/src/video_core/vulkan_common/vulkan.h @@ -15,7 +15,11 @@ #define VK_USE_PLATFORM_WAYLAND_KHR #endif +#ifdef __APPLE__ +#include +#else #include +#endif // Sanitize macros #undef CreateEvent diff --git a/src/yuzu/debugger/console.cpp b/src/yuzu/debugger/console.cpp index 1c1342ff18..6b131c88f3 100644 --- a/src/yuzu/debugger/console.cpp +++ b/src/yuzu/debugger/console.cpp @@ -2,9 +2,23 @@ // SPDX-License-Identifier: GPL-2.0-or-later #ifdef _WIN32 -#include - #include +#include +#endif + +#ifdef __APPLE__ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common/fs/path_util.h" + +extern char** environ; #endif #include "common/logging/backend.h" @@ -12,18 +26,76 @@ #include "yuzu/uisettings.h" namespace Debugger { +#ifdef __APPLE__ +namespace { + +pid_t g_terminal_pid = -1; +int g_saved_out = -1; +int g_saved_err = -1; + +std::string GetLogFilePath() { + std::string dir = Common::FS::GetEdenPathString(Common::FS::EdenPath::LogDir); + if (!dir.empty() && dir.back() != '/') + dir.push_back('/'); + return dir + "eden_log.txt"; +} + +void ShowMacConsole() { + const std::string logfile = GetLogFilePath(); + if (logfile.empty()) + return; + + g_saved_out = dup(STDOUT_FILENO); + g_saved_err = dup(STDERR_FILENO); + + int fd = ::open(logfile.c_str(), O_WRONLY | O_CREAT | O_APPEND, 0644); + if (fd == -1) + return; + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + close(fd); + +const std::string shell_cmd = + "osascript -e 'tell application \"Terminal\" " + "to do script \"printf \\\\e]1;Eden logs\\\\a\\\\e]2;Eden logs\\\\a; " + "tail -n +1 -F " + logfile + "\"'"; + + posix_spawnp(&g_terminal_pid, "/bin/sh", nullptr, nullptr, + (char* const[]){const_cast("/bin/sh"), const_cast("-c"), + const_cast(shell_cmd.c_str()), nullptr}, + environ); +} + +void HideMacConsole() { + if (g_terminal_pid > 0) { + kill(g_terminal_pid, SIGTERM); + g_terminal_pid = -1; + } + if (g_saved_out != -1) { + dup2(g_saved_out, STDOUT_FILENO); + close(g_saved_out); + g_saved_out = -1; + } + if (g_saved_err != -1) { + dup2(g_saved_err, STDERR_FILENO); + close(g_saved_err); + g_saved_err = -1; + } +} +} // namespace +#endif // __APPLE__ + void ToggleConsole() { static bool console_shown = false; - if (console_shown == UISettings::values.show_console.GetValue()) { + const bool want_console = UISettings::values.show_console.GetValue(); + if (console_shown == want_console) return; - } else { - console_shown = UISettings::values.show_console.GetValue(); - } + console_shown = want_console; using namespace Common::Log; #if defined(_WIN32) && !defined(_DEBUG) FILE* temp; - if (UISettings::values.show_console) { + if (want_console) { if (AllocConsole()) { // The first parameter for freopen_s is a out parameter, so we can just ignore it freopen_s(&temp, "CONIN$", "r", stdin); @@ -43,6 +115,12 @@ void ToggleConsole() { } } #else +#if defined(__APPLE__) + if (want_console) + ShowMacConsole(); + else + HideMacConsole(); +#endif SetColorConsoleBackendEnabled(UISettings::values.show_console.GetValue()); #endif }