diff options
| author | ruki <[email protected]> | 2024-04-03 00:57:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-04-03 00:57:04 +0800 |
| commit | efbf92709a0be6e2fba38efe3e10a2684d4e3836 (patch) | |
| tree | d135001bc3f1fbeb0887a05058b7aa7a45d5211d | |
| parent | 1cb62a5d466173ce4e8690eb320c44d5ddd6e1e2 (diff) | |
add xmake.arch
| -rw-r--r-- | core/src/xmake/engine.c | 49 | ||||
| -rw-r--r-- | xmake/core/_xmake_main.lua | 1 | ||||
| -rw-r--r-- | xmake/core/base/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/xmake.lua | 1 |
4 files changed, 36 insertions, 20 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index cbe1ed4fc..827d46d2e 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -933,11 +933,39 @@ static tb_void_t xm_engine_init_host(xm_engine_t* engine) lua_setglobal(engine->lua, "_SUBHOST"); } +static __tb_inline__ tb_char_t const* xm_engine_xmake_arch() +{ + tb_char_t const* arch = tb_null; +#if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) +# if defined(TB_ARCH_x64) + arch = "x64"; +# elif defined(TB_ARCH_ARM64) + arch = "arm64"; +# elif defined(TB_ARCH_ARM) + arch = "arm"; +# else + arch = "x86"; +# endif +#elif defined(TB_ARCH_x64) + arch = "x86_64"; +#elif defined(TB_ARCH_x86) + arch = "i386"; +#else + arch = TB_ARCH_STRING; +#endif + return arch; +} + static tb_void_t xm_engine_init_arch(xm_engine_t* engine) { // check tb_assert_and_check_return(engine && engine->lua); + // init xmake arch + tb_char_t const* xmakearch = xm_engine_xmake_arch(); + lua_pushstring(engine->lua, xmakearch); + lua_setglobal(engine->lua, "_XMAKE_ARCH"); + // init system architecture tb_char_t const* sysarch = tb_null; #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) @@ -972,27 +1000,8 @@ static tb_void_t xm_engine_init_arch(xm_engine_t* engine) default: break; } - - // get arch from compiler - if (!sysarch) - { -# if defined(TB_ARCH_x64) - sysarch = "x64"; -# elif defined(TB_ARCH_ARM64) - sysarch = "arm64"; -# elif defined(TB_ARCH_ARM) - sysarch = "arm"; -# else - sysarch = "x86"; -# endif - } -#elif defined(TB_ARCH_x64) - sysarch = "x86_64"; -#elif defined(TB_ARCH_x86) - sysarch = "i386"; -#else - sysarch = TB_ARCH_STRING; #endif + if (!sysarch) sysarch = xmakearch; lua_pushstring(engine->lua, sysarch); lua_setglobal(engine->lua, "_ARCH"); diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua index 6dba86db5..38f7df73d 100644 --- a/xmake/core/_xmake_main.lua +++ b/xmake/core/_xmake_main.lua @@ -26,6 +26,7 @@ xmake._HOST = _HOST xmake._ARCH = _ARCH xmake._SUBHOST = _SUBHOST xmake._SUBARCH = _SUBARCH +xmake._XMAKE_ARCH = _XMAKE_ARCH xmake._VERSION = _VERSION xmake._VERSION_SHORT = _VERSION_SHORT xmake._PROGRAM_DIR = _PROGRAM_DIR diff --git a/xmake/core/base/xmake.lua b/xmake/core/base/xmake.lua index e892a5a04..dad96dc06 100644 --- a/xmake/core/base/xmake.lua +++ b/xmake/core/base/xmake.lua @@ -37,6 +37,11 @@ function xmake.version() return xmake._VERSION_CACHE or nil end +-- get the xmake binary architecture +function xmake.arch() + return xmake._XMAKE_ARCH +end + -- get the git branch of xmake version, e.g. build: {"dev", "d4cff6e11"} function xmake.branch() return xmake.version():build()[1] diff --git a/xmake/core/sandbox/modules/xmake.lua b/xmake/core/sandbox/modules/xmake.lua index d4e23984a..f4f36d23c 100644 --- a/xmake/core/sandbox/modules/xmake.lua +++ b/xmake/core/sandbox/modules/xmake.lua @@ -25,6 +25,7 @@ local xmake = require("base/xmake") local sandbox_xmake = sandbox_xmake or {} -- inherit some builtin interfaces +sandbox_xmake.arch = xmake.arch sandbox_xmake.version = xmake.version sandbox_xmake.branch = xmake.branch sandbox_xmake.programdir = xmake.programdir |
