[*] Rework 072ec58f2a '[+] More portable Linux builds'

This commit is contained in:
Reece Wilson 2024-06-29 14:37:41 +01:00
parent 072ec58f2a
commit f132d8980c

View File

@ -5,7 +5,7 @@ local function normalizeCpyPath(absPath)
end
-- file name, type, directory, extension, is windows, configuration, real name
local function formatCpy(name, type, dir, ex, iswin, config, platformName, arch, realName)
local function formatCpy(name, type, dir, ex, iswin, config, platformName, arch, realName)
local pathSuffix = "";
local hack2 = os.host() == "windows" and _ACTION == "gmake2"
@ -28,15 +28,17 @@ local function formatCpy(name, type, dir, ex, iswin, config, platformName, arch,
local outputTarget = string.format("%s/%s", dir, name)
local uglyBuildPath = string.format("%%{cfg.targetdir}/%s%s", name, ex)
local hack = "{COPY}"
if (hack2) then
hack = "cp -rf"
end
return string.format("%s \"%s\" \"%s%s", hack, uglyBuildPath, outputPath, pathSuffix), outputPath, uglyBuildPath
local nameAndExt = name .. ex
return string.format("%s \"%s\" \"%s%s", hack, uglyBuildPath, outputPath, pathSuffix), outputPath, uglyBuildPath, name
end
local function gnuCoreUtilsMkdirRecursive(dir)
local function gnuCoreUtilsMkdirRecursive(dir)
return string.format("mkdir -p \"%s\"", dir);
end
@ -63,73 +65,73 @@ local function addUserDestCopy(name, type, config, platformName, arch, dir, proj
local ext = (platform.exts or {})[type] or ""
local copy, outputPath, file = formatCpy(Aurora.Settings.sLibPrefix .. name, type, dir, ext, isWin, config, platformName, arch, name)
local copy, outputPath, file, fileName = formatCpy(Aurora.Settings.sLibPrefix .. name, type, dir, ext, isWin, config, platformName, arch, name)
if (platform.devChainCoreUtils) then
gnuCoreUtilsMkdirRecursive(dir)
-- TODO: why was this never executed until now?
os.execute(gnuCoreUtilsMkdirRecursive(dir))
end
if (platform.devChainRequiresElfStrip and
platform.devChainSupportsElfStrip and
config ~= Aurora.Settings.sNameOfDebug) then
local debugSymbolPath = normalizeCpyPath(Aurora.Settings.sAbsSymbols) .. "/" .. name .. ".dwarf"
platform.devChainSupportsElfStrip) then
-- never straight copy, just in case
-- id rather objcopy fail and leave us with no copy than have missed a symbol strip step
postbuildcommands("objcopy --strip-debug --strip-unneeded \"" .. file .. "\" \"" .. outputPath .. "\"")
if (config ~= Aurora.Settings.sNameOfShip) then
local debugSymbolPath = normalizeCpyPath(Aurora.Settings.sAbsSymbols) .. "/" .. name .. ".dwarf"
postbuildcommands("objcopy --add-gnu-debuglink=\"" .. debugSymbolPath .. "\" \"" .. outputPath .. "\"")
end
if (not Aurora.Settings.bUseAuBuildHooks) then
return
end
if (config ~= Aurora.Settings.sNameOfShip) then
postbuildcommands("objcopy --add-gnu-debuglink=\"" .. debugSymbolPath .. "\" \"" .. outputPath .. "\"")
end
if (platform.forcePortableLibc and not os.getenv("AURORA_LINK_NOT_PORTABLE")) then
local platformSuffix = "System." .. platform.outputName .. "." .. arch
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. platformSuffix .. ".so \"" .. outputPath .. "\"")
postbuildcommands("patchelf --replace-needed libc.so.6 libc." .. platformSuffix .. ".so \"" .. outputPath .. "\"")
postbuildcommands("patchelf --replace-needed libgcc_s.so.1 libgcc." .. platformSuffix .. ".so \"" .. outputPath .. "\"")
local isExec = type == "WindowedApp" or type == "ConsoleApp"
if (arch == "x86_64" or arch == "ARM64" or arch == "aarch64" or arch == "mips64") then
if (projectType == "WindowedApp" or projectType == "ConsoleApp") then
if (isExec) then
postbuildcommands("patchelf --set-interpreter \"ld-Aurora.System.Linux.x86_64.so\" \"" .. outputPath .. "\"")
io.writefile(outputPath .. ".exe", "#!/bin/bash\nchmod +x \"$(dirname \"$0\")/ld-Aurora.System.Linux.x86_64.so\"\nchmod +x \"$(dirname \"$0\")/".. fileName .. "\"\n\"$(dirname \"$0\")/ld-Aurora.System.Linux.x86_64.so\" \"$(dirname \"$0\")/".. fileName .. "\" $@")
end
postbuildcommands("cp -f /lib64/ld-linux-x86-64.so.2 \"" .. dir .. "/ld-Aurora.System.Linux.x86_64.so\"")
postbuildcommands("cp -f /lib64/libc.so.6 \"" .. dir .. "/libc." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib64/libm.so.6 \"" .. dir .. "/libm." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib64/libgcc_s.so.1 \"" .. dir .. "/libgcc." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib64/ld-linux-x86-64.so.2 \"" .. dir .. "/ld-Aurora.System.Linux.x86_64.so\"")
postbuildcommands("cp -f /lib64/libc.so.6 \"" .. dir .. "/libc." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib64/libm.so.6 \"" .. dir .. "/libm." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib64/libgcc_s.so.1 \"" .. dir .. "/libgcc." .. platformSuffix .. ".so\"")
else
if (projectType == "WindowedApp" or projectType == "ConsoleApp") then
postbuildcommands("patchelf --set-interpreter \"ld-Aurora.System.Linux.x86_32.so\" \"" .. file .. "\"")
if (isExec) then
postbuildcommands("patchelf --set-interpreter \"ld-Aurora.System.Linux.x86_32.so\" \"" .. outputPath .. "\"")
io.writefile(outputPath .. ".exe", "#!/bin/bash\nchmod +x \"$(dirname \"$0\")/ld-Aurora.System.Linux.x86_32.so\"\nchmod +x \"$(dirname \"$0\")/".. fileName .. "\"\n\"$(dirname \"$0\")/ld-Aurora.System.Linux.x86_32.so\" \"$(dirname \"$0\")/".. fileName .. "\" $@")
end
postbuildcommands("cp -f /lib/ld-linux.so.2 \"" .. dir .. "/ld-Aurora.System.Linux.x86_32.so\"")
postbuildcommands("cp -f /lib/libc.so.6 \"" .. dir .. "/libc." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib/libm.so.6 \"" .. dir .. "/libm." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib/libgcc_s.so.1 \"" .. dir .. "/libgcc." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib/ld-linux.so.2 \"" .. dir .. "/ld-Aurora.System.Linux.x86_32.so\"")
postbuildcommands("cp -f /lib/libc.so.6 \"" .. dir .. "/libc." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib/libm.so.6 \"" .. dir .. "/libm." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib/libgcc_s.so.1 \"" .. dir .. "/libgcc." .. platformSuffix .. ".so\"")
end
postbuildcommands("patchelf --replace-needed libc.so.6 libc." .. platformSuffix .. ".so \"" .. dir .. "/libm." .. platformSuffix .. ".so\"")
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. platformSuffix .. ".so \"" .. dir .. "/libm." .. platformSuffix .. ".so\"")
postbuildcommands("patchelf --replace-needed libc.so.6 libc." .. platformSuffix .. ".so \"" .. dir .. "/libgcc." .. platformSuffix .. ".so\"")
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. platformSuffix .. ".so \"" .. dir .. "/libgcc." .. platformSuffix .. ".so\"")
if (os.isfile(dir .. "/libunwind-x86_64.so.8")) then
postbuildcommands("patchelf --replace-needed libc.so.6 libc." .. "System.Linux.x86_64" .. ".so \"" .. dir .. "/libunwind-x86_64.so.8\"")
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. "System.Linux.x86_64" .. ".so \"" .. dir .. "/libunwind-x86_64.so.8\"")
postbuildcommands("patchelf --replace-needed libgcc_s.so.1 libgcc." .. "System.Linux.x86_64" .. ".so \"" .. dir .. "/libunwind-x86_64.so.8\"")
end
if (os.isfile(dir .. "/libunwind.so.8")) then
postbuildcommands("patchelf --replace-needed libc.so.6 libc." .. platformSuffix .. ".so \"" .. dir .. "/libunwind.so.8\"")
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. platformSuffix .. ".so \"" .. dir .. "/libunwind.so.8\"")
postbuildcommands("patchelf --replace-needed libgcc_s.so.1 libgcc." .. platformSuffix .. ".so \"" .. dir .. "/libunwind.so.8\"")
end
if (os.isfile(dir .. "/liblzma.so.5")) then
postbuildcommands("patchelf --replace-needed libc.so.6 libc." .. platformSuffix .. ".so \"" .. dir .. "/liblzma.so.5\"")
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. platformSuffix .. ".so \"" .. dir .. "/liblzma.so.5\"")
postbuildcommands("patchelf --replace-needed libgcc_s.so.1 libgcc." .. platformSuffix .. ".so \"" .. dir .. "/liblzma.so.5\"")
end
if (os.isfile(dir .. "/liblzma.so.6")) then
postbuildcommands("patchelf --replace-needed libc.so.6 libc." .. platformSuffix .. ".so \"" .. dir .. "/liblzma.so.6\"")
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. platformSuffix .. ".so \"" .. dir .. "/liblzma.so.6\"")
@ -141,10 +143,51 @@ local function addUserDestCopy(name, type, config, platformName, arch, dir, proj
end
end
local function patchPortableElf(name, type, config, platform, platformName, arch, dir)
local ext = (platform.exts or {})[type] or ""
if (not Aurora.Settings.bUseAuBuildHooks) then
return
end
if (not platform.forcePortableLibc) then
return
end
if (os.getenv("AURORA_LINK_NOT_PORTABLE")) then
return
end
local copy, outputPath, file, fileName = formatCpy(Aurora.Settings.sLibPrefix .. name, type, "%{cfg.targetdir}", ext, isWin, config, platformName, arch, name)
local platformSuffix = "System." .. platform.outputName .. "." .. arch
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. platformSuffix .. ".so \"" .. outputPath .. "\"")
postbuildcommands("patchelf --replace-needed libc.so.6 libc." .. platformSuffix .. ".so \"" .. outputPath .. "\"")
postbuildcommands("patchelf --replace-needed libgcc_s.so.1 libgcc." .. platformSuffix .. ".so \"" .. outputPath .. "\"")
if (arch == "x86_64" or arch == "ARM64" or arch == "aarch64" or arch == "mips64") then
postbuildcommands("cp -f /lib64/ld-linux-x86-64.so.2 \"" .. "%{cfg.targetdir}/ld-Aurora.System.Linux.x86_64.so\"")
postbuildcommands("cp -f /lib64/libc.so.6 \"" .. "%{cfg.targetdir}/libc." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib64/libm.so.6 \"" .. "%{cfg.targetdir}/libm." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib64/libgcc_s.so.1 \"" .. "%{cfg.targetdir}/libgcc." .. platformSuffix .. ".so\"")
else
postbuildcommands("cp -f /lib/ld-linux.so.2 \"" .. "%{cfg.targetdir}/ld-Aurora.System.Linux.x86_32.so\"")
postbuildcommands("cp -f /lib/libc.so.6 \"" .. "%{cfg.targetdir}/libc." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib/libm.so.6 \"" .. "%{cfg.targetdir}/libm." .. platformSuffix .. ".so\"")
postbuildcommands("cp -f /lib/libgcc_s.so.1 \"" .. "%{cfg.targetdir}/libgcc." .. platformSuffix .. ".so\"")
end
postbuildcommands("patchelf --replace-needed libc.so.6 libc." .. platformSuffix .. ".so \"%{cfg.targetdir}/libm." .. platformSuffix .. ".so\"")
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. platformSuffix .. ".so \"%{cfg.targetdir}/libm." .. platformSuffix .. ".so\"")
postbuildcommands("patchelf --replace-needed libc.so.6 libc." .. platformSuffix .. ".so \"%{cfg.targetdir}/libgcc." .. platformSuffix .. ".so\"")
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. platformSuffix .. ".so \"%{cfg.targetdir}/libgcc." .. platformSuffix .. ".so\"")
end
local function addDest(name, projectType, dest)
local lookup = {}
local append = ""
if (isNoLinkType(projectType)) then
return
end
@ -173,13 +216,13 @@ local function postBuildCommands(name, type, config, platformName, arch)
if (platformName == "win32") then
postbuildcommands(formatCpy(Aurora.Settings.sLibPrefix .. name, type, normalizeCpyPath(Aurora.Settings.sAbsSymbols), ".pdb", true, config, platformName, arch, name))
if (type == "SharedLib" or
if (type == "SharedLib" or
type == "StaticLib") then
postbuildcommands(formatCpy(Aurora.Settings.sLibPrefix .. name, type, normalizeCpyPath(Aurora.Settings.sAbsLinkLibs), ".lib", true, config, platformName, arch, name))
end
else
local ext = (Aurora.Platforms[platformName].exts[type] or "")
if (type == "SharedLib" or
if (type == "SharedLib" or
type == "StaticLib") then
local ext = (Aurora.Platforms[platformName].exts[type] or "")
local cmd = nil
@ -207,12 +250,28 @@ local function postBuildCommands(name, type, config, platformName, arch)
debugEx = ".dwarf"
debugSymbolPath = normalizeCpyPath(Aurora.Settings.sAbsSymbols) .. "/" .. name .. ".dwarf"
postbuildcommands("objcopy --only-keep-debug \"" .. compilerDirectOutput .. "\" \"" .. debugSymbolPath .. "\"")
if (type == "SharedLib" or
type == "StaticLib") then
postbuildcommands("objcopy --strip-debug --strip-unneeded \"" .. compilerDirectOutput .. "\"")
if (config ~= Aurora.Settings.sNameOfShip) then
postbuildcommands("objcopy --add-gnu-debuglink=\"" .. debugSymbolPath .. "\" \"" .. compilerDirectOutput .. "\"")
end
end
if (type == "SharedLib" or
type == "WindowedApp" or
type == "ConsoleApp") then
patchPortableElf(name, type, config, platform, platformName, arch)
end
elseif (isWin) then
debugEx = ".pdb"
debugSymbolPath = normalizeCpyPath(Aurora.Settings.sAbsSymbols) .. "/" .. name .. ".pdb"
end
if (debugSymbolPath and
if (debugSymbolPath and
config == Aurora.Settings.sNameOfShip) then
archiveShipPdb(debugSymbolPath, debugEx)
end