IL2CPP for Mac only available in Mac editor

This is a bit disappointing, really goes against the whole point of Unity being able to build everywhere from one editor. If this will never be added to the windows editor (I don’t know if this is a temporary limitation or here to stay) can we atleast seperate the backend setting for mac, windows linux? Because right now we can only turn all of them to IL2CPP, which is really annoying since we can ONLY build windows to IL2CPP

Think I’ll be sticking to mono then, shame

2 Likes

Well, you can’t compile C++ code for macOS on Windows. That’s way that restriction exists.

The suggestion to separate the setting is interesting, but it might be hard to implement without breaking scripting backwards compatibility as right now you set it according to BuildTargetGroup.

May I suggest you change scripting backend and build player via script in your project rather than using default build window?

Is there any way to detect if IL2CPP is supported on the current installation for a given build target? If so, then I gladly would. Would make things a lot easier. If IL2CPP is selected AND it is supported for this editor + target combo, use IL2CPP, otherwise, use mono

My current experimentation shows the API only lets us set and get the backend for a given group, but given Mac and Windows are both standalone, this doesn’t help. Am I missing anything?

static bool CanBuildTargetToIL2CPP(BuildTarget target)
{
   return Application.platform == GetHostPlatform(target);
}

static RuntimePlatform GetHostPlatform(BuildTarget target)
{
   switch (target)
   {
       case BuildTarget.StandaloneOSX:
#pragma warning disable 612, 618
       case BuildTarget.StandaloneOSXUniversal:
       case BuildTarget.StandaloneOSXIntel:
       case BuildTarget.StandaloneOSXIntel64:
#pragma warning restore 612, 618
           return RuntimePlatform.OSXEditor;
           break;
           
       case BuildTarget.StandaloneLinux:
       case BuildTarget.StandaloneLinux64:
       case BuildTarget.StandaloneLinuxUniversal:
           return RuntimePlatform.LinuxEditor;
           
       case BuildTarget.StandaloneWindows:
       case BuildTarget.StandaloneWindows64:
           return RuntimePlatform.WindowsEditor;
           
       default:
           throw new Exception(string.Format("BuildTarget.{0} is not a standalone player build target!");
   }
}

So essentially just doing it manually? If I’m not mistaken, Windows IL2CPP is a seperate module to the base Windows mono, meaning this test would be incorrect if the user has not installed windows IL2CPP?

Yeah, you’d have to check that too if you want to include that scenario. I thought you just cared about “running on X platform editor cannot build IL2CPP”.

static bool AreIl2CppPlayersInstalled(BuildTarget target)
{
   string playerPackage, playerName;
   string[] il2cppVariations;

   switch (target)
   {
       case BuildTarget.StandaloneOSX:
#pragma warning disable 612, 618
       case BuildTarget.StandaloneOSXUniversal:
       case BuildTarget.StandaloneOSXIntel:
       case BuildTarget.StandaloneOSXIntel64:
#pragma warning restore 612, 618
           {
               playerPackage = BuildPipeline.GetPlaybackEngineDirectory(BuildTarget.StandaloneOSX, BuildOptions.None);
               playerName = "UnityPlayer.app/Contents/MacOS/UnityPlayer";
               il2cppVariations = new[]
               {
                   "macosx64_development_il2cpp",
                   "macosx64_nondevelopment_il2cpp",
               };
           }
           break;
           
       case BuildTarget.StandaloneLinux:
       case BuildTarget.StandaloneLinux64:
       case BuildTarget.StandaloneLinuxUniversal:
           {
               playerPackage = BuildPipeline.GetPlaybackEngineDirectory(BuildTarget.StandaloneLinux, BuildOptions.None);
               playerName = "LinuxPlayer";
               il2cppVariations = new[]
               {
                   "linux32_headless_development_il2cpp",
                   "linux32_headless_nondevelopment_il2cpp",
                   "linux32_withgfx_development_il2cpp",
                   "linux32_withgfx_nondevelopment_il2cpp",
                   "linux64_headless_development_il2cpp",
                   "linux64_headless_nondevelopment_il2cpp",
                   "linux64_withgfx_development_il2cpp",
                   "linux64_withgfx_nondevelopment_il2cpp",
               };
           }
           break;
           
       case BuildTarget.StandaloneWindows:
       case BuildTarget.StandaloneWindows64:
           {
               playerPackage = BuildPipeline.GetPlaybackEngineDirectory(BuildTarget.StandaloneWindows, BuildOptions.None);
               playerName = "UnityPlayer.dll";
               il2cppVariations = new[]
               {
                   "win32_development_il2cpp",
                   "win32_nondevelopment_il2cpp",
                   "win64_development_il2cpp",
                   "win64_nondevelopment_il2cpp"
               };
           }
           break;
           
       default:
           throw new Exception(string.Format("BuildTarget.{0} is not a standalone player build target!");
   }

   foreach (var variation in il2cppVariations)
   {
       if (File.Exists(Paths.Combine(playerPackage, "Variations", variation, playerName)))
           return true;
   }

   return false;
}

I see, so just check if the files exist? Any plans to add a proper API for this in the future? Windows store has IL2CPP as a seperate module too right? Whereas Android and iOS come with it? (Windows store also has .net as a module?)

Yeah, that’s how Unity checks it. We had no plans to add anything like this, maybe it’s worth it. And yes, UWP has two modules (.NET and IL2CPP), while iOS and Android come with both in one.

1 Like

Thanks, let me know if it comes back that a more proper API will be added. In the mean time, I’ll probably take what you have and perhaps try and flesh it out more :slight_smile:

BuildPipeline.GetPlaybackEngineDirectory doesnt exist, or am I missing a namespace?

EDIT: It’s private

For anyone with a similar issue, I reflected my way in

MethodInfo[] Methods = typeof(BuildPipeline).GetMethods(BindingFlags.NonPublic | BindingFlags.Static);
            MethodInfo GetPlaybackEngineDirectory = Methods.First((MethodInfo x) => x.Name == "GetPlaybackEngineDirectory" && x.ReturnType == typeof(string) && x.GetParameters().Length == 2);
            string PlayerPackage = GetPlaybackEngineDirectory.Invoke(null, new object[] { Target, BuildOptions.None }).ToString();

Almost everything is up and running correctly now :slight_smile: However, x86 IL2CPP build seemed to fail with the IL2CPP.exe crashing

Assertion failed: Assertion failed on expression: 'ptr == NULL || !HAS_ROOT_REFERENCE(GET_CURRENT_ALLOC_ROOT_REFERENCE()) || GET_CURRENT_ALLOC_ROOT_REFERENCE() == GET_ROOT_REFERENCE(s_MonoDomainContainer, kMemMono)'
UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions)
BA.Platform:BuildToPlatform(BuildAutomator) (at Assets/Plugins/QFSW/Build Automator/Editor/Platform.cs:294)
BA.BuildAutomator:PerformBuilds() (at Assets/Plugins/QFSW/Build Automator/Editor/BuildAutomator.cs:951)
BA.BuildAutomator:OnGUI() (at Assets/Plugins/QFSW/Build Automator/Editor/BuildAutomatorUI.cs:145)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

that happened 900 times, then this happened

Exception: C:\Program Files\Unity\Editor\Data\il2cpp/build/il2cpp.exe did not run properly!
UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:130)
UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:73)
UnityEditorInternal.IL2CPPBuilder.RunIl2CppWithArguments (System.Collections.Generic.List`1[T] arguments, System.Action`1[T] setupStartInfo, System.String workingDirectory) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:362)
UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (System.Collections.Generic.ICollection`1[T] userAssemblies, System.String outputDirectory, System.String workingDirectory, System.Boolean platformSupportsManagedDebugging) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:343)
UnityEditorInternal.IL2CPPBuilder.Run () (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:162)
UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:42)
DesktopStandalonePostProcessor.SetupStagingArea (UnityEditor.Modules.BuildPostProcessArgs args) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/DesktopStandalonePostProcessor.cs:192)
DesktopStandalonePostProcessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/DesktopStandalonePostProcessor.cs:20)
UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at C:/buildslave/unity/build/Editor/Mono/Modules/DefaultBuildPostprocessor.cs:27)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:285)
UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions)
BA.Platform:BuildToPlatform(BuildAutomator) (at Assets/Plugins/QFSW/Build Automator/Editor/Platform.cs:294)
BA.BuildAutomator:PerformBuilds() (at Assets/Plugins/QFSW/Build Automator/Editor/BuildAutomator.cs:951)
BA.BuildAutomator:OnGUI() (at Assets/Plugins/QFSW/Build Automator/Editor/BuildAutomatorUI.cs:145)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Could you look into this? Also, it seems whenever theres an IL2CPP error (IL2CPP doesnt exist, crashes etc) the build will fail but the build reporting api will say that the build succeeded, I think you should have this looked into :slight_smile:

Anyways thanks for the help, let me know about the whole IL2CPP on windows x86 stuff

Can you post a full editor log? Does this happen with only your project or also an empty project?

Sure, should be able to get back to you in a few hours. Will test with a different project too

https://www.dropbox.com/s/sh694po2r62iyd1/Editor.log?dl=0
Was too big to upload here

Ouch, you’ve hit an internal compiler error :frowning:

il2cpp.exe didn't catch exception: Unity.IL2CPP.Building.BuilderFailedException: Bulk_Rewired_Core_9.cpp
c:\users\yusuf\unity projects\games\subsideria\temp\stagingarea\data\il2cppoutput\bulk_rewired_core_9.cpp(50030) : fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\utc\src\p2\main.c', line 260)
 To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
 Help menu, or open the Technical Support help file for more information

c:\users\yusuf\unity projects\games\subsideria\temp\stagingarea\data\il2cppoutput\bulk_rewired_core_9.cpp(50030) : fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'f:\dd\vctools\compiler\utc\src\common\error.c', line 792)
 To work around this problem, try simplifying or changing the program near the locations listed above.
Please choose the Technical Support command on the Visual C++
 Help menu, or open the Technical Support help file for more information

Invocation was: Executable: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\bin\HostX64\x86\cl.exe"
Arguments: "C:\Users\Yusuf\Unity Projects\Games\Subsideria\Temp\StagingArea\Data\il2cppOutput\Bulk_Rewired_Core_9.cpp" /nologo /c /bigobj /W3 /Zi /EHs /GR- /Gy /wd4715 /wd4102 /wd4800 /wd4056 /wd4190 /wd4723 /wd4467 /wd4503 /Ox /Oi /Oy- /GS- /Gw /GF /Zo /MT /DNET_4_0 /DUNITY_JIT /DGC_NOT_DLL /DRUNTIME_IL2CPP /D_WIN32 /DWIN32 /DWIN32_THREADS /D_WINDOWS /DWINDOWS /D_UNICODE /DUNICODE /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS /D_WINSOCK_DEPRECATED_NO_WARNINGS /DNOMINMAX /D_NDEBUG /DNDEBUG /DWINDOWS_SDK_BUILD_VERSION=16299 /DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP /I"C:\Program Files\Unity\Editor\Data\il2cpp\libil2cpp" /I"C:\Program Files\Unity\Editor\Data\il2cpp\external\boehmgc\include" /I"C:\Program Files\Unity\Editor\Data\il2cpp\libil2cpp\mono-runtime" /I"C:\Program Files\Unity\Editor\Data\il2cpp\libil2cpp\mono-runtime" /I"C:\Users\Yusuf\Unity Projects\Games\Subsideria\Temp\StagingArea\Data\il2cppOutput" /I"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\include" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\winrt" /I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt" /Fo"C:\Users\Yusuf\Unity Projects\Games\Subsideria\Library\il2cpp_cache\AB4C0CC03C82BBB9B1FFAB7447689AA8.obj" /Fd"C:\Users\Yusuf\Unity Projects\Games\Subsideria\Library\il2cpp_cache\AB4C0CC03C82BBB9B1FFAB7447689AA8.pdb"
EnvArg key: PATH value: C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x86;C:\Program Files (x86)\Windows Kits\10\bin\x86;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.13.26128\bin\HostX64\x64

   at Unity.IL2CPP.Building.CppProgramBuilder.BuildAllCppFiles(IEnumerable`1 sourceFilesToCompile, IBuildStatisticsCollector statisticsCollector)
   at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
   at Unity.IL2CPP.Building.Statistics.BuildingTestRunnerHelper.BuildAndLogStatsForTestRunner(CppProgramBuilder builder, IBuildStatistics& statistics)
   at il2cpp.Program.DoRun(String[] args)
   at il2cpp.Program.Run(String[] args)
   at il2cpp.Program.Main(String[] args)

We’ll need a bug report to look at this and fix it. It will likely involve us contacting Microsoft as this is a bug in the Visual C++ compiler, not IL2CPP. Does it also happen if you target 64-bit?

ouch :frowning: So nothing wrong on my end then? At least I’m glad I can help improve Unity by catching this error
Nope, only x86. x64 + IL2CPP for Windows works fine, so I’m not too bothered given most users will be x64 at this point :slight_smile:

Tried a smaller project that didn’t use any plugins btw, and it worked there, in case that helps

Yeah, the issue is probably something in “Rewired.Core.dll” that is causing this.

Hmm I see, perhaps I’ll forward this thread over to the folks who made rewired?

Sure, we don’t really care where the bug report comes from :slight_smile: