Skip to content

Commit b39f092

Browse files
committed
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 #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.
1 parent 9177306 commit b39f092

File tree

6 files changed

+73
-5
lines changed

6 files changed

+73
-5
lines changed

eng/Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,11 @@
290290
<PackageVersion Include="xunit.extensibility.execution" Version="$(xunitVersion)" />
291291
<PackageVersion Include="XunitXml.TestLogger" Version="2.1.26" />
292292
<PackageVersion Include="runtime.win-x64.Microsoft.NETCore.ILDAsm" Version="$(ILDAsmPackageVersion)" />
293+
<PackageVersion Include="runtime.linux-arm64.Microsoft.NETCore.ILDAsm" Version="$(ILDAsmPackageVersion)" />
293294
<PackageVersion Include="runtime.linux-x64.Microsoft.NETCore.ILDAsm" Version="$(ILDAsmPackageVersion)" />
294295
<PackageVersion Include="runtime.osx-x64.Microsoft.NETCore.ILDAsm" Version="$(ILDAsmPackageVersion)" />
295296
<PackageVersion Include="runtime.win-x64.Microsoft.NETCore.ILAsm" Version="$(ILAsmPackageVersion)" />
297+
<PackageVersion Include="runtime.linux-arm64.Microsoft.NETCore.ILAsm" Version="$(ILAsmPackageVersion)" />
296298
<PackageVersion Include="runtime.linux-x64.Microsoft.NETCore.ILAsm" Version="$(ILAsmPackageVersion)" />
297299
<PackageVersion Include="runtime.osx-x64.Microsoft.NETCore.ILAsm" Version="$(ILAsmPackageVersion)" />
298300
<PackageVersion Include="Basic.CompilerLog.Util" Version="0.6.1" />

eng/targets/ILAsm.targets

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
<Visible>false</Visible>
1313
<Pack>false</Pack>
1414
</Content>
15+
<Content Include="$(Pkgruntime_linux-arm64_Microsoft_NETCore_ILAsm)\runtimes\**\*.*">
16+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
17+
<LinkBase>runtimes</LinkBase>
18+
<Visible>false</Visible>
19+
<Pack>false</Pack>
20+
</Content>
1521
<Content Include="$(Pkgruntime_linux-x64_Microsoft_NETCore_ILAsm)\runtimes\**\*.*">
1622
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1723
<LinkBase>runtimes</LinkBase>
@@ -26,7 +32,8 @@
2632
</Content>
2733

2834
<PackageReference Include="runtime.win-x64.Microsoft.NETCore.ILAsm" GeneratePathProperty="true" ExcludeAssets="all" />
35+
<PackageReference Include="runtime.linux-arm64.Microsoft.NETCore.ILAsm" GeneratePathProperty="true" ExcludeAssets="all" />
2936
<PackageReference Include="runtime.linux-x64.Microsoft.NETCore.ILAsm" GeneratePathProperty="true" ExcludeAssets="all" />
3037
<PackageReference Include="runtime.osx-x64.Microsoft.NETCore.ILAsm" GeneratePathProperty="true" ExcludeAssets="all" />
3138
</ItemGroup>
32-
</Project>
39+
</Project>

eng/targets/ILDAsm.targets

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
<Visible>false</Visible>
1212
<Pack>false</Pack>
1313
</Content>
14+
<Content Include="$(Pkgruntime_linux-arm64_Microsoft_NETCore_ILDAsm)\runtimes\**\*.*">
15+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
16+
<LinkBase>runtimes</LinkBase>
17+
<Visible>false</Visible>
18+
<Pack>false</Pack>
19+
</Content>
1420
<Content Include="$(Pkgruntime_linux-x64_Microsoft_NETCore_ILDAsm)\runtimes\**\*.*">
1521
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1622
<LinkBase>runtimes</LinkBase>
@@ -25,7 +31,8 @@
2531
</Content>
2632

2733
<PackageReference Include="runtime.win-x64.Microsoft.NETCore.ILDAsm" GeneratePathProperty="true" ExcludeAssets="all" />
34+
<PackageReference Include="runtime.linux-arm64.Microsoft.NETCore.ILDAsm" GeneratePathProperty="true" ExcludeAssets="all" />
2835
<PackageReference Include="runtime.linux-x64.Microsoft.NETCore.ILDAsm" GeneratePathProperty="true" ExcludeAssets="all" />
2936
<PackageReference Include="runtime.osx-x64.Microsoft.NETCore.ILDAsm" GeneratePathProperty="true" ExcludeAssets="all" />
3037
</ItemGroup>
31-
</Project>
38+
</Project>

