After upgrading MacOS from 12.1 to 12.3, and trying to build any WebGL project (including just a blank 3d project) - the build constantly errors with an il2cpp win32 exception.
This is 100% reproducible on 2020.3.31f1
Made a bug
System.ComponentModel.Win32Exception (2): No such file or directory
at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at Unity.IL2CPP.Shell.SetupAndStart(ExecuteContext context, Boolean asyncMode) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.Shell/Shell.cs:line 423
at Unity.IL2CPP.Shell.ExecuteAsync(ExecuteArgs executeArgs, IExecuteController controller, Boolean asyncMode) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.Shell/Shell.cs:line 299
at Unity.IL2CPP.Shell.Execute(ExecuteArgs executeArgs, IExecuteController controller) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.Shell/Shell.cs:line 355
at Unity.IL2CPP.Building.CppProgramBuilder.ProvideObjectFile(IntermediateObjectFileCompilationData data) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.Building/CppProgramBuilder.cs:line 334
at Unity.IL2CPP.Building.ParallelFor.<>c__DisplayClass1_0`2.<RunWithResult>b__0(Object o) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.Building/ParallelFor.cs:line 78
There is a previous tracker for this error against Linux, but it was marked as WNF due to it being Linux, but as above this bug is also now occurring on MacOS
Looking for information about the problem, I found other similar problems based on the same error that we are getting, but in other libraries.
From what I saw in a Github thread (I saw it the other day so I don’t have the link anymore) the problem came from python2.
I didn’t know that this update had removed python2, but seeing this, it’s likely that the problem is coming from there.
I put in a support ticket, the team are aware of the issue now, however no current fix timelines. I’ve asked for a public tracker bug so will hopefully have one up that we can stay aware of the status of:
We directly notified the issue to the WebGL team because of the severity of the problem. After some additional tests, they confirmed that the issue is only related to WebGL and not IL2CPP.
Using the official package for Python 2.7.18 from www.python.org didn’t resolve the problem for me, I am still getting the same errors like in the description above.
After installation of the official version, python is available in /usr/local/bin/python which is a symlink to the framework that was installed.
Is there anything else I have to do after the installation of Python to make it work?
The next piece of the workaround, is that, after installing Python 2.7 (from https://www.python.org/) the symlink at /usr/bin/python is missing. It’s not straightforward to re-create the symlink due to macOS System Integrity Protection. So, instead create the environment variable EMSDK_PYTHON to refer to the installed python. i.e.
which is the correct way of setting the environment variable for all applications (if you want to persist it you have to edit /etc/launchd.conf
I grepped for EMSDK_PYTHON inside the unity editor files and it’s not used - I believe it’s usage has been introduced after they switched to python3, so it’s not useful as a workaround.
I grepped inside the unity editor files for /usr/bin/python and rewrote all occurences in scripts as /usr/bin/env python. However, there’s one reference in the node binary that I couldn’t replace.
I tried using /etc/synthetic.conf to create symlinks, but this only works for symlinks directly under /.
Finally I tried to create the symlinks in /usr/bin/ by disabling system integrity protection and authenticated-root, but I wasn’t able to remount the filesystem as writable (Error 66) or mount it as writable into a new folder (Error 75).
I am writing this so anyone trying to fix this can save time trying these options.
I found a way to get this working. Just create a pre-build script that will set the EMSDK_PYTHON enviorment variable, because I have no idea where Unity is getting it’s Enviorment variables, but they are not the same as the system ones.
public class PreBuildProcessing : IPreprocessBuildWithReport
{
public int callbackOrder => 1;
public void OnPreprocessBuild(BuildReport report)
{
System.Environment.SetEnvironmentVariable("EMSDK_PYTHON", "/Library/Frameworks/Python.framework/Versions/2.7/bin/python");
}
}
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
public class PreBuildProcessing : IPreprocessBuildWithReport
{
public int callbackOrder => 1;
public void OnPreprocessBuild(BuildReport report)
{
System.Environment.SetEnvironmentVariable("EMSDK_PYTHON", "/Library/Frameworks/Python.framework/Versions/2.7/bin/python");
}
}
#endif
The emscripten in 2020.3 is pretty old, (1.38.11 from August 2018) but it does look like it still supports either python 2 or 3 (since this change in Apr 2018).
So it should actually be sufficient to just use the system python3 now, by setting EMSDK_PYTHON to “/usr/bin/python3” (which is actually part of Xcode command line tools - so run it in a terminal first to check it’s all installed and hooked up properly).
To avoid needing to change the env var, in the end I just updated the first line of emcc to reference python3 rather than python. Looks to have done the trick, I got a working build of a minimal demo scene at least.
Find it in /Applications/Unity/Hub/Editor/2020.3.31f1/PlaybackEngines/WebGLSupport/BuildTools/Emscripten/emcc
One thought on picking up system environment - I think the Unity Hub passes on the environment to the editor, and likes to keep itself running at all times. So you might need to fully quit Unity Hub from the Mac menu bar to pick up any system-level changes. Not tested this myself, as I preferred the more targeted emcc intervention anyway.
I had the same issue but after trying a different option like installing python and putting a pre-build snippet of code, I upgrade my unity version 2021.2.18f1 (the ARM version) and now he build my WEBGL app with my MacBook M1.
I’m pretty sure that was all I did. You’ll need to have Xcode + command line tools installed - check running /usr/bin/python3 in a terminal works as expected.