diff options
| author | ruki <[email protected]> | 2025-03-30 01:05:28 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-04-08 15:31:57 +0800 |
| commit | 736e327bf3b51888da68cba78f4ee1b780a7b1d6 (patch) | |
| tree | 267849cae37bf4ae6ab3da19c74df9fe8c6eb155 | |
| parent | b644fa46c237f5471e313dfa28f4ffc11cec956f (diff) | |
improve protobuf
| -rw-r--r-- | xmake/core/base/graph.lua | 5 | ||||
| -rw-r--r-- | xmake/rules/protobuf/proto.lua | 93 | ||||
| -rw-r--r-- | xmake/rules/protobuf/xmake.lua | 14 |
3 files changed, 11 insertions, 101 deletions
diff --git a/xmake/core/base/graph.lua b/xmake/core/base/graph.lua index db8682b21..53f09c59f 100644 --- a/xmake/core/base/graph.lua +++ b/xmake/core/base/graph.lua @@ -318,6 +318,11 @@ function graph:topo_sort() return order_vertices, has_cycle end +-- deprecated +function graph:topological_sort() + return self:topo_sort() +end + -- find cycle function graph:find_cycle() local visited = {} diff --git a/xmake/rules/protobuf/proto.lua b/xmake/rules/protobuf/proto.lua index c35ffb697..bebeb3105 100644 --- a/xmake/rules/protobuf/proto.lua +++ b/xmake/rules/protobuf/proto.lua @@ -22,10 +22,8 @@ import("core.base.option") import("lib.detect.find_tool") import("core.project.depend") -import("private.action.build.object", {alias = "build_objectfiles"}) import("utils.progress") import("private.utils.batchcmds") -import("private.async.buildjobs") -- get protoc function _get_protoc(target, sourcekind) @@ -100,7 +98,7 @@ function load(target, sourcekind) end end -function buildcmd_pfiles(target, batchcmds, sourcefile_proto, opt, sourcekind) +function buildcmd_pfile(target, batchcmds, sourcefile_proto, sourcekind, opt) -- get protoc local protoc = _get_protoc(target, sourcekind) @@ -166,7 +164,7 @@ function buildcmd_pfiles(target, batchcmds, sourcefile_proto, opt, sourcekind) end end -function buildcmd_cxfiles(target, batchcmds, sourcefile_proto, opt, sourcekind) +function buildcmd_cxfile(target, batchcmds, sourcefile_proto, sourcekind, opt) -- get protoc local protoc = _get_protoc(target, sourcekind) @@ -223,90 +221,3 @@ function buildcmd_cxfiles(target, batchcmds, sourcefile_proto, opt, sourcekind) end end -function build_cxfile_objects(target, batchjobs, opt, sourcekind) - local sourcebatch_cx = { - rulename = (sourcekind == "cxx" and "c++" or "c").. ".build", - sourcekind = sourcekind, - sourcefiles = {}, - objectfiles = {}, - dependfiles = {} - } - for _, sourcefile_proto in ipairs(sourcefiles) do - -- get c/c++ source file for protobuf - local prefixdir - local autogendir - local public - local grpc_cpp_plugin - local fileconfig = target:fileconfig(sourcefile_proto) - if fileconfig then - public = fileconfig.proto_public - prefixdir = fileconfig.proto_rootdir - -- custom autogen directory to access the generated header files - -- @see https://github.com/xmake-io/xmake/issues/3678 - autogendir = fileconfig.proto_autogendir - grpc_cpp_plugin = fileconfig.proto_grpc_cpp_plugin - end - local rootdir = autogendir and autogendir or path.join(target:autogendir(), "rules", "protobuf") - local filename = path.basename(sourcefile_proto) .. ".pb" .. (sourcekind == "cxx" and ".cc" or "-c.c") - local sourcefile_cx = target:autogenfile(sourcefile_proto, {rootdir = rootdir, filename = filename}) - local sourcefile_dir = prefixdir and path.join(rootdir, prefixdir) or path.directory(sourcefile_cx) - - local grpc_cpp_plugin_bin - local filename_grpc - local sourcefile_cx_grpc - if grpc_cpp_plugin then - grpc_cpp_plugin_bin = _get_grpc_cpp_plugin(target, sourcekind) - filename_grpc = path.basename(sourcefile_proto) .. ".grpc.pb.cc" - sourcefile_cx_grpc = target:autogenfile(sourcefile_proto, {rootdir = rootdir, filename = filename_grpc}) - end - - -- add includedirs - target:add("includedirs", sourcefile_dir, {public = public}) - - -- add objectfile - local objectfile = target:objectfile(sourcefile_cx) - local dependfile = target:dependfile(sourcefile_proto) - table.insert(sourcebatch_cx.sourcefiles, sourcefile_cx) - table.insert(sourcebatch_cx.objectfiles, objectfile) - table.insert(sourcebatch_cx.dependfiles, dependfile) - - local objectfile_grpc - if grpc_cpp_plugin then - objectfile_grpc = target:objectfile(sourcefile_cx_grpc) - table.insert(sourcebatch_cx.sourcefiles, sourcefile_cx_grpc) - table.insert(sourcebatch_cx.objectfiles, objectfile_grpc) - table.insert(sourcebatch_cx.dependfiles, dependfile) - end - end - build_objectfiles(target, batchjobs, sourcebatch_cx, opt) -end - --- build batch jobs -function build_cxfiles(target, batchjobs, sourcebatch, opt, sourcekind) - opt = opt or {} - local nodes = {} - local nodenames = {} - local node_rulename = "rules/" .. sourcebatch.rulename .. "/node" - local sourcefiles = sourcebatch.sourcefiles - for _, sourcefile_proto in ipairs(sourcefiles) do - local nodename = node_rulename .. "/" .. sourcefile_proto - nodes[nodename] = { - name = nodename, - job = batchjobs:addjob(nodename, function(index, total, jobopt) - local batchcmds_ = batchcmds.new({target = target}) - buildcmd_pfiles(target, batchcmds_, sourcefile_proto, {progress = jobopt.progress}, sourcekind) - batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")}) - end) - } - table.insert(nodenames, nodename) - end - local rootname = "rules/" .. sourcebatch.rulename .. "/root" - nodes[rootname] = { - name = rootname, - deps = nodenames, - job = batchjobs:addjob(rootname, function(_index, _total) - build_cxfile_objects(target, batchjobs, opt, sourcekind) - end) - } - buildjobs(nodes, batchjobs, opt.rootjob) -end diff --git a/xmake/rules/protobuf/xmake.lua b/xmake/rules/protobuf/xmake.lua index 119ff3d1f..f2cbf2615 100644 --- a/xmake/rules/protobuf/xmake.lua +++ b/xmake/rules/protobuf/xmake.lua @@ -27,14 +27,11 @@ rule("protobuf.cpp") end) -- generate build commands before_buildcmd_file(function(target, batchcmds, sourcefile_proto, opt) - import("proto").buildcmd_pfiles(target, batchcmds, sourcefile_proto, opt, "cxx") + import("proto").buildcmd_pfile(target, batchcmds, sourcefile_proto, "cxx", opt) end) on_buildcmd_file(function(target, batchcmds, sourcefile_proto, opt) - import("proto").buildcmd_cxfiles(target, batchcmds, sourcefile_proto, opt, "cxx") + import("proto").buildcmd_cxfile(target, batchcmds, sourcefile_proto, "cxx", opt) end) - before_build_files(function (target, batchjobs, sourcebatch, opt) - import("proto").build_cxfiles(target, batchjobs, sourcebatch, opt, "cxx") - end, {batch = true}) -- define rule: protobuf.c @@ -45,11 +42,8 @@ rule("protobuf.c") import("proto").load(target, "cc") end) before_buildcmd_file(function(target, batchcmds, sourcefile_proto, opt) - import("proto").buildcmd_pfiles(target, batchcmds, sourcefile_proto, opt, "cc") + import("proto").buildcmd_pfile(target, batchcmds, sourcefile_proto, "cc", opt) end) on_buildcmd_file(function(target, batchcmds, sourcefile_proto, opt) - import("proto").buildcmd_cxfiles(target, batchcmds, sourcefile_proto, opt, "cc") + import("proto").buildcmd_cxfile(target, batchcmds, sourcefile_proto, "cc", opt) end) - before_build_files(function (target, batchjobs, sourcebatch, opt) - import("proto").build_cxfiles(target, batchjobs, sourcebatch, opt, "cc") - end, {batch = true}) |
