Skip to content

Commit

Permalink
detect host and arch for windows/cosmocc
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Aug 22, 2024
1 parent 6e8697e commit 01d4ef4
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions core/src/xmake/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
#ifdef TB_CONFIG_OS_HAIKU
# include <image.h>
#endif
#ifdef __COSMOPOLITAN__
# include <sys/utsname.h>
#endif

// for uid
#ifndef TB_CONFIG_OS_WINDOWS
Expand Down Expand Up @@ -958,7 +961,18 @@ static tb_void_t xm_engine_init_host(xm_engine_t* engine)

// init system host
tb_char_t const* syshost = tb_null;
#if defined(TB_CONFIG_OS_WINDOWS)
#if defined(__COSMOPOLITAN__)
struct utsname buffer;
if (uname(&buffer) == 0)
{
if (tb_strstr(buffer.sysname, "Darwin"))
syshost = "macosx";
else if (tb_strstr(buffer.sysname, "Linux"))
syshost = "linux";
else if (tb_strstr(buffer.sysname, "Windows"))
syshost = "windows";
}
#elif defined(TB_CONFIG_OS_WINDOWS)
syshost = "windows";
#elif defined(TB_CONFIG_OS_MACOSX)
syshost = "macosx";
Expand Down Expand Up @@ -1039,7 +1053,22 @@ static tb_void_t xm_engine_init_arch(xm_engine_t* engine)

// init system architecture
tb_char_t const* sysarch = tb_null;
#if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX)
#if defined(__COSMOPOLITAN__)
struct utsname buffer;
if (uname(&buffer) == 0)
{
sysarch = buffer.machine;
if (tb_strstr(buffer.sysname, "Windows"))
{
if (!tb_strcmp(buffer.machine, "x86_64"))
sysarch = "x64";
else if (!tb_strcmp(buffer.machine, "i686") || !tb_strcmp(buffer.machine, "i386"))
sysarch = "x86";
}
else if (!tb_strcmp(buffer.machine, "aarch64"))
sysarch = "arm64";
}
#elif defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX)
// the GetNativeSystemInfo function type
typedef void (WINAPI *GetNativeSystemInfo_t)(LPSYSTEM_INFO);

Expand Down

0 comments on commit 01d4ef4

Please sign in to comment.