diff options
| author | ruki <[email protected]> | 2026-03-23 06:41:15 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-23 06:41:15 +0800 |
| commit | 36b97ea5b101ded8d44a3e798e0c8b4748adf9a5 (patch) | |
| tree | fec3ea025e838a1a49e9fdcffaca2f73b8248169 | |
| parent | 84634aa837efe4275613d7826dc92f253cdf7cf5 (diff) | |
| parent | 484b73ea9ab074569edd8708f49868dbf61d0b03 (diff) | |
Merge pull request #7416 from xmake-io/cli
Improve xmake.cli, use bin2obj
| -rw-r--r-- | tests/projects/xmake_cli/hello/src/lni/main.c | 8 | ||||
| -rw-r--r-- | xmake/repository/templates/c++/xmake/cli/src/lni/main.cpp | 10 | ||||
| -rw-r--r-- | xmake/repository/templates/c/xmake/cli/src/lni/main.c | 8 | ||||
| -rw-r--r-- | xmake/rules/xmake_cli/xmake.lua | 15 |
4 files changed, 17 insertions, 24 deletions
diff --git a/tests/projects/xmake_cli/hello/src/lni/main.c b/tests/projects/xmake_cli/hello/src/lni/main.c index d61d60dac..740857750 100644 --- a/tests/projects/xmake_cli/hello/src/lni/main.c +++ b/tests/projects/xmake_cli/hello/src/lni/main.c @@ -1,8 +1,7 @@ #include <xmake/xmake.h> -static tb_byte_t const g_luafiles_data[] = { - #include "luafiles.xmz.h" -}; +extern tb_byte_t const _binary_luafiles_xmz_start[]; +extern tb_byte_t const _binary_luafiles_xmz_end[]; static tb_int_t lni_test_hello(lua_State* lua) { lua_pushliteral(lua, "hello xmake!"); @@ -15,7 +14,8 @@ static tb_void_t lni_initalizer(xm_engine_ref_t engine, lua_State* lua) { , {tb_null, tb_null} }; xm_engine_register(engine, "test", lni_test_funcs); - xm_engine_add_embedfiles(engine, g_luafiles_data, sizeof(g_luafiles_data)); + xm_engine_add_embedfiles(engine, _binary_luafiles_xmz_start, + (tb_size_t)(_binary_luafiles_xmz_end - _binary_luafiles_xmz_start)); } tb_int_t main(tb_int_t argc, tb_char_t** argv) { diff --git a/xmake/repository/templates/c++/xmake/cli/src/lni/main.cpp b/xmake/repository/templates/c++/xmake/cli/src/lni/main.cpp index 3de2b1e36..6dd5b81b1 100644 --- a/xmake/repository/templates/c++/xmake/cli/src/lni/main.cpp +++ b/xmake/repository/templates/c++/xmake/cli/src/lni/main.cpp @@ -1,10 +1,9 @@ extern "C" { #include <xmake/xmake.h> -} -static tb_byte_t const g_luafiles_data[] = { -#include "luafiles.xmz.h" -}; +extern tb_byte_t const _binary_luafiles_xmz_start[]; +extern tb_byte_t const _binary_luafiles_xmz_end[]; +} static tb_int_t lni_test_hello(lua_State *lua) { lua_pushliteral(lua, "hello xmake!"); @@ -14,7 +13,8 @@ static tb_int_t lni_test_hello(lua_State *lua) { static tb_void_t lni_initalizer(xm_engine_ref_t engine, lua_State *lua) { static luaL_Reg const lni_test_funcs[] = { { "hello", lni_test_hello }, { tb_null, tb_null } }; xm_engine_register(engine, "test", lni_test_funcs); - xm_engine_add_embedfiles(engine, g_luafiles_data, sizeof(g_luafiles_data)); + xm_engine_add_embedfiles(engine, _binary_luafiles_xmz_start, + (tb_size_t)(_binary_luafiles_xmz_end - _binary_luafiles_xmz_start)); } tb_int_t main(tb_int_t argc, tb_char_t **argv) { diff --git a/xmake/repository/templates/c/xmake/cli/src/lni/main.c b/xmake/repository/templates/c/xmake/cli/src/lni/main.c index 1ef27cd75..b1cef4e40 100644 --- a/xmake/repository/templates/c/xmake/cli/src/lni/main.c +++ b/xmake/repository/templates/c/xmake/cli/src/lni/main.c @@ -1,8 +1,7 @@ #include <xmake/xmake.h> -static tb_byte_t const g_luafiles_data[] = { -#include "luafiles.xmz.h" -}; +extern tb_byte_t const _binary_luafiles_xmz_start[]; +extern tb_byte_t const _binary_luafiles_xmz_end[]; static tb_int_t lni_test_hello(lua_State *lua) { lua_pushliteral(lua, "hello xmake!"); @@ -12,7 +11,8 @@ static tb_int_t lni_test_hello(lua_State *lua) { static tb_void_t lni_initalizer(xm_engine_ref_t engine, lua_State *lua) { static luaL_Reg const lni_test_funcs[] = { { "hello", lni_test_hello }, { tb_null, tb_null } }; xm_engine_register(engine, "test", lni_test_funcs); - xm_engine_add_embedfiles(engine, g_luafiles_data, sizeof(g_luafiles_data)); + xm_engine_add_embedfiles(engine, _binary_luafiles_xmz_start, + (tb_size_t)(_binary_luafiles_xmz_end - _binary_luafiles_xmz_start)); } tb_int_t main(tb_int_t argc, tb_char_t **argv) { diff --git a/xmake/rules/xmake_cli/xmake.lua b/xmake/rules/xmake_cli/xmake.lua index 7c543cb36..8106cfda1 100644 --- a/xmake/rules/xmake_cli/xmake.lua +++ b/xmake/rules/xmake_cli/xmake.lua @@ -24,16 +24,12 @@ rule("xmake.cli") on_load(function (target) target:set("kind", "binary") assert(target:pkg("libxmake"), 'please add_packages("libxmake") to target(%s) first!', target:name()) - - local headerdir = path.join(target:autogendir(), "rules", "xmake.cli", "include") - if not os.isdir(headerdir) then - os.mkdir(headerdir) - end - target:add("includedirs", headerdir) end) before_buildcmd_files(function (target, batchcmds, sourcebatch, opt) import("private.core.base.match_copyfiles") + import("rules.utils.bin2obj.utils", {alias = "bin2obj_utils", rootdir = os.programdir()}) + local sourcefiles = sourcebatch.sourcefiles local archivefile = path.join(target:autogendir(), "rules", "xmake.cli", "luafiles.xmz") local dependfile = archivefile .. ".d" @@ -51,11 +47,8 @@ rule("xmake.cli") end batchcmds:vrunv(os.programfile(), argv, {envs = {XMAKE_SKIP_HISTORY = "y"}}) - local headerdir = path.join(target:autogendir(), "rules", "xmake.cli", "include") - local headerfile = path.join(headerdir, "luafiles.xmz.h") - target:add("includedirs", headerdir) - argv = {"--nozeroend", "-i", path(archivefile), "-o", path(headerfile)} - batchcmds:vlua("utils.binary.bin2c", argv) + -- convert archive to object file via bin2obj + bin2obj_utils.generate_objectfile(target, batchcmds, archivefile) batchcmds:add_depfiles(sourcefiles) batchcmds:set_depmtime(os.mtime(dependfile)) |