src/Compilers/Test/Core/Metadata/IlasmUtilities.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using System;
88
using System.IO;
9+
using System.Runtime.InteropServices;
910
using Roslyn.Test.Utilities;
1011
using Roslyn.Utilities;
1112
using Xunit;
@@ -22,6 +23,24 @@ public static DisposableFile CreateTempAssembly(string declarations, bool prepen
2223
return new DisposableFile(assemblyPath);
2324
}
2425

26+
private static string GetArchitecture() => RuntimeInformation.ProcessArchitecture switch
27+
{
28+
#if NET8_0_OR_GREATER
29+
System.Runtime.InteropServices.Architecture.Arm => "arm",
30+
System.Runtime.InteropServices.Architecture.Arm64 => "arm64",
31+
System.Runtime.InteropServices.Architecture.Armv6 => "armv6",
32+
System.Runtime.InteropServices.Architecture.LoongArch64 => "loongarch64",
33+
System.Runtime.InteropServices.Architecture.Ppc64le => "ppc64le",
34+
System.Runtime.InteropServices.Architecture.S390x => "s390x",
35+
System.Runtime.InteropServices.Architecture.Wasm => "wasm",
36+
System.Runtime.InteropServices.Architecture.X86 => "x86",
37+
System.Runtime.InteropServices.Architecture.X64 => "x64",
38+
_ => throw new NotImplementedException()
39+
#else
40+
_ => "x64"
41+
#endif
42+
};
43+
2544
private static string GetIlasmPath()
2645
{
2746
if (ExecutionConditionUtil.IsWindowsDesktop)
@@ -46,7 +65,7 @@ private static string GetIlasmPath()
4665
}
4766
else if (ExecutionConditionUtil.IsLinux)
4867
{
49-
ridName = "linux-x64";
68+
ridName = $"linux-{GetArchitecture()}";
5069
}
5170
else
5271
{

src/Tools/BuildValidator/IldasmUtilities.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ namespace BuildValidator
1212
{
1313
internal static class IldasmUtilities
1414
{
15+
private static string GetArchitecture() => RuntimeInformation.ProcessArchitecture switch
16+
{
17+
#if NET8_0_OR_GREATER
18+
System.Runtime.InteropServices.Architecture.Arm => "arm",
19+
System.Runtime.InteropServices.Architecture.Arm64 => "arm64",
20+
System.Runtime.InteropServices.Architecture.Armv6 => "armv6",
21+
System.Runtime.InteropServices.Architecture.LoongArch64 => "loongarch64",
22+
System.Runtime.InteropServices.Architecture.Ppc64le => "ppc64le",
23+
System.Runtime.InteropServices.Architecture.S390x => "s390x",
24+
System.Runtime.InteropServices.Architecture.Wasm => "wasm",
25+
System.Runtime.InteropServices.Architecture.X86 => "x86",
26+
System.Runtime.InteropServices.Architecture.X64 => "x64",
27+
_ => throw new NotImplementedException()
28+
#else
29+
_ => "x64"
30+
#endif
31+
};
32+
1533
private static string GetIldasmPath()
1634
{
1735
var ildasmExeName = PlatformInformation.IsWindows ? "ildasm.exe" : "ildasm";
@@ -27,7 +45,8 @@ private static string GetIldasmPath()
2745
}
2846
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
2947
{
30-
ridName = "linux-x64";
48+
ridName = $"linux-{GetArchitecture()}";
49+
3150
}
3251
else
3352
{

src/Tools/Source/RunTests/Options.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,24 @@ public Options(
138138
Architecture = architecture;
139139
}
140140

141+
private static string GetArchitecture() => RuntimeInformation.ProcessArchitecture switch
142+
{
143+
System.Runtime.InteropServices.Architecture.Arm => "arm",
144+
System.Runtime.InteropServices.Architecture.Arm64 => "arm64",
145+
System.Runtime.InteropServices.Architecture.Armv6 => "armv6",
146+
System.Runtime.InteropServices.Architecture.LoongArch64 => "loongarch64",
147+
System.Runtime.InteropServices.Architecture.Ppc64le => "ppc64le",
148+
System.Runtime.InteropServices.Architecture.S390x => "s390x",
149+
System.Runtime.InteropServices.Architecture.Wasm => "wasm",
150+
System.Runtime.InteropServices.Architecture.X86 => "x86",
151+
System.Runtime.InteropServices.Architecture.X64 => "x64",
152+
_ => throw new NotImplementedException()
153+
};
154+
141155
internal static Options? Parse(string[] args)
142156
{
143157
string? dotnetFilePath = null;
144-
var architecture = "x64";
158+
var architecture = GetArchitecture();
145159
var includeHtml = false;
146160
var testRuntime = TestRuntime.Both;
147161
var configuration = "Debug";

0 commit comments

Comments
 (0)