[*] 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" hack = "cp -rf"
end 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 end
local function gnuCoreUtilsMkdirRecursive(dir) local function gnuCoreUtilsMkdirRecursive(dir)
@ -63,32 +65,37 @@ local function addUserDestCopy(name, type, config, platformName, arch, dir, proj
local ext = (platform.exts or {})[type] or "" 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 if (platform.devChainCoreUtils) then
gnuCoreUtilsMkdirRecursive(dir) -- TODO: why was this never executed until now?
os.execute(gnuCoreUtilsMkdirRecursive(dir))
end end
if (platform.devChainRequiresElfStrip and if (platform.devChainRequiresElfStrip and
platform.devChainSupportsElfStrip and platform.devChainSupportsElfStrip) then
config ~= Aurora.Settings.sNameOfDebug) then
local debugSymbolPath = normalizeCpyPath(Aurora.Settings.sAbsSymbols) .. "/" .. name .. ".dwarf" -- 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 .. "\"") 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 if (not Aurora.Settings.bUseAuBuildHooks) then
return return
end 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 if (platform.forcePortableLibc and not os.getenv("AURORA_LINK_NOT_PORTABLE")) then
local platformSuffix = "System." .. platform.outputName .. "." .. arch local platformSuffix = "System." .. platform.outputName .. "." .. arch
postbuildcommands("patchelf --replace-needed libm.so.6 libm." .. platformSuffix .. ".so \"" .. outputPath .. "\"") local isExec = type == "WindowedApp" or type == "ConsoleApp"
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 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 .. "\"") 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 end
postbuildcommands("cp -f /lib64/ld-linux-x86-64.so.2 \"" .. dir .. "/ld-Aurora.System.Linux.x86_64.so\"") postbuildcommands("cp -f /lib64/ld-linux-x86-64.so.2 \"" .. dir .. "/ld-Aurora.System.Linux.x86_64.so\"")
@ -96,8 +103,9 @@ local function addUserDestCopy(name, type, config, platformName, arch, dir, proj
postbuildcommands("cp -f /lib64/libm.so.6 \"" .. dir .. "/libm." .. 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/libgcc_s.so.1 \"" .. dir .. "/libgcc." .. platformSuffix .. ".so\"")
else else
if (projectType == "WindowedApp" or projectType == "ConsoleApp") then if (isExec) then
postbuildcommands("patchelf --set-interpreter \"ld-Aurora.System.Linux.x86_32.so\" \"" .. file .. "\"") 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 end
postbuildcommands("cp -f /lib/ld-linux.so.2 \"" .. dir .. "/ld-Aurora.System.Linux.x86_32.so\"") postbuildcommands("cp -f /lib/ld-linux.so.2 \"" .. dir .. "/ld-Aurora.System.Linux.x86_32.so\"")
@ -106,12 +114,6 @@ local function addUserDestCopy(name, type, config, platformName, arch, dir, proj
postbuildcommands("cp -f /lib/libgcc_s.so.1 \"" .. dir .. "/libgcc." .. platformSuffix .. ".so\"") postbuildcommands("cp -f /lib/libgcc_s.so.1 \"" .. dir .. "/libgcc." .. platformSuffix .. ".so\"")
end 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 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 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 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
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 function addDest(name, projectType, dest)
local lookup = {} local lookup = {}
local append = "" local append = ""
@ -207,6 +250,22 @@ local function postBuildCommands(name, type, config, platformName, arch)
debugEx = ".dwarf" debugEx = ".dwarf"
debugSymbolPath = normalizeCpyPath(Aurora.Settings.sAbsSymbols) .. "/" .. name .. ".dwarf" debugSymbolPath = normalizeCpyPath(Aurora.Settings.sAbsSymbols) .. "/" .. name .. ".dwarf"
postbuildcommands("objcopy --only-keep-debug \"" .. compilerDirectOutput .. "\" \"" .. debugSymbolPath .. "\"") 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 elseif (isWin) then
debugEx = ".pdb" debugEx = ".pdb"
debugSymbolPath = normalizeCpyPath(Aurora.Settings.sAbsSymbols) .. "/" .. name .. ".pdb" debugSymbolPath = normalizeCpyPath(Aurora.Settings.sAbsSymbols) .. "/" .. name .. ".pdb"