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 #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 26, 2024
1 parent 9177306 commit b3c9c79
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 6 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>
14 changes: 13 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,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)
Expand All @@ -46,7 +58,7 @@ private static string GetIlasmPath()
}
else if (ExecutionConditionUtil.IsLinux)
{
ridName = "linux-x64";
ridName = $"linux-{GetArchitecture()}";
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/Tools/BuildValidator/BuildValidator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ProjectReference Include="..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
<ProjectReference Include="..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
<ProjectReference Include="..\..\Compilers\Core\Rebuild\Microsoft.CodeAnalysis.Rebuild.csproj" />
<ProjectReference Include="..\..\Compilers\Test\Core\Microsoft.CodeAnalysis.Test.Utilities.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/Tools/BuildValidator/IldasmUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ 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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Source/RunTests/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Source/RunTests/RunTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
<Target Name="CopyCustomContent" AfterTargets="AfterBuild" Condition="$([MSBuild]::IsOSPlatform('Windows'))">
<Copy SourceFiles="@(_CopyItems)" DestinationFolder="$(OutDir)/VSIXExpInstaller" />
</Target>
</Project>
</Project>

0 comments on commit b3c9c79

Please sign in to comment.