Skip to content

Commit

Permalink
fix protobuf objectfiles #5426
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Aug 5, 2024
1 parent fd093c1 commit 76fee89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 14 additions & 8 deletions xmake/rules/protobuf/proto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions xmake/rules/protobuf/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 76fee89

Please sign in to comment.