From 9895cad019e737f24a8a2b1ee713ddb45d61f9b7 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sat, 2 Nov 2024 12:36:47 +0100 Subject: [PATCH] [Main] fix userMain on macOS --- src/Core/darwin/ThreadUtils.cpp | 4 +++- src/Core/darwin/ThreadUtilsImpl.h | 4 ++-- src/Core/darwin/ThreadUtilsImpl.m | 6 +++--- src/Main/macOS/Main-macOS.mm | 11 ++++------- src/Main/macOS/stormkit-Core.cpp | 11 +++++++++++ src/Main/macOS/stormkit-Core.hpp | 9 +++++++++ xmake.lua | 1 + 7 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 src/Main/macOS/stormkit-Core.cpp create mode 100644 src/Main/macOS/stormkit-Core.hpp diff --git a/src/Core/darwin/ThreadUtils.cpp b/src/Core/darwin/ThreadUtils.cpp index 96e8ed42..88aab712 100644 --- a/src/Core/darwin/ThreadUtils.cpp +++ b/src/Core/darwin/ThreadUtils.cpp @@ -1,6 +1,8 @@ module; +extern "C" { #include "ThreadUtilsImpl.h" +} module stormkit.Core; @@ -12,7 +14,7 @@ namespace stormkit { inline namespace core { //////////////////////////////////////// //////////////////////////////////////// auto setCurrentThreadName(std::string_view name) noexcept -> void { - ::setCurrentThreadName(std::data(name)); + setCurrentNSThreadName(std::data(name)); } //////////////////////////////////////// diff --git a/src/Core/darwin/ThreadUtilsImpl.h b/src/Core/darwin/ThreadUtilsImpl.h index 2f881454..ba3403f4 100644 --- a/src/Core/darwin/ThreadUtilsImpl.h +++ b/src/Core/darwin/ThreadUtilsImpl.h @@ -7,7 +7,7 @@ typedef void NSThread; #endif -void setThreadName(NSThread* id, const char* name); -void setCurrentThreadName(const char* name); +void setNSThreadName(NSThread* id, const char* name); +void setCurrentNSThreadName(const char* name); #endif diff --git a/src/Core/darwin/ThreadUtilsImpl.m b/src/Core/darwin/ThreadUtilsImpl.m index ae6b22e9..35289342 100644 --- a/src/Core/darwin/ThreadUtilsImpl.m +++ b/src/Core/darwin/ThreadUtilsImpl.m @@ -5,13 +5,13 @@ //////////////////////////////////////// //////////////////////////////////////// -void setThreadName(NSThread *id, const char *name) { +void setNSThreadName(NSThread *id, const char *name) { [id setName:[NSString stringWithCString:name encoding:NSASCIIStringEncoding]]; } //////////////////////////////////////// //////////////////////////////////////// -void setCurrentThreadName(const char *name) { +void setCurrentNSThreadName(const char *name) { NSThread *id = [NSThread currentThread]; - setThreadName(id, name); + setNSThreadName(id, name); } diff --git a/src/Main/macOS/Main-macOS.mm b/src/Main/macOS/Main-macOS.mm index 6f58cb5b..97f4163a 100644 --- a/src/Main/macOS/Main-macOS.mm +++ b/src/Main/macOS/Main-macOS.mm @@ -5,19 +5,16 @@ #include #include -extern auto userMain(std::span) -> int; +#include "stormkit-Core.hpp" -namespace stormkit { - extern auto setupSignalHandler() noexcept -> int; - extern auto setCurrentThreadName(std::string_view) noexcept -> void; -} // namespace stormkit +extern auto userMain(std::span) -> int; auto main(const int argc, const char **argv) -> int { [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] resourcePath]]; - stormkit::setupSignalHandler(); - stormkit::setCurrentThreadName("MainThread"); + setupSignalHandler(); + setCurrentThreadName("MainThread"); auto args = std::vector {}; diff --git a/src/Main/macOS/stormkit-Core.cpp b/src/Main/macOS/stormkit-Core.cpp new file mode 100644 index 00000000..81168438 --- /dev/null +++ b/src/Main/macOS/stormkit-Core.cpp @@ -0,0 +1,11 @@ +#include "stormkit-Core.hpp" + +import stormkit.Core; + +auto setupSignalHandler() -> void { + stormkit::setupSignalHandler(); +} + +auto setCurrentThreadName(std::string_view name) -> void { + stormkit::setCurrentThreadName(name); +} diff --git a/src/Main/macOS/stormkit-Core.hpp b/src/Main/macOS/stormkit-Core.hpp new file mode 100644 index 00000000..04f0aba8 --- /dev/null +++ b/src/Main/macOS/stormkit-Core.hpp @@ -0,0 +1,9 @@ +#ifndef STORMKIT_CORE_MAIN_HPP +#define STORMKIT_CORE_MAIN_HPP + +#include + +auto setupSignalHandler() -> void; +auto setCurrentThreadName(std::string_view name) -> void; + +#endif diff --git a/xmake.lua b/xmake.lua index 5eb259a5..38f12625 100644 --- a/xmake.lua +++ b/xmake.lua @@ -67,6 +67,7 @@ modules = { add_cxflags("-Wno-main") set_strip("debug") end, + frameworks = is_plat("macosx") and { "CoreFoundation" } or nil, }, wsi = { modulename = "Wsi",