diff options
| author | Chi Huu Huynh <[email protected]> | 2023-11-16 10:15:57 +0000 |
|---|---|---|
| committer | Chi Huu Huynh <[email protected]> | 2023-11-16 10:15:57 +0000 |
| commit | 45cacaf1760d36db7f1f7f121ee25b966a0a3037 (patch) | |
| tree | 7530e43053deb26af88a53b37c713f7285c2e1d2 | |
| parent | 7b1a926435cdd81c9b09a2eedfa43fe7c00c3302 (diff) | |
Remove `build_c_cmd` and `build_compiled_sourcefiles_proto`
| -rw-r--r-- | xmake/rules/protobuf/proto.lua | 78 | ||||
| -rw-r--r-- | xmake/rules/protobuf/xmake.lua | 14 |
2 files changed, 3 insertions, 89 deletions
diff --git a/xmake/rules/protobuf/proto.lua b/xmake/rules/protobuf/proto.lua index 08f8bf12e..7e43e9bdd 100644 --- a/xmake/rules/protobuf/proto.lua +++ b/xmake/rules/protobuf/proto.lua @@ -140,70 +140,13 @@ function build_proto_cmd(target, batchcmds, sourcefile_proto, opt, sourcekind) -- add commands batchcmds:mkdir(sourcefile_dir) - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.proto to %s %s", (sourcekind == "cxx" and "cpp" or "c"), sourcefile_proto) + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.proto %s", sourcefile_proto) batchcmds:vrunv(protoc, protoc_args) end --- generate build commands -function build_c_cmd(target, batchcmds, sourcefile_proto, opt, sourcekind) - -- get protoc - local protoc = _get_protoc(target, sourcekind) - - -- 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 filename_grpc - local sourcefile_cx_grpc - if grpc_cpp_plugin then - filename_grpc = path.basename(sourcefile_proto) .. ".grpc.pb.cc" - sourcefile_cx_grpc = target:autogenfile(sourcefile_proto, {rootdir = rootdir, filename = filename_grpc}) - end - - -- add objectfile - local objectfile = target:objectfile(sourcefile_cx) - table.insert(target:objectfiles(), objectfile) - - local objectfile_grpc - if grpc_cpp_plugin then - objectfile_grpc = target:objectfile(sourcefile_cx_grpc) - table.insert(target:objectfiles(), objectfile_grpc) - end - - batchcmds:show_progress(opt.progress, "${color.build.object}compiling.proto %s file %s", (sourcekind == "cxx" and "cpp" or "c"), sourcefile_proto) - batchcmds:compile(sourcefile_cx, objectfile, {configs = {includedirs = sourcefile_dir}}) - if grpc_cpp_plugin then - batchcmds:compile(sourcefile_cx_grpc, objectfile_grpc, {configs = {includedirs = sourcefile_dir}}) - end - - -- add deps - local depmtime = os.mtime(objectfile) - batchcmds:add_depfiles(sourcefile_proto) - batchcmds:set_depcache(target:dependfile(objectfile)) - if grpc_cpp_plugin then - batchcmds:set_depmtime(math.max(os.mtime(objectfile_grpc), depmtime)) - else - batchcmds:set_depmtime(depmtime) - end -end - -- build batch jobs function build_sourcefiles_proto(target, batchjobs, sourcebatch, opt, sourcekind) + -- get the root directory of protobuf local proto_rootdir if #sourcebatch.sourcefiles > 0 then @@ -223,8 +166,8 @@ function build_sourcefiles_proto(target, batchjobs, sourcebatch, opt, sourcekind for i = 1, sourcefiles_total do local sourcefile = sourcebatch.sourcefiles[i] local moduleinfo = moduledeps_files[sourcefile] or {} - -- make build job moduleinfo.job = batchjobs:newjob(sourcefile, function (index, total) + -- make build job local batchcmds_ = batchcmds.new({target = target}) build_proto_cmd(target, batchcmds_, sourcefile, {progress = (index * 100) / total}, sourcekind) batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")}) @@ -232,18 +175,3 @@ function build_sourcefiles_proto(target, batchjobs, sourcebatch, opt, sourcekind end module_parser.build_batchjobs(moduledeps, batchjobs, opt.rootjob) end - -function build_compiled_sourcefiles_proto(target, batchjobs, sourcebatch, opt, sourcekind) - opt = opt or {} - local sourcefiles_total = #sourcebatch.sourcefiles - -- generate jobs - for i = 1, sourcefiles_total do - local sourcefile = sourcebatch.sourcefiles[i] - -- make build job - batchjobs:newjob(sourcefile, function (index, total) - local batchcmds_ = batchcmds.new({target = target}) - build_c_cmd(target, batchcmds_, sourcefile, {progress = (index * 100) / total}, sourcekind) - batchcmds_:runcmds({changed = target:is_rebuilt(), dryrun = option.get("dry-run")}) - end) - end -end
\ No newline at end of file diff --git a/xmake/rules/protobuf/xmake.lua b/xmake/rules/protobuf/xmake.lua index 40d759f13..294d1f8be 100644 --- a/xmake/rules/protobuf/xmake.lua +++ b/xmake/rules/protobuf/xmake.lua @@ -28,15 +28,9 @@ rule("protobuf.cpp") before_buildcmd_file(function (target, batchcmds, sourcefile_proto, opt) import("proto").build_proto_cmd(target, batchcmds, sourcefile_proto, opt, "cxx") end) - on_buildcmd_file(function (target, batchcmds, sourcefile_proto, opt) - import("proto").build_c_cmd(target, batchcmds, sourcefile_proto, opt, "cxx") - end) before_build_files(function (target, batchjobs, sourcebatch, opt) import("proto").build_sourcefiles_proto(target, batchjobs, sourcebatch, opt, "cxx") end, {batch = true}) - on_build_files(function (target, batchjobs, sourcebatch, opt) - import("proto").build_compiled_sourcefiles_proto(target, batchjobs, sourcebatch, opt, "cxx") - end, {batch = true}) -- define rule: protobuf.c @@ -49,14 +43,6 @@ rule("protobuf.c") before_buildcmd_file(function (target, batchcmds, sourcefile_proto, opt) import("proto").build_proto_cmd(target, batchcmds, sourcefile_proto, opt, "cc") end) - on_buildcmd_file(function (target, batchcmds, sourcefile_proto, opt) - import("proto").build_c_cmd(target, batchcmds, sourcefile_proto, opt, "cc") - end) before_build_files(function (target, batchjobs, sourcebatch, opt) import("proto").build_sourcefiles_proto(target, batchjobs, sourcebatch, opt, "cc") end, {batch = true}) - on_build_files(function (target, batchjobs, sourcebatch, opt) - import("proto").build_compiled_sourcefiles_proto(target, batchjobs, sourcebatch, opt, "cc") - end, {batch = true}) - - |
