diff --git a/xmake/rules/c++/unity_build/unity_build.lua b/xmake/rules/c++/unity_build/unity_build.lua index a6059fec0d0..ffd222ad7e2 100644 --- a/xmake/rules/c++/unity_build/unity_build.lua +++ b/xmake/rules/c++/unity_build/unity_build.lua @@ -84,6 +84,8 @@ function main(target, sourcebatch) local uniqueid = extraconf and extraconf.uniqueid local id = 1 local count = 0 + local group_id = {} + local group_count = {} local unity_batch = {} local sourcefiles = {} local objectfiles = {} @@ -95,7 +97,20 @@ function main(target, sourcebatch) local dependfile = sourcebatch.dependfiles[idx] local fileconfig = target:fileconfig(sourcefile) if fileconfig and fileconfig.unity_group then - sourcefile_unity = path.join(sourcedir, "unity_group_" .. fileconfig.unity_group .. path.extension(sourcefile)) + if fileconfig.batchsize then + local curr_group_id = group_id[fileconfig.unity_group] or 1 + local curr_group_count = group_count[fileconfig.unity_group] or 0 + if curr_group_count >= fileconfig.batchsize then + curr_group_id = curr_group_id + 1 + curr_group_count = 0 + group_id[fileconfig.unity_group] = curr_group_id + group_count[fileconfig.unity_group] = curr_group_count + end + sourcefile_unity = path.join(sourcedir, "unity_group_" .. fileconfig.unity_group .. "_" .. tostring(curr_group_id) .. path.extension(sourcefile)) + group_count[fileconfig.unity_group] = curr_group_count + 1 + else + sourcefile_unity = path.join(sourcedir, "unity_group_" .. fileconfig.unity_group .. path.extension(sourcefile)) + end elseif (fileconfig and fileconfig.unity_ignored) or (batchsize and batchsize <= 1) then -- we do not add these files to unity file table.insert(sourcefiles, sourcefile)