From 344d2874f06cce073bb0316fe75f505d2767fbc4 Mon Sep 17 00:00:00 2001 From: Christian Rendina Date: Tue, 8 Apr 2025 15:28:56 +0200 Subject: Add some midl tests --- tests/projects/idl/test_norpc/src/lockowner.idl | 28 ++++++++++++++++++++++ tests/projects/idl/test_norpc/src/test_iid.c | 9 +++++++ tests/projects/idl/test_norpc/xmake.lua | 7 ++++++ .../idl/test_norpc_proxy/src/lockowner.idl | 28 ++++++++++++++++++++++ tests/projects/idl/test_norpc_proxy/src/test_iid.c | 9 +++++++ tests/projects/idl/test_norpc_proxy/xmake.lua | 7 ++++++ tests/projects/idl/test_rpc/src/example.idl | 13 ++++++++++ tests/projects/idl/test_rpc/src/test_iid.c | 21 ++++++++++++++++ tests/projects/idl/test_rpc/xmake.lua | 7 ++++++ .../projects/idl/test_rpc_noserver/src/example.idl | 13 ++++++++++ .../projects/idl/test_rpc_noserver/src/test_iid.c | 20 ++++++++++++++++ tests/projects/idl/test_rpc_noserver/xmake.lua | 8 +++++++ 12 files changed, 170 insertions(+) create mode 100644 tests/projects/idl/test_norpc/src/lockowner.idl create mode 100644 tests/projects/idl/test_norpc/src/test_iid.c create mode 100644 tests/projects/idl/test_norpc/xmake.lua create mode 100644 tests/projects/idl/test_norpc_proxy/src/lockowner.idl create mode 100644 tests/projects/idl/test_norpc_proxy/src/test_iid.c create mode 100644 tests/projects/idl/test_norpc_proxy/xmake.lua create mode 100644 tests/projects/idl/test_rpc/src/example.idl create mode 100644 tests/projects/idl/test_rpc/src/test_iid.c create mode 100644 tests/projects/idl/test_rpc/xmake.lua create mode 100644 tests/projects/idl/test_rpc_noserver/src/example.idl create mode 100644 tests/projects/idl/test_rpc_noserver/src/test_iid.c create mode 100644 tests/projects/idl/test_rpc_noserver/xmake.lua diff --git a/tests/projects/idl/test_norpc/src/lockowner.idl b/tests/projects/idl/test_norpc/src/lockowner.idl new file mode 100644 index 000000000..a63fe01bc --- /dev/null +++ b/tests/projects/idl/test_norpc/src/lockowner.idl @@ -0,0 +1,28 @@ +/* + * PROJECT: SupernovaX SDK + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Lock owner COM interfaces + * COPYRIGHT: Copyright 2023 Christian Rendina + */ +import "oaidl.idl"; +import "ocidl.idl"; + +[ + object, + local, + uuid(9b7e4a00-342c-4106-a19f-4f2704f689f0) +] +interface ILockOwner : IUnknown +{ + void LOEnter( + void + ); + + void LOLeave( + void + ); + + BOOL LOTryEnter( + void + ); +}; diff --git a/tests/projects/idl/test_norpc/src/test_iid.c b/tests/projects/idl/test_norpc/src/test_iid.c new file mode 100644 index 000000000..39a279072 --- /dev/null +++ b/tests/projects/idl/test_norpc/src/test_iid.c @@ -0,0 +1,9 @@ +#include +#include + +int main() +{ + IID g = IID_ILockOwner; + printf("GUID: %x-%x-%x-%llx", g.Data1, g.Data2, g.Data3, *(unsigned long long*)g.Data4); + return 0; +} diff --git a/tests/projects/idl/test_norpc/xmake.lua b/tests/projects/idl/test_norpc/xmake.lua new file mode 100644 index 000000000..d1596e3d5 --- /dev/null +++ b/tests/projects/idl/test_norpc/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") + +target("idltest_norpc") + set_kind("binary") + add_files("src/*.idl", { proxy = false }) + add_files("src/*.c") + add_syslinks("Rpcrt4") diff --git a/tests/projects/idl/test_norpc_proxy/src/lockowner.idl b/tests/projects/idl/test_norpc_proxy/src/lockowner.idl new file mode 100644 index 000000000..a63fe01bc --- /dev/null +++ b/tests/projects/idl/test_norpc_proxy/src/lockowner.idl @@ -0,0 +1,28 @@ +/* + * PROJECT: SupernovaX SDK + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Lock owner COM interfaces + * COPYRIGHT: Copyright 2023 Christian Rendina + */ +import "oaidl.idl"; +import "ocidl.idl"; + +[ + object, + local, + uuid(9b7e4a00-342c-4106-a19f-4f2704f689f0) +] +interface ILockOwner : IUnknown +{ + void LOEnter( + void + ); + + void LOLeave( + void + ); + + BOOL LOTryEnter( + void + ); +}; diff --git a/tests/projects/idl/test_norpc_proxy/src/test_iid.c b/tests/projects/idl/test_norpc_proxy/src/test_iid.c new file mode 100644 index 000000000..39a279072 --- /dev/null +++ b/tests/projects/idl/test_norpc_proxy/src/test_iid.c @@ -0,0 +1,9 @@ +#include +#include + +int main() +{ + IID g = IID_ILockOwner; + printf("GUID: %x-%x-%x-%llx", g.Data1, g.Data2, g.Data3, *(unsigned long long*)g.Data4); + return 0; +} diff --git a/tests/projects/idl/test_norpc_proxy/xmake.lua b/tests/projects/idl/test_norpc_proxy/xmake.lua new file mode 100644 index 000000000..f4255cea5 --- /dev/null +++ b/tests/projects/idl/test_norpc_proxy/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") + +target("idltest_norpc") + set_kind("binary") + add_files("src/*.idl") + add_files("src/*.c") + add_syslinks("Rpcrt4") diff --git a/tests/projects/idl/test_rpc/src/example.idl b/tests/projects/idl/test_rpc/src/example.idl new file mode 100644 index 000000000..655b7827a --- /dev/null +++ b/tests/projects/idl/test_rpc/src/example.idl @@ -0,0 +1,13 @@ +[ + uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45), + version(1.0) +] +interface MyInterface +{ + const unsigned short INT_ARRAY_LEN = 100; + + void MyRemoteProc( + [in] int param1, + [out] int outArray[INT_ARRAY_LEN] + ); +} diff --git a/tests/projects/idl/test_rpc/src/test_iid.c b/tests/projects/idl/test_rpc/src/test_iid.c new file mode 100644 index 000000000..c7e0f600b --- /dev/null +++ b/tests/projects/idl/test_rpc/src/test_iid.c @@ -0,0 +1,21 @@ +#include +#include +#include + +int main() +{ + MyInterface_v1_0_c_ifspec = (void*)1; + MyInterface_v1_0_s_ifspec = (void*)1; + printf("set ok\n"); + return 0; +} + +void __RPC_FAR * __RPC_API midl_user_allocate(size_t cBytes) +{ + return(malloc(cBytes)); +} + +void __RPC_API midl_user_free(void __RPC_FAR * p) +{ + free(p); +} diff --git a/tests/projects/idl/test_rpc/xmake.lua b/tests/projects/idl/test_rpc/xmake.lua new file mode 100644 index 000000000..3eba457d6 --- /dev/null +++ b/tests/projects/idl/test_rpc/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") + +target("idltest_rpc") + set_kind("binary") + add_files("src/*.idl" ) + add_files("src/*.c") + add_syslinks("Rpcrt4") diff --git a/tests/projects/idl/test_rpc_noserver/src/example.idl b/tests/projects/idl/test_rpc_noserver/src/example.idl new file mode 100644 index 000000000..655b7827a --- /dev/null +++ b/tests/projects/idl/test_rpc_noserver/src/example.idl @@ -0,0 +1,13 @@ +[ + uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45), + version(1.0) +] +interface MyInterface +{ + const unsigned short INT_ARRAY_LEN = 100; + + void MyRemoteProc( + [in] int param1, + [out] int outArray[INT_ARRAY_LEN] + ); +} diff --git a/tests/projects/idl/test_rpc_noserver/src/test_iid.c b/tests/projects/idl/test_rpc_noserver/src/test_iid.c new file mode 100644 index 000000000..fd992323b --- /dev/null +++ b/tests/projects/idl/test_rpc_noserver/src/test_iid.c @@ -0,0 +1,20 @@ +#include +#include +#include + +int main() +{ + MyInterface_v1_0_c_ifspec = (void*)1; + printf("call ok\n"); + return 0; +} + +void __RPC_FAR * __RPC_API midl_user_allocate(size_t cBytes) +{ + return(malloc(cBytes)); +} + +void __RPC_API midl_user_free(void __RPC_FAR * p) +{ + free(p); +} diff --git a/tests/projects/idl/test_rpc_noserver/xmake.lua b/tests/projects/idl/test_rpc_noserver/xmake.lua new file mode 100644 index 000000000..6c4bcdd2b --- /dev/null +++ b/tests/projects/idl/test_rpc_noserver/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.debug", "mode.release") + +target("idltest_rpc_noserver") + set_kind("binary") + --add_rules("midl") + add_files("src/*.idl", { server = false } ) + add_files("src/*.c") + add_syslinks("Rpcrt4") -- cgit v1.3.1 From cb97438a6ea9a5e67dca949a979d08e951b14f3d Mon Sep 17 00:00:00 2001 From: Christian Rendina Date: Tue, 8 Apr 2025 15:29:14 +0200 Subject: Improve midl support --- xmake/rules/platform/windows/idl/xmake.lua | 152 +++++++++++++++++++++++++++-- 1 file changed, 142 insertions(+), 10 deletions(-) diff --git a/xmake/rules/platform/windows/idl/xmake.lua b/xmake/rules/platform/windows/idl/xmake.lua index 0381658ec..f95846c32 100644 --- a/xmake/rules/platform/windows/idl/xmake.lua +++ b/xmake/rules/platform/windows/idl/xmake.lua @@ -30,6 +30,34 @@ rule("platform.windows.idl") before_buildcmd_file(function (target, batchcmds, sourcefile, opt) import("lib.detect.find_tool") + import("core.project.depend") + import("utils.progress") -- it only for v2.5.9, we need use print to show prog + + local fileconfig = target:fileconfig(sourcefile) + local enable_server = true + local enable_client = true + + local defs = table.wrap(target:get("defines") or {}) + local incs = table.wrap(target:get("includedirs") or {}) + local undefs = table.wrap(target:get("undefines") or {}) + + if fileconfig then + if fileconfig.server ~= nil then + enable_server = fileconfig.server + end + if fileconfig.client ~= nil then + enable_client = fileconfig.client + end + if fileconfig.includedirs ~= nil then + table.join2(incs, fileconfig.includedirs) + end + if fileconfig.defines ~= nil then + table.join2(defs, fileconfig.defines) + end + if fileconfig.undefines ~= nil then + table.join2(undefs, fileconfig.undefines) + end + end local msvc = target:toolchain("msvc") or target:toolchain("clang-cl") or target:toolchain("clang") local midl = assert(find_tool("midl", {envs = msvc:runenvs(), toolchain = msvc}), "midl not found!") @@ -39,26 +67,130 @@ rule("platform.windows.idl") local flags = {"/nologo"} table.join2(flags, table.wrap(target:values("idl.flags"))) + + -- specify warn levels + local warns = target:get("warnings") + if warns == "none" then + table.insert(flags, "/W0") + table.insert(flags, "/no_warn") + elseif warns == "less" then + table.insert(flags, "/W1") + elseif warns == "more" then + table.insert(flags, "/W2") + elseif warns == "extra" then + table.insert(flags, "/W3") + elseif warns == "error" then + table.insert(flags, "/WX") + table.insert(flags, "/W4") + end + + -- add include dirs, defines and undefines from compiler flags + for _, inc in ipairs(incs) do + table.insert(flags, "/I") + table.insert(flags, path.absolute(inc)) + end + + for _, def in ipairs(defs) do + table.insert(flags, "/D") + table.insert(flags, def) + end + + for _, undef in ipairs(undefs) do + table.insert(flags, "/U") + table.insert(flags, undef) + end + table.join2(flags, { "/out", path(autogendir), "/header", name .. ".h", "/iid", name .. "_i.c", "/proxy", name .. "_p.c", "/tlb", name .. ".tlb", + "/cstub", name .. "_c.c", + "/sstub", name .. "_s.c", + "/server", (enable_server and "stub" or "none"), + "/client", (enable_client and "stub" or "none"), path(sourcefile) }) - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.idl %s", sourcefile) - batchcmds:vrunv(midl.program, flags, {envs = msvc:runenvs()}) + -- use this way to set depend to avoid generating files multiple times + depend.on_changed(function() + progress.show(opt.progress, "${color.build.object}generating.idl %s", sourcefile) + os.vrunv(midl.program, flags, { envs = msvc:runenvs() }) + end, { files = sourcefile, dependfile = path.join(autogendir, path.basename(sourcefile) .. ".idl.d") }) - local iid_file = path.join(autogendir, name .. "_i.c") - local objectfile = target:objectfile(iid_file) - table.insert(target:objectfiles(), objectfile) + --batchcmds:show_progress(opt.progress, "${color.build.object}compiling.idl %s", sourcefile) + --batchcmds:vrunv(midl.program, flags, {envs = msvc:runenvs()}) + + end) + --[[ + we don't have a way to detect which files midl.exe has generated and os.exists + does not work in before_buildcmd_file because in the invokation of xmake + the files might not have been generated yet from batchcmds, therefore + the files are compiled and checked during the buildcmd as _i, _p, _c, _s + might not exists depending on the idl file + ]] + on_buildcmd_file(function (target, batchcmds, sourcefile, opt) + import("core.project.depend") + + local name = path.basename(sourcefile) + local autogendir = path.join(target:autogendir(), "platform/windows/idl") + + -- we don't have a way to detect which midl files are generated + + local icfile = path.join(autogendir, name .. "_i.c") + local icobj = target:objectfile(icfile) + + local scfile = path.join(autogendir, name .. "_s.c") + local scobj = target:objectfile(scfile) + + local ccfile = path.join(autogendir, name .. "_c.c") + local ccobj = target:objectfile(ccfile) + + local pcfile = path.join(autogendir, name .. "_p.c") + local pcobj = target:objectfile(pcfile) + + local fileconfig = target:fileconfig(sourcefile) + local enable_proxy = true + if fileconfig then + if fileconfig.proxy ~= nil then + enable_proxy = fileconfig.proxy + end + end + + -- compile c files + local configs = {includedirs = autogendir, languages = "c89"} + + if os.exists(icfile) then + table.insert(target:objectfiles(), icobj) + depend.on_changed(function() + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", icfile) + batchcmds:compile(icfile, icobj, {sourcekind = "cxx", configs = configs}) + end, { files = {icobj}, changed = target:is_rebuilt() }) + end + + if os.exists(scfile) then + table.insert(target:objectfiles(), scobj) + depend.on_changed(function() + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", scfile) + batchcmds:compile(scfile, scobj, {sourcekind = "cxx", configs = configs}) + end, { files = {scobj}, changed = target:is_rebuilt() }) + end + - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", iid_file) - batchcmds:compile(iid_file, objectfile) + if os.exists(pcfile) and enable_proxy then + table.insert(target:objectfiles(), pcobj) + depend.on_changed(function() + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", pcfile) + batchcmds:compile(pcfile, pcobj, {sourcekind = "cxx", configs = configs}) + end, { files = {pcobj}, changed = target:is_rebuilt() }) + end - batchcmds:add_depfiles(sourcefile, iid_file) - batchcmds:set_depmtime(os.mtime(objectfile)) - batchcmds:set_depcache(target:dependfile(objectfile)) + if os.exists(ccfile) then + table.insert(target:objectfiles(), ccobj) + depend.on_changed(function() + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", ccfile) + batchcmds:compile(ccfile, ccobj, {sourcekind = "cxx", configs = configs}) + end, { files = {ccobj}, changed = target:is_rebuilt() }) + end end) -- cgit v1.3.1 From 2051c13f735a626f7b6fd8b98aa69f01fd9cef7e Mon Sep 17 00:00:00 2001 From: Christian Rendina Date: Tue, 8 Apr 2025 17:12:27 +0200 Subject: Address reviews --- tests/projects/idl/test_norpc/src/lockowner.idl | 24 +++++----- .../idl/test_norpc_proxy/src/lockowner.idl | 24 +++++----- tests/projects/idl/test_rpc/src/example.idl | 14 +++--- .../projects/idl/test_rpc_noserver/src/example.idl | 14 +++--- tests/projects/idl/test_rpc_noserver/xmake.lua | 1 - xmake/rules/platform/windows/idl/xmake.lua | 54 +++++++++++----------- 6 files changed, 65 insertions(+), 66 deletions(-) diff --git a/tests/projects/idl/test_norpc/src/lockowner.idl b/tests/projects/idl/test_norpc/src/lockowner.idl index a63fe01bc..49d314ca2 100644 --- a/tests/projects/idl/test_norpc/src/lockowner.idl +++ b/tests/projects/idl/test_norpc/src/lockowner.idl @@ -8,21 +8,21 @@ import "oaidl.idl"; import "ocidl.idl"; [ - object, - local, - uuid(9b7e4a00-342c-4106-a19f-4f2704f689f0) + object, + local, + uuid(9b7e4a00-342c-4106-a19f-4f2704f689f0) ] interface ILockOwner : IUnknown { - void LOEnter( - void - ); + void LOEnter( + void + ); - void LOLeave( - void - ); + void LOLeave( + void + ); - BOOL LOTryEnter( - void - ); + BOOL LOTryEnter( + void + ); }; diff --git a/tests/projects/idl/test_norpc_proxy/src/lockowner.idl b/tests/projects/idl/test_norpc_proxy/src/lockowner.idl index a63fe01bc..49d314ca2 100644 --- a/tests/projects/idl/test_norpc_proxy/src/lockowner.idl +++ b/tests/projects/idl/test_norpc_proxy/src/lockowner.idl @@ -8,21 +8,21 @@ import "oaidl.idl"; import "ocidl.idl"; [ - object, - local, - uuid(9b7e4a00-342c-4106-a19f-4f2704f689f0) + object, + local, + uuid(9b7e4a00-342c-4106-a19f-4f2704f689f0) ] interface ILockOwner : IUnknown { - void LOEnter( - void - ); + void LOEnter( + void + ); - void LOLeave( - void - ); + void LOLeave( + void + ); - BOOL LOTryEnter( - void - ); + BOOL LOTryEnter( + void + ); }; diff --git a/tests/projects/idl/test_rpc/src/example.idl b/tests/projects/idl/test_rpc/src/example.idl index 655b7827a..1eb750a97 100644 --- a/tests/projects/idl/test_rpc/src/example.idl +++ b/tests/projects/idl/test_rpc/src/example.idl @@ -1,13 +1,13 @@ [ - uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45), - version(1.0) + uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45), + version(1.0) ] interface MyInterface { - const unsigned short INT_ARRAY_LEN = 100; + const unsigned short INT_ARRAY_LEN = 100; - void MyRemoteProc( - [in] int param1, - [out] int outArray[INT_ARRAY_LEN] - ); + void MyRemoteProc( + [in] int param1, + [out] int outArray[INT_ARRAY_LEN] + ); } diff --git a/tests/projects/idl/test_rpc_noserver/src/example.idl b/tests/projects/idl/test_rpc_noserver/src/example.idl index 655b7827a..1eb750a97 100644 --- a/tests/projects/idl/test_rpc_noserver/src/example.idl +++ b/tests/projects/idl/test_rpc_noserver/src/example.idl @@ -1,13 +1,13 @@ [ - uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45), - version(1.0) + uuid(ba209999-0c6c-11d2-97cf-00c04f8eea45), + version(1.0) ] interface MyInterface { - const unsigned short INT_ARRAY_LEN = 100; + const unsigned short INT_ARRAY_LEN = 100; - void MyRemoteProc( - [in] int param1, - [out] int outArray[INT_ARRAY_LEN] - ); + void MyRemoteProc( + [in] int param1, + [out] int outArray[INT_ARRAY_LEN] + ); } diff --git a/tests/projects/idl/test_rpc_noserver/xmake.lua b/tests/projects/idl/test_rpc_noserver/xmake.lua index 6c4bcdd2b..c44a6433b 100644 --- a/tests/projects/idl/test_rpc_noserver/xmake.lua +++ b/tests/projects/idl/test_rpc_noserver/xmake.lua @@ -2,7 +2,6 @@ add_rules("mode.debug", "mode.release") target("idltest_rpc_noserver") set_kind("binary") - --add_rules("midl") add_files("src/*.idl", { server = false } ) add_files("src/*.c") add_syslinks("Rpcrt4") diff --git a/xmake/rules/platform/windows/idl/xmake.lua b/xmake/rules/platform/windows/idl/xmake.lua index f95846c32..75c47f7e9 100644 --- a/xmake/rules/platform/windows/idl/xmake.lua +++ b/xmake/rules/platform/windows/idl/xmake.lua @@ -42,19 +42,19 @@ rule("platform.windows.idl") local undefs = table.wrap(target:get("undefines") or {}) if fileconfig then - if fileconfig.server ~= nil then + if fileconfig.server then enable_server = fileconfig.server end - if fileconfig.client ~= nil then + if fileconfig.client then enable_client = fileconfig.client end - if fileconfig.includedirs ~= nil then + if fileconfig.includedirs then table.join2(incs, fileconfig.includedirs) end - if fileconfig.defines ~= nil then + if fileconfig.defines then table.join2(defs, fileconfig.defines) end - if fileconfig.undefines ~= nil then + if fileconfig.undefines then table.join2(undefs, fileconfig.undefines) end end @@ -118,11 +118,8 @@ rule("platform.windows.idl") progress.show(opt.progress, "${color.build.object}generating.idl %s", sourcefile) os.vrunv(midl.program, flags, { envs = msvc:runenvs() }) end, { files = sourcefile, dependfile = path.join(autogendir, path.basename(sourcefile) .. ".idl.d") }) - - --batchcmds:show_progress(opt.progress, "${color.build.object}compiling.idl %s", sourcefile) - --batchcmds:vrunv(midl.program, flags, {envs = msvc:runenvs()}) - end) + --[[ we don't have a way to detect which files midl.exe has generated and os.exists does not work in before_buildcmd_file because in the invokation of xmake @@ -160,37 +157,40 @@ rule("platform.windows.idl") -- compile c files local configs = {includedirs = autogendir, languages = "c89"} - + if os.exists(icfile) then table.insert(target:objectfiles(), icobj) - depend.on_changed(function() - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", icfile) - batchcmds:compile(icfile, icobj, {sourcekind = "cxx", configs = configs}) - end, { files = {icobj}, changed = target:is_rebuilt() }) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", icfile) + batchcmds:compile(icfile, icobj, {sourcekind = "cxx", configs = configs}) + batchcmds:add_depfiles(icfile) + batchcmds:set_depmtime(os.mtime(icobj)) + batchcmds:set_depcache(target:dependfile(icobj)) end if os.exists(scfile) then table.insert(target:objectfiles(), scobj) - depend.on_changed(function() - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", scfile) - batchcmds:compile(scfile, scobj, {sourcekind = "cxx", configs = configs}) - end, { files = {scobj}, changed = target:is_rebuilt() }) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", scfile) + batchcmds:compile(scfile, scobj, {sourcekind = "cxx", configs = configs}) + batchcmds:add_depfiles(scfile) + batchcmds:set_depmtime(os.mtime(scobj)) + batchcmds:set_depcache(target:dependfile(scobj)) end - if os.exists(pcfile) and enable_proxy then table.insert(target:objectfiles(), pcobj) - depend.on_changed(function() - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", pcfile) - batchcmds:compile(pcfile, pcobj, {sourcekind = "cxx", configs = configs}) - end, { files = {pcobj}, changed = target:is_rebuilt() }) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", pcfile) + batchcmds:compile(pcfile, pcobj, {sourcekind = "cxx", configs = configs}) + batchcmds:add_depfiles(pcfile) + batchcmds:set_depmtime(os.mtime(pcobj)) + batchcmds:set_depcache(target:dependfile(pcobj)) end if os.exists(ccfile) then table.insert(target:objectfiles(), ccobj) - depend.on_changed(function() - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", ccfile) - batchcmds:compile(ccfile, ccobj, {sourcekind = "cxx", configs = configs}) - end, { files = {ccobj}, changed = target:is_rebuilt() }) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", ccfile) + batchcmds:compile(ccfile, ccobj, {sourcekind = "cxx", configs = configs}) + batchcmds:add_depfiles(ccfile) + batchcmds:set_depmtime(os.mtime(ccobj)) + batchcmds:set_depcache(target:dependfile(ccobj)) end end) -- cgit v1.3.1 From e865a0206e1c57e0f34c473b4616304f6b44d377 Mon Sep 17 00:00:00 2001 From: Christian Rendina Date: Fri, 11 Apr 2025 18:11:42 +0200 Subject: Format files --- tests/projects/idl/test_norpc/src/test_iid.c | 3 +-- tests/projects/idl/test_norpc_proxy/src/test_iid.c | 3 +-- tests/projects/idl/test_rpc/src/test_iid.c | 9 +++------ tests/projects/idl/test_rpc_noserver/src/test_iid.c | 9 +++------ xmake/rules/platform/windows/idl/xmake.lua | 2 +- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/tests/projects/idl/test_norpc/src/test_iid.c b/tests/projects/idl/test_norpc/src/test_iid.c index 39a279072..b581c32fb 100644 --- a/tests/projects/idl/test_norpc/src/test_iid.c +++ b/tests/projects/idl/test_norpc/src/test_iid.c @@ -1,8 +1,7 @@ #include #include -int main() -{ +int main() { IID g = IID_ILockOwner; printf("GUID: %x-%x-%x-%llx", g.Data1, g.Data2, g.Data3, *(unsigned long long*)g.Data4); return 0; diff --git a/tests/projects/idl/test_norpc_proxy/src/test_iid.c b/tests/projects/idl/test_norpc_proxy/src/test_iid.c index 39a279072..b581c32fb 100644 --- a/tests/projects/idl/test_norpc_proxy/src/test_iid.c +++ b/tests/projects/idl/test_norpc_proxy/src/test_iid.c @@ -1,8 +1,7 @@ #include #include -int main() -{ +int main() { IID g = IID_ILockOwner; printf("GUID: %x-%x-%x-%llx", g.Data1, g.Data2, g.Data3, *(unsigned long long*)g.Data4); return 0; diff --git a/tests/projects/idl/test_rpc/src/test_iid.c b/tests/projects/idl/test_rpc/src/test_iid.c index c7e0f600b..b835c9fde 100644 --- a/tests/projects/idl/test_rpc/src/test_iid.c +++ b/tests/projects/idl/test_rpc/src/test_iid.c @@ -2,20 +2,17 @@ #include #include -int main() -{ +int main() { MyInterface_v1_0_c_ifspec = (void*)1; MyInterface_v1_0_s_ifspec = (void*)1; printf("set ok\n"); return 0; } -void __RPC_FAR * __RPC_API midl_user_allocate(size_t cBytes) -{ +void __RPC_FAR * __RPC_API midl_user_allocate(size_t cBytes) { return(malloc(cBytes)); } -void __RPC_API midl_user_free(void __RPC_FAR * p) -{ +void __RPC_API midl_user_free(void __RPC_FAR * p) { free(p); } diff --git a/tests/projects/idl/test_rpc_noserver/src/test_iid.c b/tests/projects/idl/test_rpc_noserver/src/test_iid.c index fd992323b..8edfb7807 100644 --- a/tests/projects/idl/test_rpc_noserver/src/test_iid.c +++ b/tests/projects/idl/test_rpc_noserver/src/test_iid.c @@ -2,19 +2,16 @@ #include #include -int main() -{ +int main() { MyInterface_v1_0_c_ifspec = (void*)1; printf("call ok\n"); return 0; } -void __RPC_FAR * __RPC_API midl_user_allocate(size_t cBytes) -{ +void __RPC_FAR * __RPC_API midl_user_allocate(size_t cBytes) { return(malloc(cBytes)); } -void __RPC_API midl_user_free(void __RPC_FAR * p) -{ +void __RPC_API midl_user_free(void __RPC_FAR * p) { free(p); } diff --git a/xmake/rules/platform/windows/idl/xmake.lua b/xmake/rules/platform/windows/idl/xmake.lua index 8cffe18df..e34acc4a0 100644 --- a/xmake/rules/platform/windows/idl/xmake.lua +++ b/xmake/rules/platform/windows/idl/xmake.lua @@ -90,7 +90,7 @@ rule("platform.windows.idl") -- add include dirs, defines and undefines from compiler flags for _, inc in ipairs(incs) do table.insert(flags, "/I") - table.insert(flags, path.absolute(inc)) + table.insert(flags, path(inc)) end for _, def in ipairs(defs) do -- cgit v1.3.1 From 228a13777b5c0c5e8c0c09f1eefa73add81c269e Mon Sep 17 00:00:00 2001 From: Christian Rendina Date: Tue, 15 Apr 2025 11:41:58 +0200 Subject: Use jobgraph rather than batchcmds --- xmake/rules/platform/windows/idl/idl.lua | 177 +++++++++++++++++++++++++++++ xmake/rules/platform/windows/idl/xmake.lua | 177 +---------------------------- 2 files changed, 181 insertions(+), 173 deletions(-) create mode 100644 xmake/rules/platform/windows/idl/idl.lua diff --git a/xmake/rules/platform/windows/idl/idl.lua b/xmake/rules/platform/windows/idl/idl.lua new file mode 100644 index 000000000..17190be12 --- /dev/null +++ b/xmake/rules/platform/windows/idl/idl.lua @@ -0,0 +1,177 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file idl.lua +-- +import("private.action.build.object", {alias = "build_objectfiles"}) +import("lib.detect.find_tool") +import("core.project.depend") +import("utils.progress") -- it only for v2.5.9, we need use print to show prog + +function generate_single(target, sourcefile, opt) + local msvc = target:toolchain("msvc") or target:toolchain("clang-cl") or target:toolchain("clang") + local midl = assert(find_tool("midl", {envs = msvc:runenvs(), toolchain = msvc}), "midl not found!") + + local name = path.basename(sourcefile) + local fileconfig = target:fileconfig(sourcefile) + local autogendir = path.join(target:autogendir(), "platform/windows/idl") + + local enable_server = true + local enable_client = true + local defs = table.wrap(target:get("defines") or {}) + local incs = table.wrap(target:get("includedirs") or {}) + local undefs = table.wrap(target:get("undefines") or {}) + + + if fileconfig then + if fileconfig.server ~= nil then + enable_server = fileconfig.server + end + if fileconfig.client ~= nil then + enable_client = fileconfig.client + end + if fileconfig.includedirs then + table.join2(incs, fileconfig.includedirs) + end + if fileconfig.defines then + table.join2(defs, fileconfig.defines) + end + if fileconfig.undefines then + table.join2(undefs, fileconfig.undefines) + end + end + + + local flags = {"/nologo"} + table.join2(flags, table.wrap(target:values("idl.flags"))) + + -- specify warn levels + local warns = target:get("warnings") + if warns == "none" then + table.insert(flags, "/W0") + table.insert(flags, "/no_warn") + elseif warns == "less" then + table.insert(flags, "/W1") + elseif warns == "more" then + table.insert(flags, "/W2") + elseif warns == "extra" then + table.insert(flags, "/W3") + elseif warns == "error" then + table.insert(flags, "/WX") + table.insert(flags, "/W4") + end + + -- add include dirs, defines and undefines from compiler flags + for _, inc in ipairs(incs) do + table.insert(flags, "/I") + table.insert(flags, path(inc)) + end + + for _, def in ipairs(defs) do + table.insert(flags, "/D") + table.insert(flags, def) + end + + for _, undef in ipairs(undefs) do + table.insert(flags, "/U") + table.insert(flags, undef) + end + + table.join2(flags, { + "/out", path(autogendir), + "/header", name .. ".h", + "/iid", name .. "_i.c", + "/proxy", name .. "_p.c", + "/tlb", name .. ".tlb", + "/cstub", name .. "_c.c", + "/sstub", name .. "_s.c", + "/server", (enable_server and "stub" or "none"), + "/client", (enable_client and "stub" or "none"), + path(sourcefile) + }) + + depend.on_changed(function() + progress.show(opt.progress or 0, "${color.build.object}generating.idl %s", sourcefile) + os.vrunv(midl.program, flags, { envs = msvc:runenvs() }) + end, {files = sourcefile, + dependfile = path.join(autogendir, path.basename(sourcefile) .. ".idl.d") } + ) +end + +-- add *.idl for rc file + +function configure(target) + local sourcebatch = target:sourcebatches()["platform.windows.idl"] + if sourcebatch then + local autogendir = path.join(target:autogendir(), "platform/windows/idl") + os.mkdir(autogendir) + target:add("includedirs", autogendir, {public = true}) + end +end + +function build_idlfiles(target, jobgraph, sourcebatch, opt) + local mysources = {} + local autogendir = path.join(target:autogendir(), "platform/windows/idl") + + local addsrc = function (sourcename, suffix) + local fullfile = path.join(autogendir, sourcename .. suffix) + if os.exists(fullfile) then + table.insert(mysources, fullfile) + end + end + + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local fileconfig = target:fileconfig(sourcefile) + local enable_proxy = true + if fileconfig then + if fileconfig.proxy ~= nil then + enable_proxy = fileconfig.proxy + end + end + + generate_single(target, sourcefile, opt) + + local name = path.basename(sourcefile) + + addsrc(name, "_i.c") + + if enable_proxy then + addsrc(name, "_p.c") + end + + addsrc(name, "_c.c") + addsrc(name, "_s.c") + end + + -- we don't have a way to detect which midl files are generated + + local batchcxx = { + rulename = "c.build", + sourcekind = "cc", + sourcefiles = mysources, + objectfiles = {}, + dependfiles = {} + } + for _, sourcefile in ipairs(batchcxx.sourcefiles) do + local objfile = target:objectfile(sourcefile) + local depfile = target:objectfile(objfile) + table.insert(target:objectfiles(), objfile) + table.insert(batchcxx.objectfiles, objfile) + table.insert(batchcxx.dependfiles, depfile) + end + build_objectfiles(target, jobgraph, batchcxx, opt) +end diff --git a/xmake/rules/platform/windows/idl/xmake.lua b/xmake/rules/platform/windows/idl/xmake.lua index e34acc4a0..cd138eadc 100644 --- a/xmake/rules/platform/windows/idl/xmake.lua +++ b/xmake/rules/platform/windows/idl/xmake.lua @@ -16,184 +16,15 @@ -- -- @author ruki -- @file xmake.lua --- -- add *.idl for rc file rule("platform.windows.idl") set_extensions(".idl") on_config("windows", "mingw", function (target) - local sourcebatch = target:sourcebatches()["platform.windows.idl"] - if sourcebatch then - local autogendir = path.join(target:autogendir(), "platform/windows/idl") - os.mkdir(autogendir) - target:add("includedirs", autogendir, {public = true}) - end + import("idl").configure(target) end) - before_buildcmd_file(function (target, batchcmds, sourcefile, opt) - import("lib.detect.find_tool") - import("core.project.depend") - import("utils.progress") -- it only for v2.5.9, we need use print to show prog - - local fileconfig = target:fileconfig(sourcefile) - local enable_server = true - local enable_client = true - - local defs = table.wrap(target:get("defines") or {}) - local incs = table.wrap(target:get("includedirs") or {}) - local undefs = table.wrap(target:get("undefines") or {}) - - if fileconfig then - if fileconfig.server then - enable_server = fileconfig.server - end - if fileconfig.client then - enable_client = fileconfig.client - end - if fileconfig.includedirs then - table.join2(incs, fileconfig.includedirs) - end - if fileconfig.defines then - table.join2(defs, fileconfig.defines) - end - if fileconfig.undefines then - table.join2(undefs, fileconfig.undefines) - end - end - - local msvc = target:toolchain("msvc") or target:toolchain("clang-cl") or target:toolchain("clang") - local midl = assert(find_tool("midl", {envs = msvc:runenvs(), toolchain = msvc}), "midl not found!") - - local name = path.basename(sourcefile) - local autogendir = path.join(target:autogendir(), "platform/windows/idl") - - local flags = {"/nologo"} - table.join2(flags, table.wrap(target:values("idl.flags"))) - - -- specify warn levels - local warns = target:get("warnings") - if warns == "none" then - table.insert(flags, "/W0") - table.insert(flags, "/no_warn") - elseif warns == "less" then - table.insert(flags, "/W1") - elseif warns == "more" then - table.insert(flags, "/W2") - elseif warns == "extra" then - table.insert(flags, "/W3") - elseif warns == "error" then - table.insert(flags, "/WX") - table.insert(flags, "/W4") - end - - -- add include dirs, defines and undefines from compiler flags - for _, inc in ipairs(incs) do - table.insert(flags, "/I") - table.insert(flags, path(inc)) - end - - for _, def in ipairs(defs) do - table.insert(flags, "/D") - table.insert(flags, def) - end - - for _, undef in ipairs(undefs) do - table.insert(flags, "/U") - table.insert(flags, undef) - end - - table.join2(flags, { - "/out", path(autogendir), - "/header", name .. ".h", - "/iid", name .. "_i.c", - "/proxy", name .. "_p.c", - "/tlb", name .. ".tlb", - "/cstub", name .. "_c.c", - "/sstub", name .. "_s.c", - "/server", (enable_server and "stub" or "none"), - "/client", (enable_client and "stub" or "none"), - path(sourcefile) - }) - - -- use this way to set depend to avoid generating files multiple times - depend.on_changed(function() - progress.show(opt.progress, "${color.build.object}generating.idl %s", sourcefile) - os.vrunv(midl.program, flags, { envs = msvc:runenvs() }) - end, { files = sourcefile, dependfile = path.join(autogendir, path.basename(sourcefile) .. ".idl.d") }) - end) - - --[[ - we don't have a way to detect which files midl.exe has generated and os.exists - does not work in before_buildcmd_file because in the invokation of xmake - the files might not have been generated yet from batchcmds, therefore - the files are compiled and checked during the buildcmd as _i, _p, _c, _s - might not exists depending on the idl file - ]] - on_buildcmd_file(function (target, batchcmds, sourcefile, opt) - import("core.project.depend") - - local name = path.basename(sourcefile) - local autogendir = path.join(target:autogendir(), "platform/windows/idl") - - -- we don't have a way to detect which midl files are generated - - local icfile = path.join(autogendir, name .. "_i.c") - local icobj = target:objectfile(icfile) - - local scfile = path.join(autogendir, name .. "_s.c") - local scobj = target:objectfile(scfile) - - local ccfile = path.join(autogendir, name .. "_c.c") - local ccobj = target:objectfile(ccfile) - - local pcfile = path.join(autogendir, name .. "_p.c") - local pcobj = target:objectfile(pcfile) - - local fileconfig = target:fileconfig(sourcefile) - local enable_proxy = true - if fileconfig then - if fileconfig.proxy ~= nil then - enable_proxy = fileconfig.proxy - end - end - - -- compile c files - local configs = {includedirs = autogendir, languages = "c89"} - - if os.exists(icfile) then - table.insert(target:objectfiles(), icobj) - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", icfile) - batchcmds:compile(icfile, icobj, {sourcekind = "cxx", configs = configs}) - batchcmds:add_depfiles(icfile) - batchcmds:set_depmtime(os.mtime(icobj)) - batchcmds:set_depcache(target:dependfile(icobj)) - end - - if os.exists(scfile) then - table.insert(target:objectfiles(), scobj) - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", scfile) - batchcmds:compile(scfile, scobj, {sourcekind = "cxx", configs = configs}) - batchcmds:add_depfiles(scfile) - batchcmds:set_depmtime(os.mtime(scobj)) - batchcmds:set_depcache(target:dependfile(scobj)) - end - - if os.exists(pcfile) and enable_proxy then - table.insert(target:objectfiles(), pcobj) - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", pcfile) - batchcmds:compile(pcfile, pcobj, {sourcekind = "cxx", configs = configs}) - batchcmds:add_depfiles(pcfile) - batchcmds:set_depmtime(os.mtime(pcobj)) - batchcmds:set_depcache(target:dependfile(pcobj)) - end - - if os.exists(ccfile) then - table.insert(target:objectfiles(), ccobj) - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.$(mode) %s", ccfile) - batchcmds:compile(ccfile, ccobj, {sourcekind = "cxx", configs = configs}) - batchcmds:add_depfiles(ccfile) - batchcmds:set_depmtime(os.mtime(ccobj)) - batchcmds:set_depcache(target:dependfile(ccobj)) - end - end) + on_build_files(function (target, jobgraph, sourcebatch, opt) + import("idl").build_idlfiles(target, jobgraph, sourcebatch, opt) + end, { jobgraph = true, batch = true, distcc = true }) -- cgit v1.3.1 From d9d3b81f0804717fa1055c7106de72445d2b2264 Mon Sep 17 00:00:00 2001 From: Christian Rendina Date: Tue, 15 Apr 2025 15:40:44 +0200 Subject: Address formatting --- tests/projects/idl/test_norpc/src/test_iid.c | 2 +- tests/projects/idl/test_norpc_proxy/src/test_iid.c | 2 +- tests/projects/idl/test_rpc/src/test_iid.c | 2 +- tests/projects/idl/test_rpc_noserver/src/test_iid.c | 2 +- xmake/rules/platform/windows/idl/idl.lua | 8 ++------ 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/tests/projects/idl/test_norpc/src/test_iid.c b/tests/projects/idl/test_norpc/src/test_iid.c index b581c32fb..79b344b9a 100644 --- a/tests/projects/idl/test_norpc/src/test_iid.c +++ b/tests/projects/idl/test_norpc/src/test_iid.c @@ -1,7 +1,7 @@ #include #include -int main() { +int main(int argc, char** argv) { IID g = IID_ILockOwner; printf("GUID: %x-%x-%x-%llx", g.Data1, g.Data2, g.Data3, *(unsigned long long*)g.Data4); return 0; diff --git a/tests/projects/idl/test_norpc_proxy/src/test_iid.c b/tests/projects/idl/test_norpc_proxy/src/test_iid.c index b581c32fb..79b344b9a 100644 --- a/tests/projects/idl/test_norpc_proxy/src/test_iid.c +++ b/tests/projects/idl/test_norpc_proxy/src/test_iid.c @@ -1,7 +1,7 @@ #include #include -int main() { +int main(int argc, char** argv) { IID g = IID_ILockOwner; printf("GUID: %x-%x-%x-%llx", g.Data1, g.Data2, g.Data3, *(unsigned long long*)g.Data4); return 0; diff --git a/tests/projects/idl/test_rpc/src/test_iid.c b/tests/projects/idl/test_rpc/src/test_iid.c index b835c9fde..56e1e6e47 100644 --- a/tests/projects/idl/test_rpc/src/test_iid.c +++ b/tests/projects/idl/test_rpc/src/test_iid.c @@ -2,7 +2,7 @@ #include #include -int main() { +int main(int argc, char** argv) { MyInterface_v1_0_c_ifspec = (void*)1; MyInterface_v1_0_s_ifspec = (void*)1; printf("set ok\n"); diff --git a/tests/projects/idl/test_rpc_noserver/src/test_iid.c b/tests/projects/idl/test_rpc_noserver/src/test_iid.c index 8edfb7807..041033894 100644 --- a/tests/projects/idl/test_rpc_noserver/src/test_iid.c +++ b/tests/projects/idl/test_rpc_noserver/src/test_iid.c @@ -2,7 +2,7 @@ #include #include -int main() { +int main(int argc, char** argv) { MyInterface_v1_0_c_ifspec = (void*)1; printf("call ok\n"); return 0; diff --git a/xmake/rules/platform/windows/idl/idl.lua b/xmake/rules/platform/windows/idl/idl.lua index 17190be12..f44611424 100644 --- a/xmake/rules/platform/windows/idl/idl.lua +++ b/xmake/rules/platform/windows/idl/idl.lua @@ -36,7 +36,6 @@ function generate_single(target, sourcefile, opt) local incs = table.wrap(target:get("includedirs") or {}) local undefs = table.wrap(target:get("undefines") or {}) - if fileconfig then if fileconfig.server ~= nil then enable_server = fileconfig.server @@ -55,7 +54,6 @@ function generate_single(target, sourcefile, opt) end end - local flags = {"/nologo"} table.join2(flags, table.wrap(target:values("idl.flags"))) @@ -112,8 +110,6 @@ function generate_single(target, sourcefile, opt) ) end --- add *.idl for rc file - function configure(target) local sourcebatch = target:sourcebatches()["platform.windows.idl"] if sourcebatch then @@ -147,6 +143,8 @@ function build_idlfiles(target, jobgraph, sourcebatch, opt) local name = path.basename(sourcefile) + -- we don't have a way to detect which midl files are generated + addsrc(name, "_i.c") if enable_proxy then @@ -157,8 +155,6 @@ function build_idlfiles(target, jobgraph, sourcebatch, opt) addsrc(name, "_s.c") end - -- we don't have a way to detect which midl files are generated - local batchcxx = { rulename = "c.build", sourcekind = "cc", -- cgit v1.3.1 From 42371b9d4d7b3c397e620bfa29041614a8416041 Mon Sep 17 00:00:00 2001 From: Christian Rendina Date: Wed, 16 Apr 2025 11:54:52 +0200 Subject: Use jobgraph rather than batchcmd --- xmake/rules/platform/windows/idl/idl.lua | 82 ++++++++++++++++-------------- xmake/rules/platform/windows/idl/xmake.lua | 7 +-- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/xmake/rules/platform/windows/idl/idl.lua b/xmake/rules/platform/windows/idl/idl.lua index f44611424..c6f65fc82 100644 --- a/xmake/rules/platform/windows/idl/idl.lua +++ b/xmake/rules/platform/windows/idl/idl.lua @@ -119,11 +119,19 @@ function configure(target) end end +function gen_idl(target, jobgraph, sourcebatch, opt) + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local midljob = target:fullname() .. "/midl/generate/" .. sourcefile + jobgraph:add(midljob, function (index, total, opt) + generate_single(target, sourcefile, opt) + end) + end +end + function build_idlfiles(target, jobgraph, sourcebatch, opt) - local mysources = {} local autogendir = path.join(target:autogendir(), "platform/windows/idl") - local addsrc = function (sourcename, suffix) + local addsrc = function (sourcename, suffix, mysources) local fullfile = path.join(autogendir, sourcename .. suffix) if os.exists(fullfile) then table.insert(mysources, fullfile) @@ -131,43 +139,41 @@ function build_idlfiles(target, jobgraph, sourcebatch, opt) end for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - local fileconfig = target:fileconfig(sourcefile) - local enable_proxy = true - if fileconfig then - if fileconfig.proxy ~= nil then - enable_proxy = fileconfig.proxy + local ccjob = target:fullname() .. "/midl/compile/" .. sourcefile + jobgraph:add(ccjob, function (index, total, opt) + local fileconfig = target:fileconfig(sourcefile) + local enable_proxy = true + if fileconfig then + if fileconfig.proxy ~= nil then + enable_proxy = fileconfig.proxy + end end - end - - generate_single(target, sourcefile, opt) - - local name = path.basename(sourcefile) - - -- we don't have a way to detect which midl files are generated + local name = path.basename(sourcefile) + local mysources = {} - addsrc(name, "_i.c") - - if enable_proxy then - addsrc(name, "_p.c") - end - - addsrc(name, "_c.c") - addsrc(name, "_s.c") - end - - local batchcxx = { - rulename = "c.build", - sourcekind = "cc", - sourcefiles = mysources, - objectfiles = {}, - dependfiles = {} - } - for _, sourcefile in ipairs(batchcxx.sourcefiles) do - local objfile = target:objectfile(sourcefile) - local depfile = target:objectfile(objfile) - table.insert(target:objectfiles(), objfile) - table.insert(batchcxx.objectfiles, objfile) - table.insert(batchcxx.dependfiles, depfile) + -- we don't have a way to detect which midl files are generated + addsrc(name, "_i.c", mysources) + if enable_proxy then + addsrc(name, "_p.c", mysources) + end + addsrc(name, "_c.c", mysources) + addsrc(name, "_s.c", mysources) + + local batchcxx = { + rulename = "c.build", + sourcekind = "cc", + sourcefiles = mysources, + objectfiles = {}, + dependfiles = {} + } + for _, sourcefile in ipairs(batchcxx.sourcefiles) do + local objfile = target:objectfile(sourcefile) + local depfile = target:objectfile(objfile) + table.insert(target:objectfiles(), objfile) + table.insert(batchcxx.objectfiles, objfile) + table.insert(batchcxx.dependfiles, depfile) + end + build_objectfiles(target, jobgraph, batchcxx, opt) + end) end - build_objectfiles(target, jobgraph, batchcxx, opt) end diff --git a/xmake/rules/platform/windows/idl/xmake.lua b/xmake/rules/platform/windows/idl/xmake.lua index cd138eadc..f7a47b230 100644 --- a/xmake/rules/platform/windows/idl/xmake.lua +++ b/xmake/rules/platform/windows/idl/xmake.lua @@ -20,11 +20,12 @@ -- add *.idl for rc file rule("platform.windows.idl") set_extensions(".idl") - on_config("windows", "mingw", function (target) import("idl").configure(target) end) - + before_build_files(function (target, jobgraph, sourcebatch, opt) + import("idl").gen_idl(target, jobgraph, sourcebatch, opt) + end, {jobgraph = true, batch = true}) on_build_files(function (target, jobgraph, sourcebatch, opt) import("idl").build_idlfiles(target, jobgraph, sourcebatch, opt) - end, { jobgraph = true, batch = true, distcc = true }) + end, {jobgraph = true, batch = true, distcc = true}) -- cgit v1.3.1 From 70c19442388286529c7a17f5edde4f5d31d17fc7 Mon Sep 17 00:00:00 2001 From: Christian Rendina Date: Tue, 22 Apr 2025 10:58:22 +0200 Subject: Use jobgraphs --- xmake/rules/platform/windows/idl/idl.lua | 93 +++++++++++++++++--------------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/xmake/rules/platform/windows/idl/idl.lua b/xmake/rules/platform/windows/idl/idl.lua index c6f65fc82..0c4715fad 100644 --- a/xmake/rules/platform/windows/idl/idl.lua +++ b/xmake/rules/platform/windows/idl/idl.lua @@ -120,12 +120,15 @@ function configure(target) end function gen_idl(target, jobgraph, sourcebatch, opt) - for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - local midljob = target:fullname() .. "/midl/generate/" .. sourcefile - jobgraph:add(midljob, function (index, total, opt) - generate_single(target, sourcefile, opt) - end) - end + local idljob = target:fullname() .. "/generate/midl" + jobgraph:group(idljob, function() + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local midljob = target:fullname() .. "/generate/" .. sourcefile + jobgraph:add(midljob, function (index, total, opt) + generate_single(target, sourcefile, opt) + end) + end + end) end function build_idlfiles(target, jobgraph, sourcebatch, opt) @@ -138,42 +141,46 @@ function build_idlfiles(target, jobgraph, sourcebatch, opt) end end - for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - local ccjob = target:fullname() .. "/midl/compile/" .. sourcefile - jobgraph:add(ccjob, function (index, total, opt) - local fileconfig = target:fileconfig(sourcefile) - local enable_proxy = true - if fileconfig then - if fileconfig.proxy ~= nil then - enable_proxy = fileconfig.proxy + local jobgrp = target:fullname() .. "/obj/midl" + jobgraph:group(jobgrp, function() + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + local ccjob = target:fullname() .. "/obj/" .. sourcefile + jobgraph:add(ccjob, function (index, total, opt) + local fileconfig = target:fileconfig(sourcefile) + local enable_proxy = true + if fileconfig then + if fileconfig.proxy ~= nil then + enable_proxy = fileconfig.proxy + end end - end - local name = path.basename(sourcefile) - local mysources = {} - - -- we don't have a way to detect which midl files are generated - addsrc(name, "_i.c", mysources) - if enable_proxy then - addsrc(name, "_p.c", mysources) - end - addsrc(name, "_c.c", mysources) - addsrc(name, "_s.c", mysources) - - local batchcxx = { - rulename = "c.build", - sourcekind = "cc", - sourcefiles = mysources, - objectfiles = {}, - dependfiles = {} - } - for _, sourcefile in ipairs(batchcxx.sourcefiles) do - local objfile = target:objectfile(sourcefile) - local depfile = target:objectfile(objfile) - table.insert(target:objectfiles(), objfile) - table.insert(batchcxx.objectfiles, objfile) - table.insert(batchcxx.dependfiles, depfile) - end - build_objectfiles(target, jobgraph, batchcxx, opt) - end) - end + local name = path.basename(sourcefile) + local mysources = {} + + -- we don't have a way to detect which midl files are generated + addsrc(name, "_i.c", mysources) + if enable_proxy then + addsrc(name, "_p.c", mysources) + end + addsrc(name, "_c.c", mysources) + addsrc(name, "_s.c", mysources) + + local batchcxx = { + rulename = "c.build", + sourcekind = "cc", + sourcefiles = mysources, + objectfiles = {}, + dependfiles = {} + } + for _, sourcefile in ipairs(batchcxx.sourcefiles) do + local objfile = target:objectfile(sourcefile) + local depfile = target:objectfile(objfile) + table.insert(target:objectfiles(), objfile) + table.insert(batchcxx.objectfiles, objfile) + table.insert(batchcxx.dependfiles, depfile) + table.insert(target:objectfiles(), objfile) + end + build_objectfiles.build(target, batchcxx, opt) + end) + end + end) end -- cgit v1.3.1 From a0d0742175678a5829cbda0ada1f6cb89883214e Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 22 Apr 2025 17:35:01 +0800 Subject: Update idl.lua --- xmake/rules/platform/windows/idl/idl.lua | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/xmake/rules/platform/windows/idl/idl.lua b/xmake/rules/platform/windows/idl/idl.lua index 0c4715fad..3f18380cf 100644 --- a/xmake/rules/platform/windows/idl/idl.lua +++ b/xmake/rules/platform/windows/idl/idl.lua @@ -17,10 +17,12 @@ -- @author ruki -- @file idl.lua -- -import("private.action.build.object", {alias = "build_objectfiles"}) + +-- imports import("lib.detect.find_tool") import("core.project.depend") -import("utils.progress") -- it only for v2.5.9, we need use print to show prog +import("utils.progress") +import("private.action.build.object", {alias = "build_objectfiles"}) function generate_single(target, sourcefile, opt) local msvc = target:toolchain("msvc") or target:toolchain("clang-cl") or target:toolchain("clang") @@ -37,10 +39,10 @@ function generate_single(target, sourcefile, opt) local undefs = table.wrap(target:get("undefines") or {}) if fileconfig then - if fileconfig.server ~= nil then + if fileconfig.server then enable_server = fileconfig.server end - if fileconfig.client ~= nil then + if fileconfig.client then enable_client = fileconfig.client end if fileconfig.includedirs then @@ -102,12 +104,14 @@ function generate_single(target, sourcefile, opt) path(sourcefile) }) - depend.on_changed(function() + local dependfile = path.join(autogendir, path.basename(sourcefile) .. ".idl.d") + depend.on_changed(function() progress.show(opt.progress or 0, "${color.build.object}generating.idl %s", sourcefile) os.vrunv(midl.program, flags, { envs = msvc:runenvs() }) - end, {files = sourcefile, - dependfile = path.join(autogendir, path.basename(sourcefile) .. ".idl.d") } - ) + end, { + files = sourcefile, + dependfile = dependfile + }) end function configure(target) @@ -119,7 +123,7 @@ function configure(target) end end -function gen_idl(target, jobgraph, sourcebatch, opt) +function generate_idl(target, jobgraph, sourcebatch, opt) local idljob = target:fullname() .. "/generate/midl" jobgraph:group(idljob, function() for _, sourcefile in ipairs(sourcebatch.sourcefiles) do @@ -134,22 +138,22 @@ end function build_idlfiles(target, jobgraph, sourcebatch, opt) local autogendir = path.join(target:autogendir(), "platform/windows/idl") - local addsrc = function (sourcename, suffix, mysources) + local function addsrc(sourcename, suffix, mysources) local fullfile = path.join(autogendir, sourcename .. suffix) if os.exists(fullfile) then table.insert(mysources, fullfile) end end - local jobgrp = target:fullname() .. "/obj/midl" - jobgraph:group(jobgrp, function() + local build_midl = target:fullname() .. "/obj/midl" + jobgraph:group(build_midl, function() for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local ccjob = target:fullname() .. "/obj/" .. sourcefile jobgraph:add(ccjob, function (index, total, opt) local fileconfig = target:fileconfig(sourcefile) local enable_proxy = true if fileconfig then - if fileconfig.proxy ~= nil then + if fileconfig.proxy then enable_proxy = fileconfig.proxy end end @@ -177,7 +181,7 @@ function build_idlfiles(target, jobgraph, sourcebatch, opt) table.insert(target:objectfiles(), objfile) table.insert(batchcxx.objectfiles, objfile) table.insert(batchcxx.dependfiles, depfile) - table.insert(target:objectfiles(), objfile) + table.insert(target:objectfiles(), objfile) end build_objectfiles.build(target, batchcxx, opt) end) -- cgit v1.3.1 From 700b5497b88aecdfc604ef866f666d13f7d6c0b5 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 22 Apr 2025 17:35:50 +0800 Subject: Update xmake.lua --- xmake/rules/platform/windows/idl/xmake.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xmake/rules/platform/windows/idl/xmake.lua b/xmake/rules/platform/windows/idl/xmake.lua index f7a47b230..4e3aabd1b 100644 --- a/xmake/rules/platform/windows/idl/xmake.lua +++ b/xmake/rules/platform/windows/idl/xmake.lua @@ -23,9 +23,11 @@ rule("platform.windows.idl") on_config("windows", "mingw", function (target) import("idl").configure(target) end) + before_build_files(function (target, jobgraph, sourcebatch, opt) - import("idl").gen_idl(target, jobgraph, sourcebatch, opt) + import("idl").generate_idl(target, jobgraph, sourcebatch, opt) end, {jobgraph = true, batch = true}) + on_build_files(function (target, jobgraph, sourcebatch, opt) import("idl").build_idlfiles(target, jobgraph, sourcebatch, opt) end, {jobgraph = true, batch = true, distcc = true}) -- cgit v1.3.1