diff options
| author | ruki <[email protected]> | 2025-12-15 13:41:50 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-15 13:41:50 +0800 |
| commit | fb06feeb88ecd2512a4a737d7e543b88892ad783 (patch) | |
| tree | 02dcca161c9389b28ef04d3b0af4967b4530377d | |
| parent | 777fdde191dc443aba4b987c07247446e10bb5d9 (diff) | |
| parent | 1243c8ca1a3edbbdc5d4669f6be199bd3f20e0e8 (diff) | |
Merge pull request #7125 from xmake-io/cosmocc
fix cosmocc ci
| -rw-r--r-- | .github/workflows/cosmocc.yml | 9 | ||||
| -rw-r--r-- | core/src/xmake/engine.c | 9 | ||||
| -rw-r--r-- | core/src/xmake/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/cli/binutils/bin2obj.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/utils/binary/bin2obj.lua | 29 | ||||
| -rw-r--r-- | xmake/rules/utils/bin2obj/utils.lua | 10 |
6 files changed, 48 insertions, 16 deletions
diff --git a/.github/workflows/cosmocc.yml b/.github/workflows/cosmocc.yml index 924a2210c..5f4479561 100644 --- a/.github/workflows/cosmocc.yml +++ b/.github/workflows/cosmocc.yml @@ -102,15 +102,9 @@ jobs: sudo apt install -y libgl1-mesa-dev libglu1-mesa-dev clang --version - - name: Prepare (macOS) - if: matrix.os == 'macos-13' - run: | - brew install dmd - brew install dub - # In the tests, cmake tries to use make from the cosmopolitan toolchain and fails, so uninstall it - name: Remove cosmocc - if: matrix.os == 'macos-13' + if: startsWith(matrix.os, 'macos') run: | INSTALL_DIR="${{runner.temp}}/cosmocc-4.0.2" echo "Removing cosmocc from PATH" @@ -120,6 +114,7 @@ jobs: - name: Tests run: | ls -l core/build/ + cmake --version core/build/xmake --version core/build/xmake lua -v -D tests/run.lua 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/modules/cli/binutils/bin2obj.lua b/xmake/modules/cli/binutils/bin2obj.lua index 6ee6c2158..06493143a 100644 --- a/xmake/modules/cli/binutils/bin2obj.lua +++ b/xmake/modules/cli/binutils/bin2obj.lua @@ -31,7 +31,8 @@ local options = { {'p', "plat", "kv", nil, "Set the target platform (macosx, iphoneos, etc.)."}, {nil, "target_minver", "kv", nil, "Set the target minimum version (e.g., 10.0, 18.2)."}, {nil, "xcode_sdkver", "kv", nil, "Set the Xcode SDK version (e.g., 10.0, 18.2)."}, - {nil, "zeroend", "k", nil, "Append a null terminator ('\\0') at the end of data."} + {nil, "zeroend", "k", nil, "Append a null terminator ('\\0') at the end of data."}, + {nil, "cosmocc", "k", nil, "Enable cosmocc support (generate concomitant object file)."} } function main(...) diff --git a/xmake/modules/utils/binary/bin2obj.lua b/xmake/modules/utils/binary/bin2obj.lua index 13ff633e1..e77cfad6f 100644 --- a/xmake/modules/utils/binary/bin2obj.lua +++ b/xmake/modules/utils/binary/bin2obj.lua @@ -49,6 +49,35 @@ function main(binarypath, outputpath, opt) -- do conversion binutils.bin2obj(binarypath, outputpath, opt) + -- generate concomitant object file for cosmocc + if opt.cosmocc then + local arch = opt.arch or "x86_64" + local arch_concomitant + local objectfile_concomitant + if arch == "x86_64" or arch == "x64" then + arch_concomitant = "aarch64" + objectfile_concomitant = path.join(path.directory(outputpath), ".aarch64", path.filename(outputpath)) + elseif arch == "aarch64" or arch == "arm64" then + arch_concomitant = "x86_64" + objectfile_concomitant = path.join(path.directory(outputpath), ".x86_64", path.filename(outputpath)) + end + + if arch_concomitant and objectfile_concomitant then + + -- clone options for concomitant + local opt_concomitant = table.clone(opt) + opt_concomitant.arch = arch_concomitant + opt_concomitant.cosmocc = false + + -- trace + print("converting binary file %s to %s object file %s ..", binarypath, format or "coff", objectfile_concomitant) + + -- do conversion + os.mkdir(path.directory(objectfile_concomitant)) + binutils.bin2obj(binarypath, objectfile_concomitant, opt_concomitant) + end + end + -- trace cprint("${bright}%s generated!", outputpath) end diff --git a/xmake/rules/utils/bin2obj/utils.lua b/xmake/rules/utils/bin2obj/utils.lua index 0e2bba9fd..3e8802e97 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" @@ -108,6 +113,9 @@ function generate_objectfile(target, batchcmds, binaryfile, opt) if zeroend then table.insert(argv, "--zeroend") end + if is_cosmocc then + table.insert(argv, "--cosmocc") + end batchcmds:vlua("cli.binutils.bin2obj", argv) return objectfile |
