Skip to content

Commit 01d4ef4

Browse files
committed
detect host and arch for windows/cosmocc
1 parent 6e8697e commit 01d4ef4

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

core/src/xmake/engine.c

+31-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
#ifdef TB_CONFIG_OS_HAIKU
5050
# include <image.h>
5151
#endif
52+
#ifdef __COSMOPOLITAN__
53+
# include <sys/utsname.h>
54+
#endif
5255

5356
// for uid
5457
#ifndef TB_CONFIG_OS_WINDOWS
@@ -958,7 +961,18 @@ static tb_void_t xm_engine_init_host(xm_engine_t* engine)
958961

959962
// init system host
960963
tb_char_t const* syshost = tb_null;
961-
#if defined(TB_CONFIG_OS_WINDOWS)
964+
#if defined(__COSMOPOLITAN__)
965+
struct utsname buffer;
966+
if (uname(&buffer) == 0)
967+
{
968+
if (tb_strstr(buffer.sysname, "Darwin"))
969+
syshost = "macosx";
970+
else if (tb_strstr(buffer.sysname, "Linux"))
971+
syshost = "linux";
972+
else if (tb_strstr(buffer.sysname, "Windows"))
973+
syshost = "windows";
974+
}
975+
#elif defined(TB_CONFIG_OS_WINDOWS)
962976
syshost = "windows";
963977
#elif defined(TB_CONFIG_OS_MACOSX)
964978
syshost = "macosx";
@@ -1039,7 +1053,22 @@ static tb_void_t xm_engine_init_arch(xm_engine_t* engine)
10391053

10401054
// init system architecture
10411055
tb_char_t const* sysarch = tb_null;
1042-
#if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX)
1056+
#if defined(__COSMOPOLITAN__)
1057+
struct utsname buffer;
1058+
if (uname(&buffer) == 0)
1059+
{
1060+
sysarch = buffer.machine;
1061+
if (tb_strstr(buffer.sysname, "Windows"))
1062+
{
1063+
if (!tb_strcmp(buffer.machine, "x86_64"))
1064+
sysarch = "x64";
1065+
else if (!tb_strcmp(buffer.machine, "i686") || !tb_strcmp(buffer.machine, "i386"))
1066+
sysarch = "x86";
1067+
}
1068+
else if (!tb_strcmp(buffer.machine, "aarch64"))
1069+
sysarch = "arm64";
1070+
}
1071+
#elif defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX)
10431072
// the GetNativeSystemInfo function type
10441073
typedef void (WINAPI *GetNativeSystemInfo_t)(LPSYSTEM_INFO);
10451074

0 commit comments

Comments
 (0)