Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Add LLVM support for iOS test runner; use runtime packs #35106

Merged
merged 9 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@
<Uri>https://github.com/mono/linker</Uri>
<Sha>8caef57d1f3bc7a188e5dd26d43a2d34151223f9</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.XHarness.Tests.Runners" Version="1.0.0-prerelease.20214.2">
<Dependency Name="Microsoft.DotNet.XHarness.Tests.Runners" Version="1.0.0-prerelease.20216.4">
<Uri>https://github.com/dotnet/xharness</Uri>
<Sha>b5bfc4fcd431ab1fd560bdea7642c7998e30f24d</Sha>
<Sha>83b805d29a7e82f9d1d4a39c3e02f03c563b17b1</Sha>
</Dependency>
</ToolsetDependencies>
</Dependencies>
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<SystemDataSqlClientVersion>4.8.0</SystemDataSqlClientVersion>
<!-- Testing -->
<MicrosoftNETTestSdkVersion>16.7.0-preview-20200408-06</MicrosoftNETTestSdkVersion>
<MicrosoftDotNetXHarnessTestsRunnersVersion>1.0.0-prerelease.20214.2</MicrosoftDotNetXHarnessTestsRunnersVersion>
<MicrosoftDotNetXHarnessTestsRunnersVersion>1.0.0-prerelease.20216.4</MicrosoftDotNetXHarnessTestsRunnersVersion>
<XUnitVersion>2.4.1</XUnitVersion>
<TraceEventVersion>2.0.5</TraceEventVersion>
<NewtonsoftJsonVersion>12.0.3</NewtonsoftJsonVersion>
Expand Down
11 changes: 6 additions & 5 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -943,19 +943,20 @@
<PropertyGroup>
<TestDir>$(ArtifactsDir)bin\$(TestName)\$(NetCoreAppCurrent)-$(Configuration)</TestDir>
<TestDir Condition="!Exists('$(TestDir)')">$(ArtifactsDir)bin\$(TestName)\$(NetCoreAppCurrent)-Unix-$(Configuration)</TestDir>
<BclDir>$(ArtifactsDir)bin\runtime\$(NetCoreAppCurrent)-$(TargetOS)-$(Configuration)-$(TargetArchitecture)</BclDir>
<RuntimePackDir>$(ArtifactsDir)bin\lib-runtime-packs\runtimes\ios-$(TargetArchitecture)</RuntimePackDir>
<BundleDir>$(TestDir)\Bundle</BundleDir>
</PropertyGroup>
<ItemGroup>
<TestBinaries Include="$(TestDir)\*.*"/>
<AppleTestRunnerBinaries Include="msbuild\AppleTestRunner\bin\*.*" />
<BclBinaries Include="$(BclDir)\*.*" Exclude="$(BclDir)\System.Runtime.WindowsRuntime.dll" />
<BclBinaries Include="$(RuntimePackDir)\lib\$(NetCoreAppCurrent)\*.*" Exclude="$(RuntimePackDir)\lib\$(NetCoreAppCurrent)\System.Runtime.WindowsRuntime.dll" />
<BclBinaries Include="$(RuntimePackDir)\native\*.*" />
<MonoRuntimeBinaries Include="$(BinDir)\*.*" />
</ItemGroup>

<Error Condition="'$(TestName)' == ''" Text="TestName is not set" />
<Error Condition="!Exists('$(TestDir)')" Text="TestDir=$(TestDir) doesn't exist" />
<Error Condition="!Exists('$(BclDir)')" Text="BclDir=$(BclDir) doesn't exist" />
<Error Condition="!Exists('$(RuntimePackDir)')" Text="RuntimePackDir=$(RuntimePackDir) doesn't exist" />

<RemoveDir Directories="$(BundleDir)" />

Expand All @@ -967,8 +968,8 @@
<AppleAppBuilderTask
Arch="$(TargetArchitecture)"
ProjectName="$(TestName)"
MonoRuntimeHeaders="$(BinDir)include\mono-2.0"
CrossCompiler="$(BinDir)cross\mono-aot-cross"
MonoRuntimeHeaders="$(RuntimePackDir)\native\include\mono-2.0"
CrossCompiler="$(RuntimePackDir)\native\cross\mono-aot-cross"
MainLibraryFileName="AppleTestRunner.dll"
UseConsoleUITemplate="True"
GenerateXcodeProject="True"
Expand Down
32 changes: 22 additions & 10 deletions src/mono/msbuild/AppleAppBuilder/AotCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ public static void PrecompileLibraries(
string binDir,
string[] libsToPrecompile,
IDictionary<string, string> envVariables,
bool optimize)
bool optimize,
bool useLlvm,
string? llvmPath)
{
Parallel.ForEach(libsToPrecompile,
new ParallelOptions { MaxDegreeOfParallelism = parallel ? Environment.ProcessorCount : 1 },
lib => PrecompileLibrary(crossCompiler, arch, binDir, lib, envVariables, optimize));
lib => PrecompileLibrary(crossCompiler, arch, binDir, lib, envVariables, optimize, useLlvm, llvmPath));
}

