Skip to content

Commit

Permalink
Make it possible to build/run tests on linux-arm64
Browse files Browse the repository at this point in the history
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 dotnet#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.
  • Loading branch information
omajid committed Jul 24, 2024
1 parent 9177306 commit e861af5
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
2 changes: 2 additions & 0 deletions eng/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,11 @@
<PackageVersion Include="xunit.extensibility.execution" Version="$(xunitVersion)" />
<PackageVersion Include="XunitXml.TestLogger" Version="2.1.26" />
<PackageVersion Include="runtime.win-x64.Microsoft.NETCore.ILDAsm" Version="$(ILDAsmPackageVersion)" />
<PackageVersion Include="runtime.linux-arm64.Microsoft.NETCore.ILDAsm" Version="$(ILDAsmPackageVersion)" />
<PackageVersion Include="runtime.linux-x64.Microsoft.NETCore.ILDAsm" Version="$(ILDAsmPackageVersion)" />
<PackageVersion Include="runtime.osx-x64.Microsoft.NETCore.ILDAsm" Version="$(ILDAsmPackageVersion)" />
<PackageVersion Include="runtime.win-x64.Microsoft.NETCore.ILAsm" Version="$(ILAsmPackageVersion)" />
<PackageVersion Include="runtime.linux-arm64.Microsoft.NETCore.ILAsm" Version="$(ILAsmPackageVersion)" />
<PackageVersion Include="runtime.linux-x64.Microsoft.NETCore.ILAsm" Version="$(ILAsmPackageVersion)" />
<PackageVersion Include="runtime.osx-x64.Microsoft.NETCore.ILAsm" Version="$(ILAsmPackageVersion)" />
<PackageVersion Include="Basic.CompilerLog.Util" Version="0.6.1" />
Expand Down
9 changes: 8 additions & 1 deletion eng/targets/ILAsm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
<Content Include="$(Pkgruntime_linux-arm64_Microsoft_NETCore_ILAsm)\runtimes\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<LinkBase>runtimes</LinkBase>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
<Content Include="$(Pkgruntime_linux-x64_Microsoft_NETCore_ILAsm)\runtimes\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<LinkBase>runtimes</LinkBase>
Expand All @@ -26,7 +32,8 @@
</Content>

<PackageReference Include="runtime.win-x64.Microsoft.NETCore.ILAsm" GeneratePathProperty="true" ExcludeAssets="all" />
<PackageReference Include="runtime.linux-arm64.Microsoft.NETCore.ILAsm" GeneratePathProperty="true" ExcludeAssets="all" />
<PackageReference Include="runtime.linux-x64.Microsoft.NETCore.ILAsm" GeneratePathProperty="true" ExcludeAssets="all" />
<PackageReference Include="runtime.osx-x64.Microsoft.NETCore.ILAsm" GeneratePathProperty="true" ExcludeAssets="all" />
</ItemGroup>
</Project>
</Project>
9 changes: 8 additions & 1 deletion eng/targets/ILDAsm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
<Content Include="$(Pkgruntime_linux-arm64_Microsoft_NETCore_ILDAsm)\runtimes\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<LinkBase>runtimes</LinkBase>
<Visible>false</Visible>
<Pack>false</Pack>
</Content>
<Content Include="$(Pkgruntime_linux-x64_Microsoft_NETCore_ILDAsm)\runtimes\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<LinkBase>runtimes</LinkBase>
Expand All @@ -25,7 +31,8 @@
</Content>

<PackageReference Include="runtime.win-x64.Microsoft.NETCore.ILDAsm" GeneratePathProperty="true" ExcludeAssets="all" />
<PackageReference Include="runtime.linux-arm64.Microsoft.NETCore.ILDAsm" GeneratePathProperty="true" ExcludeAssets="all" />
<PackageReference Include="runtime.linux-x64.Microsoft.NETCore.ILDAsm" GeneratePathProperty="true" ExcludeAssets="all" />
<PackageReference Include="runtime.osx-x64.Microsoft.NETCore.ILDAsm" GeneratePathProperty="true" ExcludeAssets="all" />
</ItemGroup>
</Project>
</Project>
21 changes: 20 additions & 1 deletion src/Compilers/Test/Core/Metadata/IlasmUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System;
using System.IO;
using System.Runtime.InteropServices;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;
Expand All @@ -22,6 +23,24 @@ public static DisposableFile CreateTempAssembly(string declarations, bool prepen
return new DisposableFile(assemblyPath);
}

private static string GetArchitecture() => RuntimeInformation.ProcessArchitecture switch
{
#if NET8_0_OR_GREATER
System.Runtime.InteropServices.Architecture.Arm => "arm",
System.Runtime.InteropServices.Architecture.Arm64 => "arm64",
System.Runtime.InteropServices.Architecture.Armv6 => "armv6",
System.Runtime.InteropServices.Architecture.LoongArch64 => "loongarch64",
System.Runtime.InteropServices.Architecture.Ppc64le => "ppc64le",
System.Runtime.InteropServices.Architecture.S390x => "s390x",
System.Runtime.InteropServices.Architecture.Wasm => "wasm",
System.Runtime.InteropServices.Architecture.X86 => "x86",
System.Runtime.InteropServices.Architecture.X64 => "x64",
_ => throw new NotImplementedException()
#else
_ => "x64"
#endif
};

private static string GetIlasmPath()
{
if (ExecutionConditionUtil.IsWindowsDesktop)
Expand All @@ -46,7 +65,7 @@ private static string GetIlasmPath()
}
else if (ExecutionConditionUtil.IsLinux)
{
ridName = "linux-x64";
ridName = $"linux-{GetArchitecture()}";
}
else
{
Expand Down
21 changes: 20 additions & 1 deletion src/Tools/BuildValidator/IldasmUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ namespace BuildValidator
{
internal static class IldasmUtilities
{
private static string GetArchitecture() => RuntimeInformation.ProcessArchitecture switch
{
#if NET8_0_OR_GREATER
System.Runtime.InteropServices.Architecture.Arm => "arm",
System.Runtime.InteropServices.Architecture.Arm64 => "arm64",
System.Runtime.InteropServices.Architecture.Armv6 => "armv6",
System.Runtime.InteropServices.Architecture.LoongArch64 => "loongarch64",
System.Runtime.InteropServices.Architecture.Ppc64le => "ppc64le",
System.Runtime.InteropServices.Architecture.S390x => "s390x",
System.Runtime.InteropServices.Architecture.Wasm => "wasm",
System.Runtime.InteropServices.Architecture.X86 => "x86",
System.Runtime.InteropServices.Architecture.X64 => "x64",
_ => throw new NotImplementedException()
#else
_ => "x64"
#endif
};

private static string GetIldasmPath()
{
var ildasmExeName = PlatformInformation.IsWindows ? "ildasm.exe" : "ildasm";
Expand All @@ -27,7 +45,8 @@ private static string GetIldasmPath()
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
ridName = "linux-x64";
ridName = $"linux-{GetArchitecture()}";

}
else
{
Expand Down
16 changes: 15 additions & 1 deletion src/Tools/Source/RunTests/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,24 @@ public Options(
Architecture = architecture;
}

private static string GetArchitecture() => RuntimeInformation.ProcessArchitecture switch
{
System.Runtime.InteropServices.Architecture.Arm => "arm",
System.Runtime.InteropServices.Architecture.Arm64 => "arm64",
System.Runtime.InteropServices.Architecture.Armv6 => "armv6",
System.Runtime.InteropServices.Architecture.LoongArch64 => "loongarch64",
System.Runtime.InteropServices.Architecture.Ppc64le => "ppc64le",
System.Runtime.InteropServices.Architecture.S390x => "s390x",
System.Runtime.InteropServices.Architecture.Wasm => "wasm",
System.Runtime.InteropServices.Architecture.X86 => "x86",
System.Runtime.InteropServices.Architecture.X64 => "x64",
_ => throw new NotImplementedException()
};

internal static Options? Parse(string[] args)
{
string? dotnetFilePath = null;
var architecture = "x64";
var architecture = GetArchitecture();
var includeHtml = false;
var testRuntime = TestRuntime.Both;
var configuration = "Debug";
Expand Down

0 comments on commit e861af5

Please sign in to comment.