[+] Protobuf support

This commit is contained in:
Reece Wilson 2022-03-06 15:17:50 +00:00
parent ad3a926476
commit 224618d26d
10 changed files with 336 additions and 3 deletions

6
.gitignore vendored
View File

@ -1,3 +1,9 @@
# Compilers/platform specific binaries
Win32/*
bin/*
# Aurora's general purpose JS/TS/C/C++/Go vs/vscode/intellij/codelite gitignore reference # Aurora's general purpose JS/TS/C/C++/Go vs/vscode/intellij/codelite gitignore reference
# Almost usable for Java and Qt # Almost usable for Java and Qt

View File

@ -124,7 +124,9 @@ local addBuildCommand = function(when, scriptType, path, cwdRelToProject, args)
sRelWd = Aurora.Settings.sRelWd, sRelWd = Aurora.Settings.sRelWd,
sRelSymbols = Aurora.Settings.sRelSymbols, sRelSymbols = Aurora.Settings.sRelSymbols,
sRelLinkLibs = Aurora.Settings.sRelLinkLibs, sRelLinkLibs = Aurora.Settings.sRelLinkLibs,
sRelCompilerWd = Aurora.Settings.sRelCompilerWd sRelCompilerWd = Aurora.Settings.sRelCompilerWd,
sRelWin32 = Aurora.Settings.sRelWin32,
sRelUnixBins = Aurora.Settings.sRelUnixBins,
} }
command = command .. " --settings=" .. base64.encode(json.encode(settings)) command = command .. " --settings=" .. base64.encode(json.encode(settings))

View File

@ -9,6 +9,7 @@ end
local function escapeBinaryPath(bin) local function escapeBinaryPath(bin)
bin = path.translate(bin, path.getDefaultSeparator()) bin = path.translate(bin, path.getDefaultSeparator())
bin = os.realpath(bin)
if (os.host() == "windows") then if (os.host() == "windows") then
return "\"" .. bin .. "\"" return "\"" .. bin .. "\""

View File

@ -307,6 +307,10 @@ local function auBlockProjectKeyResourceScript(processor, value, map, tasks)
end, processor) end, processor)
end end
local function auBlockProjectKeyProtobuf(processor, value)
__pushFilter(value, "value", auProtobufFiles, processor, true)
end
local function auBlockProjectKeySoftDepends(processor, value) local function auBlockProjectKeySoftDepends(processor, value)
__pushFilter(value, "value", function(obj) __pushFilter(value, "value", function(obj)
handleDepends(processor, obj, true) handleDepends(processor, obj, true)
@ -384,7 +388,8 @@ auProjectBlockHandlers =
events = auBlockProjectKeyBuildEvent, events = auBlockProjectKeyBuildEvent,
actions = auBlockProjectKeyBuildAction, actions = auBlockProjectKeyBuildAction,
features = auBlockKeyFeature, features = auBlockKeyFeature,
resourceScript = auBlockProjectKeyResourceScript resourceScript = auBlockProjectKeyResourceScript,
protobuf = auBlockProjectKeyProtobuf
} }
auProjectBlockHandlers["soft-depends"] = auBlockProjectKeySoftDepends auProjectBlockHandlers["soft-depends"] = auBlockProjectKeySoftDepends
@ -413,7 +418,7 @@ auProjectRefHandlers["depends"] = auBlockProjectRefKeyDepends
"impInclude", "implInclude", "impIncludes", "implIncludes", "clangIgnore", "impInclude", "implInclude", "impIncludes", "implIncludes", "clangIgnore",
"msvcIgnore", "excludes", "depends", "require", "msvcIgnore", "excludes", "depends", "require",
"eval", "lua", "events", "actions", "staticImpDefines", "features", "eval", "lua", "events", "actions", "staticImpDefines", "features",
"links", "soft-depends", "resourceScript" "links", "soft-depends", "resourceScript", "protobuf"
} }
local kReferenceTasks = {"eval", "includes", "include", "includes"} --, "features"} local kReferenceTasks = {"eval", "includes", "include", "includes"} --, "features"}

View File

@ -0,0 +1,34 @@
local function addProtobufFiles(files)
local projName = auGetCurrentProject()
local proj = auGetCurrentProjectMeta()
local basePath = Aurora.Settings.sAbsRoot
if (proj and proj.path) then
basePath = proj.path
end
local baseProto = path.join(Aurora.Settings.sAbsCompilerWd, "ProtobufTemp")
local targetBase = nil
if (projName) then
targetBase = path.join(Aurora.Settings.sAbsCompilerWd, "ProtobufTemp", projName)
else
targetBase = path.join(Aurora.Settings.sAbsCompilerWd, "ProtobufTemp")
end
os.mkdir(baseProto)
os.mkdir(targetBase)
local compiledFiles = auMap(files, function(file)
local rel = path.getrelative(basePath, file)
return path.join(targetBase, rel:sub(1, #rel - 6)) .. ".pb.cc"
end)
includedirs(targetBase)
_G.files(compiledFiles)
auAddResource(files, {targetBase = targetBase, basePath = basePath}, path.join(Aurora.Settings.sAbsScripts, "Core", "Protobuf", "run.lua"))
end
return addProtobufFiles

38
Core/Protobuf/run.lua Normal file
View File

@ -0,0 +1,38 @@
print("Compiling protobuf files...")
print("Changed: ", json.encode_pretty(auResourceCompiler.changedFiles))
print("Unchanged: ", json.encode_pretty(auResourceCompiler.unchangedFiles))
if (#auResourceCompiler.changedFiles == 0) then return end
local function escapeBinaryPath(bin)
bin = path.translate(bin, path.getDefaultSeparator())
bin = os.realpath(bin)
if (os.host() == "windows") then
return "\"" .. bin .. "\""
end
return bin:gsub(" ", "\\ ")
end
local compiler = nil
if (os.host() == "windows") then
compiler = path.join(Aurora.Settings.sAbsWin32, "protoc.exe")
elseif (os.isfile("protoc")) then
compiler = "protoc"
else
compiler = path.join(Aurora.Settings.sRelUnixBins, "protoc")
end
compiler = escapeBinaryPath(compiler)
local cmd = compiler
cmd = cmd .. " --cpp_out=\"" .. auResourceCompiler.arguments.targetBase .. "\""
cmd = cmd .. " --proto_path=\"" .. auResourceCompiler.arguments.basePath .. "\""
auForEach(auResourceCompiler.changedFiles, function(file)
cmd = cmd .. " \"" .. file .. "\""
end)
resourceRunAndExit(cmd)

View File

@ -36,4 +36,20 @@ auResourceCompiler = {
arguments = auBuild.args.ext arguments = auBuild.args.ext
} }
function resourceExit(exitCode)
if (not exitCode) then
os.remove(cachePath)
end
os.exit(exitCode)
end
function resourceRunAndExit(cmd)
if (os.host() == "windows") then
resourceExit(os.execute("call " .. cmd))
else
resourceExit(os.execute(cmd))
end
end
auRequireAbs(auBuild.args.script) auRequireAbs(auBuild.args.script)

View File

@ -3,6 +3,7 @@ local buildAction = auRequire("Core/Actions")
local target = auRequire("Core/Target") local target = auRequire("Core/Target")
local main = auRequire("Core/Main") local main = auRequire("Core/Main")
local resourceCompiler = auRequire("Core/ResourceCompiler") local resourceCompiler = auRequire("Core/ResourceCompiler")
local protobuf = auRequire("Core/Protobuf")
-- executes inline under iprocessor::process -- executes inline under iprocessor::process
function auAddBuildAction(...) function auAddBuildAction(...)
@ -155,3 +156,7 @@ end
function auAddResource(...) function auAddResource(...)
resourceCompiler(...) resourceCompiler(...)
end end
function auProtobufFiles(files)
protobuf(files)
end

View File

@ -19,3 +19,11 @@ function table.copy(t)
--setmetatable(u, getmetatable(t)) --setmetatable(u, getmetatable(t))
return u return u
end end
function auMap(array, func)
local tbl = {}
auForEach(array, function(value)
table.insert(tbl, func(value))
end)
return tbl
end

218
aurora.gitignore Normal file
View File

@ -0,0 +1,218 @@
# Aurora's general purpose JS/TS/C/C++/Go vs/vscode/intellij/codelite gitignore reference
# Almost usable for Java and Qt
# Aurora build configuration
Build_CompilerWorkingDirectory/*
Build_Developers/*
Build_Ship/*
Build_Internal/*
Build_Develop/*
Build_Stage/*
Build_Ship/*
Build_Workspace/*
Build_Symbols/*
Build_Link/*
Build/Developers/*
Build/Ship/*
Build/Develop/*
Build/Stage/*
Build/Ship/*
Build/Workspace/*
Build/Symbols/*
Build/Link/*
# License Headers VS extension
*.licenseheader
# Binaries / object files
*.dll
*.exe
*.obj
*.so
*.so.*
*.la
*.lai
*.pdb
*.idb
*.exe~
*.obj
*.dynlib
*.dylib
*.lib
*.d
*.o
*.a
*.la
*.slo
*.lo
*.out
# go unit test
*.test
# Autogenerated project files
compile_flags.txt
*.mk
*.project
*cmake
Makefile
*.vcxproj
*.xcodeproj
# IDE trash
.vscode
.vs
/*.gcno
.intellij
.clion
*.vcxproj.filters
*.vcxproj.user
*.tlog
# OSX
.DS_Store
.AppleDouble
.LSOverride
xcuserdata/
# Win32
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
*.lnk
# Linux is trash and cant hotswap like NT
.nfs*
.fuse_hidden*
# Ninja
.ninja_deps
.ninja_log
# PID locks
*.pid
*.pid.lock
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# JetBrains
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-*/
# Android Studio
.idea/caches/build_file_checksums.ser
# why would we ever ship this dir?
.idea/caches/*
# NodeJS
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# node-waf configuration
.lock-wscript
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# VS Code Extensions
.vscode-test
# Qt unit tests
target_wrapper.*
# QtCreator
*.autosave
# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*
# QtCreator CMake
CMakeLists.txt.user*
# QtCreator 4.8< compilation database
compile_commands.json
# QtCreator local machine specific files for imported projects
*creator.user*
*_qmlcache.qrc
# QT cache and user files
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
# Java trash
hs_err_pid*
.gradle
gradle-app.setting
!gradle-wrapper.jar
.gradletasknamecache
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar