Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix os.host for Cosmopolitan build #2284

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/_premake_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
24 changes: 23 additions & 1 deletion src/host/os_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,30 @@

#include "premake.h"

#if PLATFORM_COSMO
#include <cosmo.h>
#include <assert.h>
#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;
}
30 changes: 0 additions & 30 deletions src/host/premake.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include <sys/sysctl.h>
#endif

#if PLATFORM_COSMO
#include <cosmo.h>
#endif

#define ERROR_MESSAGE "Error: %s\n"


Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -235,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);
Expand Down
14 changes: 14 additions & 0 deletions tests/base/test_os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
--
Expand Down