summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-09-10 22:45:55 +0800
committerruki <[email protected]>2024-09-10 22:45:55 +0800
commit9bb96d5156c7e1766d761589f927eb30d5229f84 (patch)
tree12e7d7e258d7d4528db3b7491ffb999d4218fb7f
parent13c9b7cca83101cdcdd48ae80cee816c800648a4 (diff)
fix protobuf
-rw-r--r--xmake/rules/protobuf/proto.lua64
1 files changed, 28 insertions, 36 deletions
diff --git a/xmake/rules/protobuf/proto.lua b/xmake/rules/protobuf/proto.lua
index 00215ac10..e5208709c 100644
--- a/xmake/rules/protobuf/proto.lua
+++ b/xmake/rules/protobuf/proto.lua
@@ -66,45 +66,37 @@ end
-- @see https://github.com/xmake-io/xmake/issues/2256
function load(target, sourcekind)
- -- get the first sourcefile
- local sourcefile_proto
local sourcebatch = target:sourcebatches()[sourcekind == "cxx" and "protobuf.cpp" or "protobuf.c"]
- if sourcebatch then
- sourcefile_proto = sourcebatch.sourcefiles[1]
- end
- if not sourcefile_proto then
- return
- end
-
- -- 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
- 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)
+ for _, sourcefile_proto in ipairs(sourcebatch.sourcefiles) do
+ 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
+ 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)
- -- add includedirs
- target:add("includedirs", sourcefile_dir, {public = public})
+ -- add includedirs
+ target:add("includedirs", sourcefile_dir, {public = public})
- -- add objectfile, @see https://github.com/xmake-io/xmake/issues/5426
- local objectfile_grpc
- local objectfile = target:objectfile(sourcefile_cx)
- table.insert(target:objectfiles(), objectfile)
- if grpc_cpp_plugin then
- local filename_grpc = path.basename(sourcefile_proto) .. ".grpc.pb.cc"
- local sourcefile_cx_grpc = target:autogenfile(sourcefile_proto, {rootdir = rootdir, filename = filename_grpc})
- objectfile_grpc = target:objectfile(sourcefile_cx_grpc)
- table.insert(target:objectfiles(), objectfile_grpc)
+ -- add objectfile, @see https://github.com/xmake-io/xmake/issues/5426
+ local objectfile_grpc
+ local objectfile = target:objectfile(sourcefile_cx)
+ table.insert(target:objectfiles(), objectfile)
+ if grpc_cpp_plugin then
+ local filename_grpc = path.basename(sourcefile_proto) .. ".grpc.pb.cc"
+ local sourcefile_cx_grpc = target:autogenfile(sourcefile_proto, {rootdir = rootdir, filename = filename_grpc})
+ objectfile_grpc = target:objectfile(sourcefile_cx_grpc)
+ table.insert(target:objectfiles(), objectfile_grpc)
+ end
end
end