RedPanda-CPP/addon/compiler_hint/debian.tl

247 lines
8.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

global function apiVersion(): ApiVersion
return {
kind = "compiler_hint",
major = 0,
minor = 1,
}
end
local nameMap: {string:{string:string}} = {
systemGcc = {
en_US = "System GCC",
pt_BR = "GCC do sistema",
zh_CN = "系统 GCC",
zh_TW = "系統 GCC",
},
systemClang = {
en_US = "System Clang",
pt_BR = "Clang do sistema",
zh_CN = "系统 Clang",
zh_TW = "系統 Clang",
},
multilibGcc = {
en_US = "Multilib GCC",
pt_BR = "GCC multilib",
zh_CN = "Multilib GCC",
zh_TW = "Multilib GCC",
},
multilibClang = {
en_US = "Multilib Clang",
pt_BR = "Clang multilib",
zh_CN = "Multilib Clang",
zh_TW = "Multilib Clang",
},
mingwGcc = {
en_US = "MinGW GCC",
pt_BR = "GCC MinGW",
zh_CN = "MinGW GCC",
zh_TW = "MinGW GCC",
},
release = {
en_US = ", release",
pt_BR = ", lançamento",
zh_CN = ",发布",
zh_TW = ",發佈",
},
debug = {
en_US = ", debug",
pt_BR = ", depuração",
zh_CN = ",调试",
zh_TW = ",偵錯",
},
debugWithAsan = {
en_US = ", debug with ASan",
pt_BR = ", depuração com ASan",
zh_CN = "ASan 调试",
zh_TW = "ASan 偵錯",
},
}
local function mergeCompilerSet(compilerSet: CompilerHint.CompilerSet, other: CompilerHint.CompilerSet)
local c = compilerSet as {string:any}
local o = other as {string:any}
for k, v in pairs(o) do
c[k] = v
end
end
local record Config
isMultilib: boolean | nil
isMingw: boolean | nil
isClang: boolean | nil
customCompileParams: {string} | nil
customLinkParams: {string} | nil
triplet: string | nil
end
local function generateConfig(
name: string, lang: string,
cCompiler: string, cxxCompiler: string,
config: Config
): CompilerHint.CompilerSet, CompilerHint.CompilerSet, CompilerHint.CompilerSet
local commonOptions: CompilerHint.CompilerSet = {
cCompiler = cCompiler,
cxxCompiler = cxxCompiler,
debugger = "/usr/bin/gdb",
debugServer = "/usr/bin/gdbserver",
make = "/usr/bin/make",
compilerType = config.isClang and "Clang" or "GCC_UTF8",
preprocessingSuffix = ".i",
compilationProperSuffix = ".s",
assemblingSuffix = ".o",
executableSuffix = config.isMingw and ".exe" or "",
compilationStage = 3,
ccCmdOptUsePipe = "on",
ccCmdOptWarningAll = "on",
ccCmdOptWarningExtra = "on",
ccCmdOptCheckIsoConformance = "on",
binDirs = {"/usr/bin"},
}
if config.isMultilib then
commonOptions.ccCmdOptPointerSize = "32"
end
if config.isMingw then
commonOptions.resourceCompiler = "/usr/bin/" .. config.triplet .. "-windres"
end
if config.customCompileParams then
commonOptions.customCompileParams = config.customCompileParams
end
if config.customLinkParams then
commonOptions.customLinkParams = config.customLinkParams
end
local release = {
name = name .. (nameMap.release[lang] or nameMap.release.en_US),
staticLink = true,
linkCmdOptStripExe = "on",
ccCmdOptOptimize = "2",
}
local debug_ = {
name = name .. (nameMap.debug[lang] or nameMap.debug.en_US),
ccCmdOptDebugInfo = "on",
}
local debugWithAsan = {
name = name .. (nameMap.debugWithAsan[lang] or nameMap.debugWithAsan.en_US),
ccCmdOptDebugInfo = "on",
ccCmdOptAddressSanitizer = "address",
}
mergeCompilerSet(release, commonOptions)
mergeCompilerSet(debug_, commonOptions)
mergeCompilerSet(debugWithAsan, commonOptions)
return release, debug_, debugWithAsan
end
global function main(): CompilerHint
local arch = C_System.osArch()
local libexecDir = C_System.appLibexecDir()
local lang = C_Desktop.language()
local compilerList = {}
do
local release, debug_, debugWithAsan = generateConfig(
nameMap.systemGcc[lang] or nameMap.systemGcc.en_US, lang,
"/usr/bin/gcc", "/usr/bin/g++",
{}
)
table.insert(compilerList, release)
table.insert(compilerList, debug_)
table.insert(compilerList, debugWithAsan)
end
if C_FileSystem.isExecutable("/usr/bin/clang") then
local release, debug_, debugWithAsan = generateConfig(
nameMap.systemClang[lang] or nameMap.systemClang.en_US, lang,
"/usr/bin/clang", "/usr/bin/clang++",
{isClang = true}
)
table.insert(compilerList, release)
table.insert(compilerList, debug_)
table.insert(compilerList, debugWithAsan)
end
-- TODO: better to check 32-bit libstdc++.a (lib32stdc++-dev), but its path is not fixed
if arch == "x86_64" and C_FileSystem.exists("/usr/lib32/libc.a") then
do
local release, debug_, debugWithAsan = generateConfig(
nameMap.multilibGcc[lang] or nameMap.multilibGcc.en_US, lang,
"/usr/bin/gcc", "/usr/bin/g++",
{isMultilib = true}
)
table.insert(compilerList, release)
table.insert(compilerList, debug_)
table.insert(compilerList, debugWithAsan)
end
if C_FileSystem.isExecutable("/usr/bin/clang") then
local release, debug_, debugWithAsan = generateConfig(
nameMap.multilibClang[lang] or nameMap.multilibClang.en_US, lang,
"/usr/bin/clang", "/usr/bin/clang++",
{isClang = true, isMultilib = true}
)
table.insert(compilerList, release)
table.insert(compilerList, debug_)
table.insert(compilerList, debugWithAsan)
end
end
-- with wine or WSL init registered in binfmt_misc, Windows binaries can run seamlessly
if (
arch == "x86_64" and (
C_FileSystem.exists("/proc/sys/fs/binfmt_misc/DOSWin") or
C_FileSystem.exists("/proc/sys/fs/binfmt_misc/WSLInterop")
)
) then
if C_FileSystem.isExecutable("/usr/bin/x86_64-w64-mingw32-gcc") then
local extraObjects = {
utf8init = libexecDir .. "/x86_64-w64-mingw32/utf8init.o",
utf8manifest = libexecDir .. "/x86_64-w64-mingw32/utf8manifest.o",
}
do
local release, _, _ = generateConfig(
(nameMap.mingwGcc[lang] or nameMap.mingwGcc.en_US) .. " x86_64", lang,
"/usr/bin/x86_64-w64-mingw32-gcc", "/usr/bin/x86_64-w64-mingw32-g++",
{
isMingw = true,
triplet = "x86_64-w64-mingw32",
customLinkParams = {extraObjects.utf8init, extraObjects.utf8manifest},
}
)
table.insert(compilerList, release)
end
end
if C_FileSystem.isExecutable("/usr/bin/i686-w64-mingw32-gcc") then
local extraObjects = {
utf8init = libexecDir .. "/i686-w64-mingw32/utf8init.o",
utf8manifest = libexecDir .. "/i686-w64-mingw32/utf8manifest.o",
}
do
local release, _, _ = generateConfig(
(nameMap.mingwGcc[lang] or nameMap.mingwGcc.en_US) .. " i686", lang,
"/usr/bin/i686-w64-mingw32-gcc", "/usr/bin/i686-w64-mingw32-g++",
{
isMingw = true,
triplet = "i686-w64-mingw32",
customLinkParams = {extraObjects.utf8init, extraObjects.utf8manifest},
}
)
table.insert(compilerList, release)
end
end
end
local result = {
compilerList = compilerList,
noSearch = {
"/usr/bin",
"/usr/lib/ccache",
},
preferCompiler = 3, -- System GCC Debug with ASan
}
return result
end