private static void PrecompileLibrary(
Expand All @@ -33,14 +35,17 @@ private static void PrecompileLibrary(
string binDir,
string libToPrecompile,
IDictionary<string, string> envVariables,
bool optimize)
bool optimize,
bool useLlvm,
string? llvmPath)
{
Utils.LogInfo($"[AOT] {libToPrecompile}");

var crossArgs = new StringBuilder();
crossArgs
.Append(" -O=gsharedvt,float32")
.Append(" --nollvm")
.Append(" -O=gsharedvt")
.Append(" -O=-float32")
.Append(useLlvm ? " --llvm" : " --nollvm")
.Append(" --debug");

string libName = Path.GetFileNameWithoutExtension(libToPrecompile);
Expand All @@ -55,15 +60,22 @@ private static void PrecompileLibrary(
.Append("outfile=").Append(Path.Combine(binDir, libName + ".dll.s,"))
.Append("msym-dir=").Append(Path.Combine(binDir, "Msym,"))
// TODO: enable aotdata
//.Append("data-outfile=").Append(Path.Combine(binDir, libName + ".aotdata,"))
.Append("data-outfile=").Append(Path.Combine(binDir, libName + ".aotdata,"))
// TODO: enable direct-pinvokes (to get rid of -force_loads)
//.Append("direct-pinvoke,")
.Append("full,");
.Append("full,")
.Append("mattr=+crc,"); // enable System.Runtime.Intrinsics.Arm

if (useLlvm)
{
aotArgs
.Append("llvm-path=").Append(llvmPath).Append(',')
.Append("llvm-outfile=").Append(Path.Combine(binDir, libName + ".dll-llvm.o,"));
// it has -llvm.o suffix because we need both LLVM and non-LLVM bits for every assembly
// most of the stuff from non-llvm .o will be linked out.
}

// TODO: enable Interpreter
// TODO: enable LLVM
// TODO: enable System.Runtime.Intrinsics.Arm (LLVM-only for now)
// e.g. .Append("mattr=+crc,")

crossArgs
.Append(" --aot=").Append(aotArgs).Append(" ")
Expand Down
20 changes: 19 additions & 1 deletion src/mono/msbuild/AppleAppBuilder/AppleAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ public class AppleAppBuilderTask : Task
/// </summary>
public bool UseConsoleUITemplate { get; set; }

/// <summary>
/// Use LLVM for FullAOT
/// The cross-compiler must be built with LLVM support
/// </summary>
public bool UseLlvm { get; set; }

/// <summary>
/// Path to LLVM binaries (opt and llc)
/// It's required if UseLlvm is set
/// </summary>
public string? LlvmPath { get; set; }

/// <summary>
/// Path to *.app bundle
/// </summary>
Expand Down Expand Up @@ -127,6 +139,12 @@ public override bool Execute()
throw new ArgumentException($"ProjectName='{ProjectName}' should not contain spaces");
}

if (UseLlvm && !string.IsNullOrEmpty(LlvmPath))
{
// otherwise we might accidentally use some random llc/opt from PATH (installed with clang)
throw new ArgumentException($"LlvmPath shoun't be empty when UseLlvm is set");
}

string[] excludes = new string[0];
if (ExcludeFromAppDir != null)
{
Expand Down Expand Up @@ -154,7 +172,7 @@ public override bool Execute()

AotCompiler.PrecompileLibraries(CrossCompiler, Arch, !DisableParallelAot, binDir, libsToAot,
new Dictionary<string, string> { {"MONO_PATH", AppDir} },
Optimized);
Optimized, UseLlvm, LlvmPath);
}

// generate modules.m
Expand Down
2 changes: 1 addition & 1 deletion src/mono/msbuild/AppleAppBuilder/Xcode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static string GenerateXCode(
string? nativeMainSource = null)
{
// bundle everything as resources excluding native files
string[] excludes = {".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a"};
string[] excludes = {".dll.o", ".dll.s", ".dwarf", ".m", ".h", ".a", ".bc"};

string[] resources = Directory.GetFiles(workspace)
.Where(f => !excludes.Any(e => f.EndsWith(e, StringComparison.InvariantCultureIgnoreCase)))
Expand Down
2 changes: 1 addition & 1 deletion src/mono/msbuild/AppleTestRunner/AppleTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static async Task<int> Main(string[] args)

protected override IEnumerable<TestAssemblyInfo> GetTestAssemblies()
{
foreach (string file in testLibs!)
foreach (string file in testLibs)
{
yield return new TestAssemblyInfo(Assembly.LoadFrom(file), file);
}
Expand Down