summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-08-06 00:41:09 +0800
committerruki <[email protected]>2024-08-06 00:41:09 +0800
commit76fee8962bf4f3e1a3d4d9742eb1b511fd6925cc (patch)
treed8eae9219c143d4d626dd9963a5bf2db09173dd7
parentfd093c16b808a63dd9e1fd718977b5cb49dd8fdc (diff)
fix protobuf objectfiles #5426
-rw-r--r--xmake/rules/protobuf/proto.lua22
-rw-r--r--xmake/rules/protobuf/xmake.lua4
2 files changed, 16 insertions, 10 deletions
diff --git a/xmake/rules/protobuf/proto.lua b/xmake/rules/protobuf/proto.lua
index 91dc4c727..00215ac10 100644
--- a/xmake/rules/protobuf/proto.lua
+++ b/xmake/rules/protobuf/proto.lua
@@ -80,11 +80,13 @@ function load(target, sourcekind)
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")
@@ -93,6 +95,17 @@ function load(target, sourcekind)
-- 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)
+ end
end
function buildcmd_pfiles(target, batchcmds, sourcefile_proto, opt, sourcekind)
@@ -194,17 +207,11 @@ function buildcmd_cxfiles(target, batchcmds, sourcefile_proto, opt, sourcekind)
sourcefile_cx_grpc = target:autogenfile(sourcefile_proto, {rootdir = rootdir, filename = filename_grpc})
end
- -- add includedirs
- target:add("includedirs", sourcefile_dir, {public = public})
-
- -- add objectfile
+ -- get 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.$(mode) %s", sourcefile_cx)
@@ -225,7 +232,6 @@ function buildcmd_cxfiles(target, batchcmds, sourcefile_proto, opt, sourcekind)
end
function build_cxfile_objects(target, batchjobs, opt, sourcekind)
- -- do build
local sourcebatch_cx = {
rulename = (sourcekind == "cxx" and "c++" or "c").. ".build",
sourcekind = sourcekind,
diff --git a/xmake/rules/protobuf/xmake.lua b/xmake/rules/protobuf/xmake.lua
index 0f1e8e445..119ff3d1f 100644
--- a/xmake/rules/protobuf/xmake.lua
+++ b/xmake/rules/protobuf/xmake.lua
@@ -22,7 +22,7 @@
rule("protobuf.cpp")
add_deps("c++")
set_extensions(".proto")
- on_load(function(target)
+ after_load(function(target)
import("proto").load(target, "cxx")
end)
-- generate build commands
@@ -41,7 +41,7 @@ rule("protobuf.cpp")
rule("protobuf.c")
add_deps("c++")
set_extensions(".proto")
- on_load(function(target)
+ after_load(function(target)
import("proto").load(target, "cc")
end)
before_buildcmd_file(function(target, batchcmds, sourcefile_proto, opt)