From 072ec58f2abab6fc80c70b850252d1430a5b0e4b Mon Sep 17 00:00:00 2001 From: J Reece Wilson Date: Fri, 28 Jun 2024 11:37:59 +0100 Subject: [PATCH] [+] More portable Linux builds --- Core/BuildHooks/BuildHooks.lua | 65 ++++++++++++++++++++++++++++++++-- Core/Target/platform.lua | 1 + 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/Core/BuildHooks/BuildHooks.lua b/Core/BuildHooks/BuildHooks.lua index ba65b88..d60090a 100644 --- a/Core/BuildHooks/BuildHooks.lua +++ b/Core/BuildHooks/BuildHooks.lua @@ -52,7 +52,7 @@ local function isNoLinkType(projectType) return projectType == "StaticLib" or isUtils(projectType) end -local function addUserDestCopy(name, type, config, platformName, arch, dir) +local function addUserDestCopy(name, type, config, platformName, arch, dir, projectType) local isWin = platformName == "win32" local debugSymbolPath = nil @@ -74,9 +74,68 @@ local function addUserDestCopy(name, type, config, platformName, arch, dir) config ~= Aurora.Settings.sNameOfDebug) then local debugSymbolPath = normalizeCpyPath(Aurora.Settings.sAbsSymbols) .. "/" .. name .. ".dwarf" postbuildcommands("objcopy --strip-debug --strip-unneeded \"" .. file .. "\" \"" .. outputPath .. "\"") - if (Aurora.Settings.bUseAuBuildHooks and config ~= Aurora.Settings.sNameOfShip) then + 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 .. "\"") + + if (arch == "x86_64" or arch == "ARM64" or arch == "aarch64" or arch == "mips64") then + if (projectType == "WindowedApp" or projectType == "ConsoleApp") then + postbuildcommands("patchelf --set-interpreter \"ld-Aurora.System.Linux.x86_64.so\" \"" .. outputPath .. "\"") + 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\"") + else + if (projectType == "WindowedApp" or projectType == "ConsoleApp") then + postbuildcommands("patchelf --set-interpreter \"ld-Aurora.System.Linux.x86_32.so\" \"" .. file .. "\"") + 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\"") + 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\"") + postbuildcommands("patchelf --replace-needed libgcc_s.so.1 libgcc." .. platformSuffix .. ".so \"" .. dir .. "/liblzma.so.6\"") + end + end else postbuildcommands(copy) end @@ -104,7 +163,7 @@ local function addDest(name, projectType, dest) end auFilterForConfigPlatforms(function(config, platform, arch) - addUserDestCopy(name, projectType, config, platform, arch, lookup[config] .. append) + addUserDestCopy(name, projectType, config, platform, arch, lookup[config] .. append, projectType) end) end diff --git a/Core/Target/platform.lua b/Core/Target/platform.lua index d9f48e5..7dd80b2 100644 --- a/Core/Target/platform.lua +++ b/Core/Target/platform.lua @@ -31,6 +31,7 @@ local platforms = { devChainSupportsElfStrip = true, devChainCoreUtils = true, elfSupportsRPath = true, + forcePortableLibc = true, exts = { SharedLib = ".so", StaticLib = ".a"