From e9e733a403c39757745c2fea5c48f5c659fea8d8 Mon Sep 17 00:00:00 2001 From: Omair Majid Date: Fri, 26 Jul 2024 09:48:06 -0400 Subject: [PATCH] Make it possible to build/run tests on linux-arm64 I wanted to run the roslyn test suite on Linux on arm64. Building everything worked, but running tests would fail with errors like: Errors Microsoft.CodeAnalysis.CSharp.Emit.UnitTests_1 Could not find 'dotnet' host for the 'X64' architecture. You can resolve the problem by installing the 'X64' .NET. With the changes in this commit, I can build and run all tests using: $ ./eng/build.sh --restore --build --pack $ ./eng/build.sh --test I would, eventually, like to be able to run the tests on other platforms, including s390x and ppc64le. Hopefully that might help identify/fix issues like https://github.com/dotnet/roslyn/pull/74392 earlier. One thing I am not too happy about in this change is how many places need an explicit addition of "linux-arm64". That won't scale as we want to add more architectures. --- eng/Directory.Packages.props | 2 ++ eng/targets/ILAsm.targets | 9 ++++++++- eng/targets/ILDAsm.targets | 9 ++++++++- src/Compilers/Test/Core/Metadata/IlasmUtilities.cs | 14 +++++++++++++- src/Tools/BuildValidator/BuildValidator.csproj | 1 + src/Tools/BuildValidator/IldasmUtilities.cs | 3 ++- src/Tools/Source/RunTests/Options.cs | 2 +- src/Tools/Source/RunTests/RunTests.csproj | 2 +- 8 files changed, 36 insertions(+), 6 deletions(-) diff --git a/eng/Directory.Packages.props b/eng/Directory.Packages.props index b74d3474e8297..512cc36b8a7a3 100644 --- a/eng/Directory.Packages.props +++ b/eng/Directory.Packages.props @@ -290,9 +290,11 @@ + + diff --git a/eng/targets/ILAsm.targets b/eng/targets/ILAsm.targets index edc2368e0ebad..9fa6580b2ce56 100644 --- a/eng/targets/ILAsm.targets +++ b/eng/targets/ILAsm.targets @@ -12,6 +12,12 @@ false false + + PreserveNewest + runtimes + false + false + PreserveNewest runtimes @@ -26,7 +32,8 @@ + - \ No newline at end of file + diff --git a/eng/targets/ILDAsm.targets b/eng/targets/ILDAsm.targets index 9e94a720804b8..2992ece5a1d44 100644 --- a/eng/targets/ILDAsm.targets +++ b/eng/targets/ILDAsm.targets @@ -11,6 +11,12 @@ false false + + PreserveNewest + runtimes + false + false + PreserveNewest runtimes @@ -25,7 +31,8 @@ + - \ No newline at end of file + diff --git a/src/Compilers/Test/Core/Metadata/IlasmUtilities.cs b/src/Compilers/Test/Core/Metadata/IlasmUtilities.cs index c67ce4bf0e343..2886ff9336a3b 100644 --- a/src/Compilers/Test/Core/Metadata/IlasmUtilities.cs +++ b/src/Compilers/Test/Core/Metadata/IlasmUtilities.cs @@ -6,6 +6,7 @@ using System; using System.IO; +using System.Runtime.InteropServices; using Roslyn.Test.Utilities; using Roslyn.Utilities; using Xunit; @@ -22,6 +23,17 @@ public static DisposableFile CreateTempAssembly(string declarations, bool prepen return new DisposableFile(assemblyPath); } + private static string GetArchitecture() + { +#if NET8_0_OR_GREATER + return RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); +#else + return "x64"; +#endif + } + + public static readonly string Architecture = GetArchitecture(); + private static string GetIlasmPath() { if (ExecutionConditionUtil.IsWindowsDesktop) @@ -46,7 +58,7 @@ private static string GetIlasmPath() } else if (ExecutionConditionUtil.IsLinux) { - ridName = "linux-x64"; + ridName = $"linux-{GetArchitecture()}"; } else { diff --git a/src/Tools/BuildValidator/BuildValidator.csproj b/src/Tools/BuildValidator/BuildValidator.csproj index 3800558e4d50f..390bf86aca592 100644 --- a/src/Tools/BuildValidator/BuildValidator.csproj +++ b/src/Tools/BuildValidator/BuildValidator.csproj @@ -19,6 +19,7 @@ + diff --git a/src/Tools/BuildValidator/IldasmUtilities.cs b/src/Tools/BuildValidator/IldasmUtilities.cs index b617c37ff759b..bfac1def53c9a 100644 --- a/src/Tools/BuildValidator/IldasmUtilities.cs +++ b/src/Tools/BuildValidator/IldasmUtilities.cs @@ -27,7 +27,8 @@ private static string GetIldasmPath() } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - ridName = "linux-x64"; + var architecture = Microsoft.CodeAnalysis.Test.Utilities.IlasmUtilities.Architecture; + ridName = $"linux-{architecture}"; } else { diff --git a/src/Tools/Source/RunTests/Options.cs b/src/Tools/Source/RunTests/Options.cs index ecc626feb0aa4..40460d1e477c9 100644 --- a/src/Tools/Source/RunTests/Options.cs +++ b/src/Tools/Source/RunTests/Options.cs @@ -141,7 +141,7 @@ public Options( internal static Options? Parse(string[] args) { string? dotnetFilePath = null; - var architecture = "x64"; + var architecture = Microsoft.CodeAnalysis.Test.Utilities.IlasmUtilities.Architecture; var includeHtml = false; var testRuntime = TestRuntime.Both; var configuration = "Debug"; diff --git a/src/Tools/Source/RunTests/RunTests.csproj b/src/Tools/Source/RunTests/RunTests.csproj index 2ef5a300de578..c3c7c14e08d87 100644 --- a/src/Tools/Source/RunTests/RunTests.csproj +++ b/src/Tools/Source/RunTests/RunTests.csproj @@ -31,4 +31,4 @@ - \ No newline at end of file +