Skip to content

Commit

Permalink
[Main] fix userMain on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthapz committed Nov 2, 2024
1 parent bc43dd5 commit 9895cad
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/Core/darwin/ThreadUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module;

extern "C" {
#include "ThreadUtilsImpl.h"
}

module stormkit.Core;

Expand All @@ -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));
}

////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/Core/darwin/ThreadUtilsImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/Core/darwin/ThreadUtilsImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
11 changes: 4 additions & 7 deletions src/Main/macOS/Main-macOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
#include <string_view>
#include <vector>

extern auto userMain(std::span<const std::string_view>) -> 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<const std::string_view>) -> 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<std::string_view> {};

Expand Down
11 changes: 11 additions & 0 deletions src/Main/macOS/stormkit-Core.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
9 changes: 9 additions & 0 deletions src/Main/macOS/stormkit-Core.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef STORMKIT_CORE_MAIN_HPP
#define STORMKIT_CORE_MAIN_HPP

#include <string_view>

auto setupSignalHandler() -> void;
auto setCurrentThreadName(std::string_view name) -> void;

#endif
1 change: 1 addition & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ modules = {
add_cxflags("-Wno-main")
set_strip("debug")
end,
frameworks = is_plat("macosx") and { "CoreFoundation" } or nil,
},
wsi = {
modulename = "Wsi",
Expand Down

0 comments on commit 9895cad

Please sign in to comment.