(Case 1412113)[BuildError] OSX 12.3 and Unity 2020.3 - constant build errors

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

1 Like

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

Have the same issue here, on an M1 Pro Mac Book, after upgrading to 12.3

Same issue here, all after updating to 12.3.

There’s an issue created for this topic: Getting System.ComponentModel.Win32Exception (2): No such file or directory - Questions & Answers - Unity Discussions

It might be because of python2 was removed in that update? But that is just a wild guess…

2 Likes

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.

1 Like

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.

1 Like
1 Like

The build error is a result of Python no longer being included with macOS 12.3. When you upgrade to macOS 12.3, python is removed from your computer.

The Emscripten build toolchain for WebGL builds on Unity 2020.3 depends on Python 2.7. [WebGL builds on Unity 2021.2 and later require Python 3].

The workaround is to install Python2.7 (from https://www.python.org/) on your computer.

4 Likes

@anthony_b

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?

6 Likes

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.

  • Install Python 2.7 from https://www.python.org/

  • Set the environment variable EMSDK_PYTHON to /usr/local/bin/python2

  • A good way of doing this is to create (or append to) your ~/.zprofile file the following line:

export EMSDK_PYTHON=/usr/local/bin/python2

And then reload the Unity Editor.

1 Like

After this follow up suggestion didn’t work I tried the following (none of which worked):

launchctl setenv EMSDK_PYTHON /usr/local/bin/python2

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.

2 Likes

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");
    }
}
8 Likes

Thanks It works. this what I do exactly

#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
13 Likes

thank you so much for this omg <3

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.

With @dimitroff 's editor env var setting the build works, unless britoli compression is enabled - which results in the following error

Going to try your suggestion @simon_zappar and see if anything is improved for britoli compressed build under emscripten pointing to py3

Hey, sorry took me ages to get round to actually trying it, is it enough to just change the bash line at the top?

I’ve tried making this change in emcc.- reloading unity, but get the same build error, is it the only change necessary?

8021696--1033100--Screenshot 2022-04-05 at 09.06.33.png

Hello,

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 hope this was helpful.

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.