From f5ddd1d3d1be6b5ef363815207bb2ccabaf793cb Mon Sep 17 00:00:00 2001 From: Reece Date: Fri, 24 Jun 2022 20:12:03 +0100 Subject: [PATCH] [+] auRPC and grpc support --- Core/JSON/jsonProjectHandlers.lua | 8 +++++--- Core/Protobuf/Protobuf.lua | 26 ++++++++++++++++++++++++-- Core/Protobuf/run.lua | 20 ++++++++++++++++++++ Public/api.lua | 4 ++-- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Core/JSON/jsonProjectHandlers.lua b/Core/JSON/jsonProjectHandlers.lua index d00e7df..508ae6d 100644 --- a/Core/JSON/jsonProjectHandlers.lua +++ b/Core/JSON/jsonProjectHandlers.lua @@ -313,8 +313,10 @@ local function auBlockProjectKeyResourceScript(processor, value, map, tasks) end, processor) end -local function auBlockProjectKeyProtobuf(processor, value) - filterForKey(value, "files", auProtobufFiles, true) +local function auBlockProjectKeyProtobuf(processor, value, map, tasks, inc, resolve, object) + filterForKey(value, "files", function(value) + auProtobufFiles(value, {grpc = object.grpc, auRPC = object.auRPC}) + end, true) end local function auBlockProjectKeyVala(processor, value) @@ -521,7 +523,7 @@ __pRunTasks = function(processor, object, map, tasks, inc, resolve) if (not value) then return end - map[key](processor, value, map, tasks, inc, resolve) + map[key](processor, value, map, tasks, inc, resolve, object) end) end diff --git a/Core/Protobuf/Protobuf.lua b/Core/Protobuf/Protobuf.lua index 2d6348a..c5634fe 100644 --- a/Core/Protobuf/Protobuf.lua +++ b/Core/Protobuf/Protobuf.lua @@ -22,19 +22,41 @@ local function getPath(projName) return targetBase, basePath end -local function addProtobufFiles(files) +local function addProtobufFiles(files, extended) + local grpc = (extended or {}).grpc + local auRPC = (extended or {}).auRPC local targetBase, basePath = getPath(auGetCurrentProject()) files = os.matchfiles(files) + local compiledFiles = auMap(files, function(file) local rel = path.getrelative(basePath, file) return path.join(targetBase, rel:sub(1, #rel - 6)) .. ".pb.cc" end) + local grpcFiles = auMap(files, function(file) + local rel = path.getrelative(basePath, file) + return path.join(targetBase, rel:sub(1, #rel - 6)) .. ".grpc.pb.cc" + end) + + local auRpcFiles = auMap(files, function(file) + local rel = path.getrelative(basePath, file) + return path.join(targetBase, rel:sub(1, #rel - 6)) .. ".aurpc.pb.cc" + end) + includedirs(targetBase) + _G.files(compiledFiles) - auAddResource(files, {targetBase = targetBase, basePath = basePath}, path.join(Aurora.Settings.sAbsScripts, "Core", "Protobuf", "run.lua")) + if (grpc) then + _G.files(grpcFiles) + end + + if (auRPC) then + _G.files(auRpcFiles) + end + + auAddResource(files, {targetBase = targetBase, basePath = basePath, grpc = grpc, auRPC = auRPC}, path.join(Aurora.Settings.sAbsScripts, "Core", "Protobuf", "run.lua")) end local function includeProtobuf(projName) diff --git a/Core/Protobuf/run.lua b/Core/Protobuf/run.lua index 1dfd970..4ef9438 100644 --- a/Core/Protobuf/run.lua +++ b/Core/Protobuf/run.lua @@ -28,7 +28,27 @@ end compiler = escapeBinaryPath(compiler) local cmd = compiler + cmd = cmd .. " --cpp_out=\"" .. auResourceCompiler.arguments.targetBase .. "\"" + +if (auResourceCompiler.arguments.grpc) then + cmd = cmd .. " --grpc_out=\"" .. auResourceCompiler.arguments.targetBase .. "\"" + + if (os.host() == "windows") then + local plugin = os.realpath(path.join(Aurora.Settings.sAbsWin32, "grpc_cpp_plugin.exe")) + cmd = cmd .. " --plugin=protoc-gen-grpc=\"" .. plugin .."\"" + end +end + +if (auResourceCompiler.arguments.auRPC) then + cmd = cmd .. " --aurpc_out=\"" .. auResourceCompiler.arguments.targetBase .. "\"" + + if (os.host() == "windows") then + local plugin = os.realpath(path.join(Aurora.Settings.sAbsWin32, "aurpc_cpp_plugin.exe")) + cmd = cmd .. " --plugin=protoc-gen-aurpc=\"" .. plugin .."\"" + end +end + cmd = cmd .. " --proto_path=\"" .. auResourceCompiler.arguments.basePath .. "\"" auForEach(auResourceCompiler.changedFiles, function(file) diff --git a/Public/api.lua b/Public/api.lua index f1a3f98..ca55301 100644 --- a/Public/api.lua +++ b/Public/api.lua @@ -158,8 +158,8 @@ function auAddResource(...) resourceCompiler(...) end -function auProtobufFiles(files) - protobuf.addProtobufFiles(files) +function auProtobufFiles(files, extended) + protobuf.addProtobufFiles(files, extended) end function auProtobufIncludeProject(projectName)