[*] 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

@ -33,7 +33,9 @@ local function formatCpy(name, type, dir, ex, iswin, config, platformName, arch,
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)
@ -63,55 +65,55 @@ 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\"")
@ -141,6 +143,47 @@ 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 = ""
@ -207,6 +250,22 @@ 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"