diff --git a/src/installer/managed/Microsoft.NET.HostModel/Bundle/TargetInfo.cs b/src/installer/managed/Microsoft.NET.HostModel/Bundle/TargetInfo.cs index 87c644272379e9..b87911ef8dd582 100644 --- a/src/installer/managed/Microsoft.NET.HostModel/Bundle/TargetInfo.cs +++ b/src/installer/managed/Microsoft.NET.HostModel/Bundle/TargetInfo.cs @@ -62,6 +62,12 @@ public TargetInfo(OSPlatform? os, Architecture? arch, Version targetFrameworkVer // This is only necessary for R2R assemblies, but we do it for all assemblies for simplicity. AssemblyAlignment = 4096; } + else if (Arch == Architecture.LoongArch64) + { + // We align assemblies in the bundle at 16K so that we can use mmap on Unix without changing the page alignment of LOONGARCH64 R2R code. + // This is only necessary for R2R assemblies, but we do it for all assemblies for simplicity. + AssemblyAlignment = 16384; + } else if (Arch == Architecture.Arm64) { // We align assemblies in the bundle at 4K so that we can use mmap on Unix without changing the page alignment of ARM64 R2R code. @@ -95,10 +101,11 @@ public override string ToString() return $"OS: {os} Arch: {arch} FrameworkVersion: {FrameworkVersion}"; } - private static readonly OSPlatform s_freebsdOSPlatform = OSPlatform.Create("FREEBSD"); - - private static OSPlatform HostOS => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? OSPlatform.Linux : - RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OSPlatform.OSX : RuntimeInformation.IsOSPlatform(s_freebsdOSPlatform) ? s_freebsdOSPlatform : OSPlatform.Windows; + private static OSPlatform? _hostOS; + private static OSPlatform HostOS => _hostOS ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? OSPlatform.Linux : + RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OSPlatform.OSX : + RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD) ? OSPlatform.FreeBSD : + RuntimeInformation.IsOSPlatform(OSPlatform.Illumos) ? OSPlatform.Illumos : OSPlatform.Windows; public bool IsOSX => OS.Equals(OSPlatform.OSX); public bool IsWindows => OS.Equals(OSPlatform.Windows); @@ -119,4 +126,22 @@ public bool ShouldExclude(string relativePath) => private string HostFxr => IsWindows ? "hostfxr.dll" : IsOSX ? "libhostfxr.dylib" : "libhostfxr.so"; private string HostPolicy => IsWindows ? "hostpolicy.dll" : IsOSX ? "libhostpolicy.dylib" : "libhostpolicy.so"; } + + file static class PlatformExtensions + { + extension(OSPlatform) + { +#if NETFRAMEWORK + public static OSPlatform FreeBSD => OSPlatform.Create("FREEBSD"); +#endif + public static OSPlatform Illumos => OSPlatform.Create("ILLUMOS"); + } + +#if NETFRAMEWORK + extension(Architecture) + { + public static Architecture LoongArch64 => (Architecture)6; + } +#endif + } } diff --git a/src/installer/tests/Assets/Projects/HelloWorld/SelfContained.csproj b/src/installer/tests/Assets/Projects/HelloWorld/SelfContained.csproj index d4197da0304bef..18c2731efa7413 100644 --- a/src/installer/tests/Assets/Projects/HelloWorld/SelfContained.csproj +++ b/src/installer/tests/Assets/Projects/HelloWorld/SelfContained.csproj @@ -9,7 +9,7 @@ <_SupportedPlatform Condition="'$(TargetsLinux)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetsWindows)' == 'true'">true - <_SupportedArchitecture Condition="'$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'arm' or'$(TargetArchitecture)' == 'arm64'">true + <_SupportedArchitecture Condition="'$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'arm' or '$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'loongarch64'">true $(OutputRID) diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/Bundle/BundlerConsistencyTests.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/Bundle/BundlerConsistencyTests.cs index b3ac86a8312a80..cb9d3ca634d62d 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/Bundle/BundlerConsistencyTests.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/Bundle/BundlerConsistencyTests.cs @@ -309,7 +309,7 @@ public void AssemblyAlignment() Bundler bundler = CreateBundlerInstance(); bundler.GenerateBundle(fileSpecs); - var alignment = OperatingSystem.IsLinux() && RuntimeInformation.OSArchitecture == Architecture.Arm64 ? 4096 : 16; + var alignment = OperatingSystem.IsLinux() && RuntimeInformation.OSArchitecture == Architecture.Arm64 ? 4096 : (OperatingSystem.IsLinux() && RuntimeInformation.OSArchitecture == Architecture.LoongArch64 ? 16384 : 16); bundler.BundleManifest.Files.ForEach(file => Assert.True((file.Type != FileType.Assembly) || (file.Offset % alignment == 0))); }