using System.IO; using System.Collections.Generic; using NiceIO.Sysroot; namespace UnityEditor.Il2Cpp { /// /// Sysroot package implementation for building Linux (x86_64) IL2CPP players. /// /// /// This class wires a sysroot payload (headers/libs) into IL2CPP's compile/link /// steps by advertising the target triple and locating the on-disk sysroot path. /// The payload itself is distributed via UPM under . /// public class SysrootLinuxX86_64 : SysrootPackage { /// /// The UPM package name that ships this sysroot payload. /// private string _packageName => "com.unity.sdk.linux-x86_64"; /// /// Human-readable package name as exposed to callers. /// public override string Name => _packageName; /// /// The OS this sysroot targets. /// /// Used for selection/routing in higher-level tooling. public override string TargetPlatform => "linux"; /// /// The CPU architecture this sysroot targets. /// /// Follows the the toolchain triple token (x86_64). public override string TargetArch => "x86_64"; /// /// Identifier for the concrete payload version that this package expects. /// /// /// CI typically substitutes this placeholder at pack/publish time so the package /// resolves a precise, immutable payload directory on disk. /// private string _payloadVersion => "2.35-134_7122795dd37e3872a95e34e6a9498cffaea142059e76c124b0e54b781e96f792-1"; /// /// Relative path (within the UPM cache) to the payload root for this platform/arch. /// private string _payloadDir; /// /// The Clang/LLVM target triple used for cross-compiling IL2CPP code against this sysroot. /// private string _target => "x86_64-unity-linux-gnu"; /// /// Cached install directory of the resolved payload. /// private NPath _sysrootInstallDir; /// /// Initializes the package and registers its payload so it can be resolved on disk. /// public SysrootLinuxX86_64() { _payloadDir = $"linux-x86_64/{_payloadVersion}"; RegisterPayload(_packageName, _payloadDir); _sysrootInstallDir = PayloadInstallDirectory(_payloadDir); } /// /// Gets the absolute path to the installed payload root directory. /// /// Absolute path to the payload root. public string PathToPayload() { return PayloadInstallDirectory(_payloadDir).ToString(); } /// /// Resolves the absolute path to the sysroot directory inside the installed payload. /// /// /// Looks for a child directory named exactly like the target triple (e.g., /// x86_64-unity-linux-gnu) and returns its sysroot subfolder. /// Returns null if the expected structure is not present. /// /// Absolute path to the sysroot directory, or null if not found. private string PathToSysroot() { var sdkPath = PathToPayload(); var sdkInfo = new DirectoryInfo(sdkPath); foreach (var target in sdkInfo.GetDirectories(_target)) { var sysrootPath = Path.Combine(sdkPath, target.Name, "sysroot"); if (Directory.Exists(sysrootPath)) { return sysrootPath.ToString(); } } return null; } /// /// Absolute path to the sysroot that IL2CPP should compile/link against (not applicable for this toolchain-only package). /// /// Absolute sysroot path, or null if the payload is missing/incomplete or a toolchain-only package. public override string GetSysrootPath() { return PathToSysroot(); } /// /// Absolute path to a toolchain payload (not applicable for this sysroot-only package). /// /// Absolute toolchain path, or null if the payload is missing/incomplete or a sysroot-only package. public override string GetToolchainPath() { return null; } /// /// Compiler flags that IL2CPP (Clang) must receive to target this sysroot. /// /// /// Primarily sets the target triple used for cross-compilation. /// Example result: -target x86_64-unity-linux-gnu. /// /// A space-separated string of compiler flags. public override string GetIl2CppCompilerFlags() { return $"-target {_target}"; } /// /// Linker flags that IL2CPP must receive to target this sysroot. /// /// /// Mirrors the compiler target so the linker resolves libraries and startup files /// from the correct sysroot. Example: -target x86_64-unity-linux-gnu. /// /// A space-separated string of linker flags. public override string GetIl2CppLinkerFlags() { return $"-target {_target}"; } } }