From ca26a3de870e281b15c16363dcdb0d63450b0d51 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Thu, 3 Oct 2024 23:11:42 +0100 Subject: [PATCH 1/2] Fix `os.host` for Cosmopolitan build. --- src/host/os_host.c | 24 +++++++++++++++++++++++- src/host/premake.c | 22 ---------------------- tests/base/test_os.lua | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/host/os_host.c b/src/host/os_host.c index ce6b6c697..cde59d647 100644 --- a/src/host/os_host.c +++ b/src/host/os_host.c @@ -6,8 +6,30 @@ #include "premake.h" +#if PLATFORM_COSMO +#include +#include +#endif + +static const char* host_os() +{ +#if PLATFORM_COSMO + if (IsLinux()) { return "linux"; } + else if (IsWindows()) { return "windows"; } + else if (IsXnu()) { return "macosx"; } + else if (IsBsd()) { return "bsd"; } + else + { + assert(0 && "Platform is unknown to Cosmopolitan Libc"); + return 0; + } +#else + return PLATFORM_OS; +#endif +} + int os_host(lua_State* L) { - lua_pushstring(L, PLATFORM_OS); + lua_pushstring(L, host_os()); return 1; } diff --git a/src/host/premake.c b/src/host/premake.c index 44f4761c9..f6fd47e8c 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -20,10 +20,6 @@ #include #endif -#if PLATFORM_COSMO -#include -#endif - #define ERROR_MESSAGE "Error: %s\n" @@ -177,24 +173,6 @@ void luaL_register(lua_State *L, const char *libname, const luaL_Reg *l) } -static const char* premake_host_os() -{ -#if PLATFORM_COSMO - if (IsLinux()) { return "linux"; } - else if (IsWindows()) { return "windows"; } - else if (IsXnu()) { return "macosx"; } - else if (IsBsd()) { return "bsd"; } - else - { - assert(0 && "Platform is unknown to Cosmopolitan Libc"); - return 0; - } -#else - return PLATFORM_OS; -#endif -} - - /** * Initialize the Premake Lua environment. */ diff --git a/tests/base/test_os.lua b/tests/base/test_os.lua index bfa424d3f..df59da31b 100644 --- a/tests/base/test_os.lua +++ b/tests/base/test_os.lua @@ -500,6 +500,20 @@ end +-- +-- os.host() tests. +-- + +function suite.host() + local host = os.host() + test.istrue(string.len(host) > 0) + + if _COSMOPOLITAN then + test.istrue(host ~= "cosmopolitan") + end +end + + -- -- os.hostarch() tests. -- From db2a83210726fed72fe4ef4168c3e3a22b61de65 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Thu, 3 Oct 2024 23:12:09 +0100 Subject: [PATCH 2/2] Move `_TARGET_OS` to Lua. --- src/_premake_main.lua | 5 ++++- src/host/premake.c | 8 -------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/_premake_main.lua b/src/_premake_main.lua index 3dcd33625..0be4153e1 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -8,9 +8,12 @@ local versionhelp = "premake5 (Premake Build Script Generator) %s" local startTime = os.clock() --- set a global. +-- set main globals. _PREMAKE_STARTTIME = startTime + -- default the target OS to the host OS + _TARGET_OS = os.host() + -- Load the collection of core scripts, required for everything else to work local modules = dofile("_modules.lua") diff --git a/src/host/premake.c b/src/host/premake.c index f6fd47e8c..042ac35d0 100644 --- a/src/host/premake.c +++ b/src/host/premake.c @@ -213,14 +213,6 @@ int premake_init(lua_State* L) lua_pushstring(L, PREMAKE_PROJECT_URL); lua_setglobal(L, "_PREMAKE_URL"); - /* set the target OS platform variable */ - lua_pushstring(L, premake_host_os()); - lua_setglobal(L, "_TARGET_OS"); - - /* set the target arch platform variable */ - lua_pushnil(L); - lua_setglobal(L, "_TARGET_ARCH"); - #if PLATFORM_COSMO /* set _COSMOPOLITAN if its a Cosmopolitan build */ lua_pushboolean(L, TRUE);