Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions protocol/src/main/kotlin/model/rider/AsmViewerModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class AsmViewerModel : Ext(SolutionModel.Solution) {
field("targetFrameworkOverride", string.nullable)
field("selectedCompiler", CompilerType)
field("disassemblyTimeoutSeconds", int)
field("useCustomRuntime", bool)
field("pathToLocalCoreClr", string.nullable)
}

private val CompilationResult = structdef {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace JetBrains.Rider.Model


/// <summary>
/// <p>Generated from: AsmViewerModel.kt:8</p>
/// <p>Generated from: AsmViewerModel.kt:7</p>
/// </summary>
public class AsmViewerModel : RdExtBase
{
Expand Down Expand Up @@ -112,7 +112,7 @@ internal AsmViewerModel (



protected override long SerializationHash => -8744739113612796705L;
protected override long SerializationHash => 4503471233995481963L;

protected override Action<ISerializers> Register => RegisterDeclaredTypesSerializers;
public static void RegisterDeclaredTypesSerializers(ISerializers serializers)
Expand Down Expand Up @@ -161,7 +161,7 @@ public static AsmViewerModel GetAsmViewerModel(this Solution solution)


/// <summary>
/// <p>Generated from: AsmViewerModel.kt:70</p>
/// <p>Generated from: AsmViewerModel.kt:72</p>
/// </summary>
public sealed class CompilationResult : IPrintable, IEquatable<CompilationResult>
{
Expand Down Expand Up @@ -406,6 +406,8 @@ public sealed class JitConfiguration : IPrintable, IEquatable<JitConfiguration>
[CanBeNull] public string TargetFrameworkOverride {get; private set;}
public CompilerType SelectedCompiler {get; private set;}
public int DisassemblyTimeoutSeconds {get; private set;}
public bool UseCustomRuntime {get; private set;}
[CanBeNull] public string PathToLocalCoreClr {get; private set;}

//private fields
//primary constructor
Expand All @@ -420,7 +422,9 @@ public JitConfiguration(
bool useDotnetBuildForReload,
[CanBeNull] string targetFrameworkOverride,
CompilerType selectedCompiler,
int disassemblyTimeoutSeconds
int disassemblyTimeoutSeconds,
bool useCustomRuntime,
[CanBeNull] string pathToLocalCoreClr
)
{
ShowAsmComments = showAsmComments;
Expand All @@ -434,10 +438,12 @@ int disassemblyTimeoutSeconds
TargetFrameworkOverride = targetFrameworkOverride;
SelectedCompiler = selectedCompiler;
DisassemblyTimeoutSeconds = disassemblyTimeoutSeconds;
UseCustomRuntime = useCustomRuntime;
PathToLocalCoreClr = pathToLocalCoreClr;
}
//secondary constructor
//deconstruct trait
public void Deconstruct(out bool showAsmComments, out bool diffable, out bool useTieredJit, out bool usePGO, out bool runAppMode, out bool useNoRestoreFlag, out bool useDotnetPublishForReload, out bool useDotnetBuildForReload, [CanBeNull] out string targetFrameworkOverride, out CompilerType selectedCompiler, out int disassemblyTimeoutSeconds)
public void Deconstruct(out bool showAsmComments, out bool diffable, out bool useTieredJit, out bool usePGO, out bool runAppMode, out bool useNoRestoreFlag, out bool useDotnetPublishForReload, out bool useDotnetBuildForReload, [CanBeNull] out string targetFrameworkOverride, out CompilerType selectedCompiler, out int disassemblyTimeoutSeconds, out bool useCustomRuntime, [CanBeNull] out string pathToLocalCoreClr)
{
showAsmComments = ShowAsmComments;
diffable = Diffable;
Expand All @@ -450,6 +456,8 @@ public void Deconstruct(out bool showAsmComments, out bool diffable, out bool us
targetFrameworkOverride = TargetFrameworkOverride;
selectedCompiler = SelectedCompiler;
disassemblyTimeoutSeconds = DisassemblyTimeoutSeconds;
useCustomRuntime = UseCustomRuntime;
pathToLocalCoreClr = PathToLocalCoreClr;
}
//statics

Expand All @@ -466,7 +474,9 @@ public void Deconstruct(out bool showAsmComments, out bool diffable, out bool us
var targetFrameworkOverride = ReadStringNullable(ctx, reader);
var selectedCompiler = (CompilerType)reader.ReadInt();
var disassemblyTimeoutSeconds = reader.ReadInt();
var _result = new JitConfiguration(showAsmComments, diffable, useTieredJit, usePGO, runAppMode, useNoRestoreFlag, useDotnetPublishForReload, useDotnetBuildForReload, targetFrameworkOverride, selectedCompiler, disassemblyTimeoutSeconds);
var useCustomRuntime = reader.ReadBool();
var pathToLocalCoreClr = ReadStringNullable(ctx, reader);
var _result = new JitConfiguration(showAsmComments, diffable, useTieredJit, usePGO, runAppMode, useNoRestoreFlag, useDotnetPublishForReload, useDotnetBuildForReload, targetFrameworkOverride, selectedCompiler, disassemblyTimeoutSeconds, useCustomRuntime, pathToLocalCoreClr);
return _result;
};
public static CtxReadDelegate<string> ReadStringNullable = JetBrains.Rd.Impl.Serializers.ReadString.NullableClass();
Expand All @@ -484,6 +494,8 @@ public void Deconstruct(out bool showAsmComments, out bool diffable, out bool us
WriteStringNullable(ctx, writer, value.TargetFrameworkOverride);
writer.Write((int)value.SelectedCompiler);
writer.Write(value.DisassemblyTimeoutSeconds);
writer.Write(value.UseCustomRuntime);
WriteStringNullable(ctx, writer, value.PathToLocalCoreClr);
};
public static CtxWriteDelegate<string> WriteStringNullable = JetBrains.Rd.Impl.Serializers.WriteString.NullableClass();

Expand All @@ -503,7 +515,7 @@ public bool Equals(JitConfiguration other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return ShowAsmComments == other.ShowAsmComments && Diffable == other.Diffable && UseTieredJit == other.UseTieredJit && UsePGO == other.UsePGO && RunAppMode == other.RunAppMode && UseNoRestoreFlag == other.UseNoRestoreFlag && UseDotnetPublishForReload == other.UseDotnetPublishForReload && UseDotnetBuildForReload == other.UseDotnetBuildForReload && Equals(TargetFrameworkOverride, other.TargetFrameworkOverride) && SelectedCompiler == other.SelectedCompiler && DisassemblyTimeoutSeconds == other.DisassemblyTimeoutSeconds;
return ShowAsmComments == other.ShowAsmComments && Diffable == other.Diffable && UseTieredJit == other.UseTieredJit && UsePGO == other.UsePGO && RunAppMode == other.RunAppMode && UseNoRestoreFlag == other.UseNoRestoreFlag && UseDotnetPublishForReload == other.UseDotnetPublishForReload && UseDotnetBuildForReload == other.UseDotnetBuildForReload && Equals(TargetFrameworkOverride, other.TargetFrameworkOverride) && SelectedCompiler == other.SelectedCompiler && DisassemblyTimeoutSeconds == other.DisassemblyTimeoutSeconds && UseCustomRuntime == other.UseCustomRuntime && Equals(PathToLocalCoreClr, other.PathToLocalCoreClr);
}
//hash code trait
public override int GetHashCode()
Expand All @@ -521,6 +533,8 @@ public override int GetHashCode()
hash = hash * 31 + (TargetFrameworkOverride != null ? TargetFrameworkOverride.GetHashCode() : 0);
hash = hash * 31 + (int) SelectedCompiler;
hash = hash * 31 + DisassemblyTimeoutSeconds.GetHashCode();
hash = hash * 31 + UseCustomRuntime.GetHashCode();
hash = hash * 31 + (PathToLocalCoreClr != null ? PathToLocalCoreClr.GetHashCode() : 0);
return hash;
}
}
Expand All @@ -540,6 +554,8 @@ public void Print(PrettyPrinter printer)
printer.Print("targetFrameworkOverride = "); TargetFrameworkOverride.PrintEx(printer); printer.Println();
printer.Print("selectedCompiler = "); SelectedCompiler.PrintEx(printer); printer.Println();
printer.Print("disassemblyTimeoutSeconds = "); DisassemblyTimeoutSeconds.PrintEx(printer); printer.Println();
printer.Print("useCustomRuntime = "); UseCustomRuntime.PrintEx(printer); printer.Println();
printer.Print("pathToLocalCoreClr = "); PathToLocalCoreClr.PrintEx(printer); printer.Println();
}
printer.Print(")");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Core;
Expand Down Expand Up @@ -276,7 +277,9 @@ private async Task<Result<JitCodeGenResult, Error>> GetJitCodegenInternalAsync(D
if (!runtimePackPath.Succeed)
return Result.FailWithValue(new Error(AsmViewerErrorCode.RuntimePackNotFound, runtimePackPath.FailMessage));

executable = Path.Combine(configuration.PathToLocalCoreClr, "dotnet.cmd");
var dotnetScript = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? "dotnet.cmd" : "dotnet.sh";
executable = Path.Combine(configuration.PathToLocalCoreClr, dotnetScript);
command = $"{Path.Combine(pathToCoreClrChecked.Value, "crossgen2", "crossgen2.dll")} --out aot ";

foreach (var envVar in envVars)
Expand Down Expand Up @@ -476,7 +479,7 @@ private async Task<Result<JitCodeGenResult, Error>> GetJitCodegenInternalAsync(D
if (!pathToCoreClrChecked.Succeed)
return Result.FailWithValue(new Error(AsmViewerErrorCode.CoreClrCheckedNotFound, pathToCoreClrChecked.FailMessage));

executable = Path.Combine(pathToCoreClrChecked.Value, "CoreRun.exe");
executable = Path.Combine(pathToCoreClrChecked.Value, JitPathUtils.CoreRunExecutable);
}

if ((configuration.RunAppMode) &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using JetBrains.Core;

namespace ReSharperPlugin.DotNetDisassembler.JitDisasm;

public class JitPathUtils
{
private static readonly string OsPrefix =
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "osx" :
RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "linux" : "windows";

private static readonly string CoreRunExecutableName =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "CoreRun.exe" : "corerun";

public static string CoreRunExecutable => CoreRunExecutableName;

public static Result<string> GetPathToRuntimePack(string pathToLocalCoreClr, string arch)
{
var result = GetPathToCoreClrChecked(pathToLocalCoreClr, arch);
if (!result.Succeed)
return Result.Fail(result.FailMessage);

string runtimePacksPath = Path.Combine(pathToLocalCoreClr, @"artifacts\bin\runtime");
string runtimePacksPath = Path.Combine(pathToLocalCoreClr, "artifacts", "bin", "runtime");
string runtimePackPath = null;
if (Directory.Exists(runtimePacksPath))
{
var packs = Directory.GetDirectories(runtimePacksPath, "*-windows-Release-" + arch);
var packs = Directory.GetDirectories(runtimePacksPath, $"*-{OsPrefix}-Release-{arch}");
runtimePackPath = packs.OrderByDescending(i => i).FirstOrDefault();
}

if (!Directory.Exists(runtimePackPath))
{
var buildCmd = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "build.cmd" : "./build.sh";
var msg =
$"""
Please, build a runtime-pack in your local repo:

Run 'build.cmd Clr+Clr.Aot+Libs -c Release -a {arch}' in the repo root
Run '{buildCmd} Clr+Clr.Aot+Libs -c Release -a {arch}' in the repo root
Don't worry, you won't have to re-build it every time you change something in jit, vm or corelib.
""";
return Result.Fail(msg);
Expand All @@ -37,13 +48,14 @@ public static Result<string> GetPathToRuntimePack(string pathToLocalCoreClr, str

public static Result<string> GetPathToCoreClrChecked(JitDisasmConfiguration configuration) =>
GetPathToCoreClrChecked(configuration.PathToLocalCoreClr, configuration.Arch, configuration.CrossgenIsSelected);

public static Result<string> GetPathToCoreClrChecked(string pathToLocalCoreClr, string arch,
bool isCrossgenSelected = false)
{
var clrCheckedFilesDir = FindJitDirectory(pathToLocalCoreClr, arch);
if (string.IsNullOrWhiteSpace(clrCheckedFilesDir))
{
var buildCmd = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "build.cmd" : "./build.sh";
var msg =
$"""
Path to a local dotnet/runtime repository is either not set or it's not built for {arch} arch yet
Expand All @@ -53,29 +65,39 @@ public static Result<string> GetPathToCoreClrChecked(string pathToLocalCoreClr,
\nPlease clone it and build it in `Checked` mode, e.g.:\n\n
git clone git@github.com:dotnet/runtime.git\n
cd runtime\n
build.cmd Clr+Clr.Aot+Libs -c Release -rc Checked -a {arch}\n\n
{buildCmd} Clr+Clr.Aot+Libs -c Release -rc Checked -a {arch}\n\n
""";
return Result.Fail(msg);
}

return Result.Success(clrCheckedFilesDir);
}


public static Result<string> GetPathToCoreClrCheckedForNativeAot(string pathToLocalCoreClr, string arch)
{
var releaseFolder = Path.Combine(pathToLocalCoreClr, "artifacts", "bin", "coreclr", $"windows.{arch}.Checked");
if (!Directory.Exists(releaseFolder) || !Directory.Exists(Path.Combine(releaseFolder, "aotsdk")) ||
!Directory.Exists(Path.Combine(releaseFolder, "ilc")))
string releaseFolder = null;
foreach (var config in new[] { "Checked", "Debug" })
{
var candidate = Path.Combine(pathToLocalCoreClr, "artifacts", "bin", "coreclr", $"{OsPrefix}.{arch}.{config}");
if (Directory.Exists(candidate) && Directory.Exists(Path.Combine(candidate, "aotsdk")) &&
Directory.Exists(Path.Combine(candidate, "ilc")))
{
releaseFolder = candidate;
break;
}
}

if (releaseFolder == null)
{
var buildCmd = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "build.cmd" : "./build.sh";
var msg =
$"""
Path to a local dotnet/runtime repository is either not set or it's not correctly built for {arch} arch yet for NativeAOT
Please clone it and build it using the following steps.:

git clone git@github.com:dotnet/runtime.git
cd runtime
build.cmd Clr+Clr.Aot+Libs -c Release -rc Checked -a {arch}
{buildCmd} Clr+Clr.Aot+Libs -c Release -rc Checked -a {arch}
""";
return Result.Fail(msg);
}
Expand All @@ -85,17 +107,13 @@ build.cmd Clr+Clr.Aot+Libs -c Release -rc Checked -a {arch}

public static string FindJitDirectory(string basePath, string arch)
{
string jitDir = Path.Combine(basePath, $@"artifacts\bin\coreclr\windows.{arch}.Checked");
string jitDir = Path.Combine(basePath, "artifacts", "bin", "coreclr", $"{OsPrefix}.{arch}.Checked");
if (Directory.Exists(jitDir))
{
return jitDir;
}

jitDir = Path.Combine(basePath, $@"artifacts\bin\coreclr\windows.{arch}.Debug");
jitDir = Path.Combine(basePath, "artifacts", "bin", "coreclr", $"{OsPrefix}.{arch}.Debug");
if (Directory.Exists(jitDir))
{
return jitDir;
}

return null;
}
Expand All @@ -122,4 +140,4 @@ public static void CopyDirectory(string sourceDir, string destinationDir)
CopyDirectory(subDir.FullName, newDestinationDir);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public static JitDisasmConfiguration Create(JitConfiguration config)
// Advanced properties use defaults (not exposed in UI)
UseUnloadableContext = false,
JitDumpInsteadOfDisasm = false,
UseCustomRuntime = false,
UseCustomRuntime = config.UseCustomRuntime,
FgEnable = false,
CustomEnvVars = null,
Crossgen2Args = null,
IlcArgs = null,
PathToLocalCoreClr = null,
PathToLocalCoreClr = config.PathToLocalCoreClr,
OverridenJitDisasm = null,
DontGuessTfm = false,
Arch = RuntimePlatformUtils.GetCurrentArch()
Expand Down
Loading