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
69 changes: 66 additions & 3 deletions ElectronNET.CLI/Commands/Actions/GetTargetPlatformInformation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace ElectronNET.CLI.Commands.Actions
Expand Down Expand Up @@ -27,6 +28,19 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
netCorePublishRid = "osx-x64";
electronPackerPlatform = "mac";
break;
case "osx-arm64":
netCorePublishRid = "osx-arm64";
electronPackerPlatform = "mac";

//Check to see if .net 6 is installed:
if (!Dotnet6Installed())
{
throw new ArgumentException("You are using a dotnet version older than dotnet 6. Compiling for osx-arm64 requires that dotnet 6 or greater is installed and targeted by your project.", "osx-arm64");
}

//Warn for .net 6 targeting:
Console.WriteLine("Please ensure that your project targets .net 6 or greater. Otherwise you may experience an error compiling for osx-arm64.");
break;
case "linux":
netCorePublishRid = "linux-x64";
electronPackerPlatform = "linux";
Expand All @@ -48,8 +62,20 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
netCorePublishRid = "osx-x64";
electronPackerPlatform = "mac";
if (RuntimeInformation.OSArchitecture.Equals(Architecture.Arm64) && Dotnet6Installed())
{
//Warn for .net 6 targeting:
Console.WriteLine("Please ensure that your project targets .net 6. Otherwise you may experience an error.");

//Apple Silicon Mac:
netCorePublishRid = "osx-arm64";
electronPackerPlatform = "mac";
}
else{
//Intel Mac:
netCorePublishRid = "osx-x64";
electronPackerPlatform = "mac";
}
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Expand All @@ -66,5 +92,42 @@ public static GetTargetPlatformInformationResult Do(string desiredPlatform, stri
NetCorePublishRid = netCorePublishRid
};
}
/// <summary>
/// Checks to see if dotnet 6 or greater is installed.
/// Required for MacOS arm targeting.
/// Note that an error may still occur if the project being compiled does not target dotnet 6 or greater.
/// </summary>
/// <returns>
/// Returns true if dotnet 6 or greater is installed.
/// </returns>
private static bool Dotnet6Installed()
{
//check for .net 6:
//execute dotnet --list-sdks to get versions
Process process = new Process();
process.StartInfo.FileName = "dotnet";
process.StartInfo.Arguments = "--list-sdks";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();

string standard_output;
bool dotnet6Exists = false;

//get command output:
while ((standard_output = process.StandardOutput.ReadLine()) != null)
{
//get the major version and see if its greater than or equal to 6
int majorVer = int.Parse(standard_output.Split(".")[0]);
if (majorVer >= 6)
{
dotnet6Exists = true;
break;
}
}
process.WaitForExit();
return dotnet6Exists;
}
}
}
}
6 changes: 6 additions & 0 deletions ElectronNET.CLI/Commands/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ public Task<bool> ExecuteAsync()

Console.WriteLine("Executing electron magic in this directory: " + buildPath);


string electronArch = "x64";
//Somewhat janky fix for Apple Silicon:
if (platformInfo.NetCorePublishRid == "osx-arm64")
{
electronArch = "arm64";
}
if (parser.Arguments.ContainsKey(_paramElectronArch))
{
electronArch = parser.Arguments[_paramElectronArch][0];
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,13 @@ There are additional platforms available:
```
electronize build /target win
electronize build /target osx
electronize build /target osx-arm64
electronize build /target linux
```

Those three "default" targets will produce x64 packages for those platforms.
Those four "default" targets will produce packages for those platforms.

Note that the `osx-arm64` build requires that the project target `net6.0`. `osx-arm64` is for Apple Silicon Macs.

For certain NuGet packages or certain scenarios you may want to build a pure x86 application. To support those things you can define the desired [.NET Core runtime](https://docs.microsoft.com/en-us/dotnet/core/rid-catalog), the [electron platform](https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#platform) and [electron architecture](https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#arch) like this:

Expand Down