Skip to content

Commit

Permalink
Fix bug with running CLT from x64 process on macOS arm64.
Browse files Browse the repository at this point in the history
  • Loading branch information
ww898 committed Aug 26, 2024
1 parent 932e03f commit dbd3b90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 9 additions & 2 deletions JetBrains.Profiler.SelfApi/src/Impl/ConsoleProfiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ public ConsoleProfiler(string executable, string arguments, string messageServic
_presentableName = presentableName;
_isApiReady = isApiReady;

// Note(ww898): We force the OS architecture everywhere!!! Process architecture is inherited by default in macOS ARM64. We turn off this behavior for x64 processes with /usr/bin/arch!!!
var isX64ProcessUnderMacOsArm64 = HabitatInfo.Platform == JetPlatform.MacOsX &&
HabitatInfo.OSArchitecture == JetArchitecture.Arm64 &&
HabitatInfo.ProcessArchitecture == JetArchitecture.X64;
var effectiveExecutable = isX64ProcessUnderMacOsArm64 ? "/usr/bin/arch" : executable;
var effectiveArguments = isX64ProcessUnderMacOsArm64 ? $"-arm64 \"{executable}\" {arguments}" : arguments;

var commandRegex = BuildCommandRegex("([a-zA-Z-]*)", "(.*)");
var si = new ProcessStartInfo
{
FileName = executable,
Arguments = arguments,
FileName = effectiveExecutable,
Arguments = effectiveArguments,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardInput = true,
Expand Down
6 changes: 2 additions & 4 deletions JetBrains.Profiler.SelfApi/src/Impl/PrerequisiteBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ private async Task DoDownloadAsync(
Trace.Info("Prerequisite.Download: targetPath = `{0}`", downloadTo);
Directory.CreateDirectory(downloadTo);

// Bug(ww898): The process architecture is inherited by default in macOS ARM64. But we force it to ARM64 on Windows ARM64 even for x64 tools. See https://youtrack.jetbrains.com/issue/NP-1703
var runtimeIdString = HabitatInfo.Platform == JetPlatform.MacOsX && HabitatInfo.OSArchitecture == JetArchitecture.Arm64
? HabitatInfo.ProcessRuntimeIdString
: HabitatInfo.OSRuntimeIdString;
// Note(ww898): We force the OS architecture everywhere!!! Process architecture is inherited by default in macOS ARM64. We turn off this behavior for x64 processes with /usr/bin/arch!!!
var runtimeIdString = HabitatInfo.OSRuntimeIdString;

var nupkgName = GetPackageName() + "." + runtimeIdString;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Supported frameworks:
<PackageProjectUrl>https://github.com/JetBrains/profiler-self-api/blob/master/README.md</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>jetbrains profiler profiling memory performance net dotnet netcore dotnetcore netstandard windows uwp macos mac linux musl glibc x86 x64 arm64 x86-64 x86_64 aarch64</PackageTags>
<Version>2.5.10</Version>
<Version>2.5.11-preview1</Version>
</PropertyGroup>
<ItemGroup>
<None Include="../../icon.png" Pack="true" Visible="false" PackagePath="" />
Expand Down

0 comments on commit dbd3b90

Please sign in to comment.