From f467d71abc40d4fee6e896d7a0b8e4f5be7e16db Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 17 Jul 2026 23:49:52 +0800 Subject: add batchcmds:call and transform for bin2obj/c --- xmake/rules/utils/bin2obj/utils.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'xmake/rules/utils/bin2obj/utils.lua') diff --git a/xmake/rules/utils/bin2obj/utils.lua b/xmake/rules/utils/bin2obj/utils.lua index 3e8802e97..c7da5f1a1 100644 --- a/xmake/rules/utils/bin2obj/utils.lua +++ b/xmake/rules/utils/bin2obj/utils.lua @@ -35,6 +35,7 @@ function generate_objectfile(target, batchcmds, binaryfile, opt) opt = opt or {} local rulename = opt.rulename or "utils.bin2obj" local progress = opt.progress + local fileconfig = target:fileconfig(binaryfile) -- check for cosmocc toolchain local is_cosmocc = target:toolchain("cosmocc") or (target:has_tool("cc", "cosmocc") and target:has_tool("ar", "cosmoar")) @@ -63,6 +64,16 @@ function generate_objectfile(target, batchcmds, binaryfile, opt) end table.insert(target:objectfiles(), objectfile) + -- transform binary data first + -- @see https://github.com/xmake-io/xmake/issues/7513 + local transform = opt.transform or (fileconfig and fileconfig.transform) or target:extraconf("rules", rulename, "transform") + if transform then + batchcmds:show_progress(progress, "${color.build.object}transforming.bin2obj %s", binaryfile) + local transformed_file = target:autogenfile(binaryfile .. ".transformed") + batchcmds:call(transform, {binaryfile, transformed_file}, {target = target}) + binaryfile = transformed_file + end + -- add commands if progress then batchcmds:show_progress(progress, "${color.build.object}generating.bin2obj %s", binaryfile) @@ -74,6 +85,9 @@ function generate_objectfile(target, batchcmds, binaryfile, opt) -- get zeroend (default: false, but can be overridden) local zeroend = opt.zeroend + if zeroend == nil then + zeroend = fileconfig and fileconfig.zeroend + end if zeroend == nil then zeroend = target:extraconf("rules", rulename, "zeroend") or false end -- cgit v1.3.1 From f9093aadcf44cadc7b3ab3c155de017d21bc5e47 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 18 Jul 2026 00:07:38 +0800 Subject: fix bin2obj symbols --- xmake/rules/utils/bin2c/utils.lua | 2 +- xmake/rules/utils/bin2obj/utils.lua | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'xmake/rules/utils/bin2obj/utils.lua') diff --git a/xmake/rules/utils/bin2c/utils.lua b/xmake/rules/utils/bin2c/utils.lua index b5bf7638b..8ea6ba17a 100644 --- a/xmake/rules/utils/bin2c/utils.lua +++ b/xmake/rules/utils/bin2c/utils.lua @@ -58,7 +58,7 @@ function generate_headerfile(target, batchcmds, binaryfile, opt) local transform = opt.transform or (fileconfig and fileconfig.transform) or target:extraconf("rules", rulename, "transform") if transform then batchcmds:show_progress(progress, "${color.build.object}transforming.bin2obj %s", binaryfile) - local transformed_file = target:autogenfile(binaryfile .. ".transformed") + local transformed_file = target:autogenfile(binaryfile) batchcmds:call(transform, {binaryfile, transformed_file}, {target = target}) binaryfile = transformed_file end diff --git a/xmake/rules/utils/bin2obj/utils.lua b/xmake/rules/utils/bin2obj/utils.lua index c7da5f1a1..7b98660d3 100644 --- a/xmake/rules/utils/bin2obj/utils.lua +++ b/xmake/rules/utils/bin2obj/utils.lua @@ -54,6 +54,16 @@ function generate_objectfile(target, batchcmds, binaryfile, opt) end end + -- transform binary data first + -- @see https://github.com/xmake-io/xmake/issues/7513 + local transform = opt.transform or (fileconfig and fileconfig.transform) or target:extraconf("rules", rulename, "transform") + if transform then + batchcmds:show_progress(progress, "${color.build.object}transforming.bin2obj %s", binaryfile) + local transformed_file = target:autogenfile(binaryfile) + batchcmds:call(transform, {binaryfile, transformed_file}, {target = target}) + binaryfile = transformed_file + end + -- get object file local objectfile = opt.objectfile if not objectfile then @@ -64,16 +74,6 @@ function generate_objectfile(target, batchcmds, binaryfile, opt) end table.insert(target:objectfiles(), objectfile) - -- transform binary data first - -- @see https://github.com/xmake-io/xmake/issues/7513 - local transform = opt.transform or (fileconfig and fileconfig.transform) or target:extraconf("rules", rulename, "transform") - if transform then - batchcmds:show_progress(progress, "${color.build.object}transforming.bin2obj %s", binaryfile) - local transformed_file = target:autogenfile(binaryfile .. ".transformed") - batchcmds:call(transform, {binaryfile, transformed_file}, {target = target}) - binaryfile = transformed_file - end - -- add commands if progress then batchcmds:show_progress(progress, "${color.build.object}generating.bin2obj %s", binaryfile) -- cgit v1.3.1 From 063bae8898d09f1f999a6fb2ad7a139777ebb7d7 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 18 Jul 2026 00:27:46 +0800 Subject: add batchcmds:call warnings --- xmake/plugins/project/utils/target_cmds.lua | 3 +++ xmake/rules/utils/bin2c/utils.lua | 2 +- xmake/rules/utils/bin2obj/utils.lua | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) (limited to 'xmake/rules/utils/bin2obj/utils.lua') diff --git a/xmake/plugins/project/utils/target_cmds.lua b/xmake/plugins/project/utils/target_cmds.lua index 7ea3a13a0..1c5fed7c8 100644 --- a/xmake/plugins/project/utils/target_cmds.lua +++ b/xmake/plugins/project/utils/target_cmds.lua @@ -87,6 +87,9 @@ function get_target_buildcmds(target, opt) cmd.program = os.programfile() cmd.argv = table.join("lua", cmd.script, cmd.argv) cmd.script = nil + elseif cmd.func and kind == "call" then + local name = cmd.opt and cmd.opt.name or "unknown" + wprint("%s: batchcmds:call() is not supported by the project generator and will be ignored!", name) end end return buildcmds:cmds() diff --git a/xmake/rules/utils/bin2c/utils.lua b/xmake/rules/utils/bin2c/utils.lua index 9765fb2f0..156752576 100644 --- a/xmake/rules/utils/bin2c/utils.lua +++ b/xmake/rules/utils/bin2c/utils.lua @@ -59,7 +59,7 @@ function generate_headerfile(target, batchcmds, binaryfile, opt) if transform then batchcmds:show_progress(progress, "${color.build.object}transforming.bin2c %s", binaryfile) local transformed_file = target:autogenfile(binaryfile) - batchcmds:call(transform, {binaryfile, transformed_file}, {target = target}) + batchcmds:call(transform, {binaryfile, transformed_file}, {name = "bin2c/transform", target = target}) binaryfile = transformed_file end diff --git a/xmake/rules/utils/bin2obj/utils.lua b/xmake/rules/utils/bin2obj/utils.lua index 7b98660d3..bcee334f0 100644 --- a/xmake/rules/utils/bin2obj/utils.lua +++ b/xmake/rules/utils/bin2obj/utils.lua @@ -60,7 +60,7 @@ function generate_objectfile(target, batchcmds, binaryfile, opt) if transform then batchcmds:show_progress(progress, "${color.build.object}transforming.bin2obj %s", binaryfile) local transformed_file = target:autogenfile(binaryfile) - batchcmds:call(transform, {binaryfile, transformed_file}, {target = target}) + batchcmds:call(transform, {binaryfile, transformed_file}, {name = "bin2obj/transform", target = target}) binaryfile = transformed_file end -- cgit v1.3.1