diff options
| author | ruki <[email protected]> | 2025-12-12 22:52:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-15 07:00:20 +0800 |
| commit | 7c64cdf5a76d86ce0884dec65ba5fd6dea5bb490 (patch) | |
| tree | f5b35c25f5eff3cbcbcd41d96ab7aad2a5a8f56e | |
| parent | 965ba548f68ed4bd4fe1090463b6e263fec82e36 (diff) | |
use bin2obj in embed mode
| -rw-r--r-- | core/src/xmake/engine.c | 9 | ||||
| -rw-r--r-- | core/src/xmake/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/rules/utils/bin2obj/utils.lua | 40 |
3 files changed, 45 insertions, 8 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index b7d071b65..530071a68 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -714,9 +714,8 @@ static lua_State *g_lua = tb_null; // the xmake script files data #ifdef XM_EMBED_ENABLE -static tb_byte_t g_xmake_xmz_data[] = { -#include "xmake.xmz.h" -}; +extern tb_byte_t _binary_xmake_xmz_start[]; +extern tb_byte_t _binary_xmake_xmz_end[]; #endif /* ////////////////////////////////////////////////////////////////////////////////////// @@ -1401,8 +1400,8 @@ static tb_bool_t xm_engine_extract_programfiles_impl(xm_engine_t *engine, static tb_bool_t xm_engine_extract_programfiles(xm_engine_t *engine, tb_char_t const *programdir) { tb_file_info_t info = { 0 }; if (!tb_file_info(programdir, &info)) { - tb_byte_t const *data = g_xmake_xmz_data; - tb_size_t size = sizeof(g_xmake_xmz_data); + tb_byte_t const *data = _binary_xmake_xmz_start; + tb_size_t size = _binary_xmake_xmz_end - _binary_xmake_xmz_start; if (!xm_engine_extract_programfiles_impl(engine, programdir, data, size)) { return tb_false; } diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua index 0883d071b..90f761b30 100644 --- a/core/src/xmake/xmake.lua +++ b/core/src/xmake/xmake.lua @@ -61,11 +61,11 @@ target("xmake") end -- embed all script files - add_rules("utils.bin2c", {linewidth = 16, extensions = ".xmz"}) + add_rules("utils.bin2obj", {extensions = ".xmz"}) on_config(function (target) import("utils.archive.archive") if has_config("embed") then - local archivefile = path.join(target:autogendir(), "bin2c", "xmake.xmz") + local archivefile = path.join(target:autogendir(), "bin2obj", "xmake.xmz") print("archiving %s ..", archivefile) os.tryrm(archivefile) local rootdir = path.normalize(path.join(os.projectdir(), "..", "xmake")) diff --git a/xmake/rules/utils/bin2obj/utils.lua b/xmake/rules/utils/bin2obj/utils.lua index 0e2bba9fd..e801d8e75 100644 --- a/xmake/rules/utils/bin2obj/utils.lua +++ b/xmake/rules/utils/bin2obj/utils.lua @@ -36,10 +36,15 @@ function generate_objectfile(target, batchcmds, binaryfile, opt) local rulename = opt.rulename or "utils.bin2obj" local progress = opt.progress + -- check for cosmocc toolchain + local is_cosmocc = target:toolchain("cosmocc") or (target:has_tool("cc", "cosmocc") and target:has_tool("ar", "cosmoar")) + -- get format (default: auto-detect from platform) local format = opt.format or target:extraconf("rules", rulename, "format") if not format then - if target:is_plat("windows", "mingw", "msys", "cygwin") then + if is_cosmocc then + format = "elf" + elseif target:is_plat("windows", "mingw", "msys", "cygwin") then format = "coff" elseif target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then format = "macho" @@ -77,6 +82,8 @@ function generate_objectfile(target, batchcmds, binaryfile, opt) local arch = target:arch() local plat = target:plat() + + -- get target_minver and xcode_sdkver from xcode toolchain (if available) local target_minver = nil local xcode_sdkver = nil @@ -110,6 +117,37 @@ function generate_objectfile(target, batchcmds, binaryfile, opt) end batchcmds:vlua("cli.binutils.bin2obj", argv) + -- generate concomitant object file for cosmocc + if is_cosmocc then + local arch_concomitant + local objectfile_concomitant + if arch == "x86_64" or arch == "x64" then + arch_concomitant = "aarch64" + objectfile_concomitant = path.join(path.directory(objectfile), ".aarch64", path.filename(objectfile)) + elseif arch == "aarch64" or arch == "arm64" then + arch_concomitant = "x86_64" + objectfile_concomitant = path.join(path.directory(objectfile), ".x86_64", path.filename(objectfile)) + end + + if arch_concomitant and objectfile_concomitant then + batchcmds:mkdir(path.directory(objectfile_concomitant)) + local argv_concomitant = { + "-i", path(binaryfile), + "-o", path(objectfile_concomitant), + "-f", format, + "-a", arch_concomitant, + "-p", plat + } + if symbol_prefix ~= "_binary_" then + table.insert(argv_concomitant, "--symbol_prefix=" .. symbol_prefix) + end + if zeroend then + table.insert(argv_concomitant, "--zeroend") + end + batchcmds:vlua("cli.binutils.bin2obj", argv_concomitant) + end + end + return objectfile end |
