Search Unity

Windows/Linux Toolchain to build to Linux does not work in script

Discussion in 'Linux' started by Snubber, Mar 29, 2022.

  1. Snubber

    Snubber

    Joined:
    Jan 20, 2020
    Posts:
    65
    Hello, I am using the Toolchain Win Linux package to build a Linux IL2CPP player from my Windows PC. This package works when I manually change my Target Platform to Linux in the Build Settings and then hit "Build". However the package does not work when I try and build via my custom C# script that builds Windows (32 and 64 bit) and Linux all at once.

    You can see the script below. It just calls
    BuildPipeline.BuildPlayer(options);
    with the specific options for each platform.

    When I try and run it I get the following error Exception:
    Exception: C++ code builder is unable to build C++ code for Linux: Could not find valid clang executable at clang.exe

    (let me know if you need to see the whole stack trace)

    It seems like the package does something extra when manually switching to Linux that my script is not doing. Is there any workaround for this? Having to manually wait for each platform to build every time I make an update is very time consuming.

    Code (CSharp):
    1. public class Build
    2.     {
    3.  
    4.         static string[] scenes = {
    5.             "Assets/Scenes/Menu.unity",
    6.             "Assets/Scenes/Game.unity",
    7.             "Assets/Scenes/Admin.unity",
    8.             "Assets/Scenes/Builder.unity",
    9.         };
    10.  
    11.         public static void PerformBuild()
    12.         {
    13.             Windows64Build();
    14.             Windows32Build();
    15.             LinuxBuild();
    16.         }
    17.  
    18.         public static void Windows64Build()
    19.         {
    20.             Debug.Log($"Starting Windows 64 bit build");
    21.  
    22.             BuildPlayerOptions options = new BuildPlayerOptions();
    23.             options.scenes = scenes;
    24.             options.locationPathName = "Build/Windows64/Skullborn.exe";
    25.             options.target = BuildTarget.StandaloneWindows64;
    26.             options.targetGroup = BuildTargetGroup.Standalone;
    27.             options.options = BuildOptions.None;
    28.             BuildReport report = BuildPipeline.BuildPlayer(options);
    29.  
    30.             BuildSummary summary = report.summary;
    31.  
    32.             if (summary.result == BuildResult.Succeeded)
    33.             {
    34.                 Debug.Log($"Windows 64 bit succeeded: {summary.totalSize} bytes. path {summary.outputPath}");
    35.             }
    36.  
    37.             if (summary.result == BuildResult.Failed)
    38.             {
    39.                 Debug.Log("Windows 64 bit failed");
    40.             }
    41.         }
    42.  
    43.         public static void Windows32Build()
    44.         {
    45.             Debug.Log($"Starting Windows 32 bit build");
    46.  
    47.             BuildPlayerOptions options = new BuildPlayerOptions();
    48.             options.scenes = scenes;
    49.             options.locationPathName = "Build/Windows32/Skullborn.exe";
    50.             options.target = BuildTarget.StandaloneWindows;
    51.             options.targetGroup = BuildTargetGroup.Standalone;
    52.             options.options = BuildOptions.None;
    53.             BuildReport report = BuildPipeline.BuildPlayer(options);
    54.  
    55.             BuildSummary summary = report.summary;
    56.  
    57.             if (summary.result == BuildResult.Succeeded)
    58.             {
    59.                 Debug.Log($"Windows 32 bit build succeeded: {summary.totalSize} bytes. path {summary.outputPath}");
    60.             }
    61.  
    62.             if (summary.result == BuildResult.Failed)
    63.             {
    64.                 Debug.Log("Windows 32 bit build failed");
    65.             }
    66.         }
    67.  
    68.         public static void LinuxBuild()
    69.         {
    70.             Debug.Log($"Starting Linux 64 bit build");
    71.  
    72.             BuildPlayerOptions options = new BuildPlayerOptions();
    73.             options.scenes = scenes;
    74.             options.locationPathName = "Build/Linux/Skullborn";
    75.             options.target = BuildTarget.StandaloneLinux64;
    76.             options.targetGroup = BuildTargetGroup.Standalone;
    77.             options.options = BuildOptions.None;
    78.             BuildReport report = BuildPipeline.BuildPlayer(options);
    79.  
    80.             BuildSummary summary = report.summary;
    81.  
    82.             if (summary.result == BuildResult.Succeeded)
    83.             {
    84.                 Debug.Log($"Linux build succeeded: {summary.totalSize} bytes. path {summary.outputPath}");
    85.             }
    86.  
    87.             if (summary.result == BuildResult.Failed)
    88.             {
    89.                 Debug.Log("Linux build failed");
    90.             }
    91.         }
    92.     }
     
  2. kalanasahabandu

    kalanasahabandu

    Unity Technologies

    Joined:
    Apr 20, 2022
    Posts:
    4
    Hi Snubber,

    Would you be able to post the stack trace as well ? Thank you.
     
  3. Snubber

    Snubber

    Joined:
    Jan 20, 2020
    Posts:
    65
    Code (CSharp):
    1. Exception: C++ code builder is unable to build C++ code for Linux: Could not find valid clang executable at clang.exe
    2. UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at <55729f52d042492e9efc384182ae2feb>:0)
    3. UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at <55729f52d042492e9efc384182ae2feb>:0)
    4. UnityEditorInternal.IL2CPPBuilder.RunIl2CppWithArguments (System.Collections.Generic.List`1[T] arguments, System.Action`1[T] setupStartInfo) (at <55729f52d042492e9efc384182ae2feb>:0)
    5. UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (UnityEditor.Il2Cpp.Il2CppBuildPipelineData data) (at <55729f52d042492e9efc384182ae2feb>:0)
    6. UnityEditorInternal.IL2CPPBuilder.Run () (at <55729f52d042492e9efc384182ae2feb>:0)
    7. UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at <55729f52d042492e9efc384182ae2feb>:0)
    8. DesktopStandalonePostProcessor.RunIL2CPP (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditorInternal.IIl2CppPlatformProvider il2cppPlatformProvider, System.Collections.Generic.List`1[T] cppPlugins) (at <55729f52d042492e9efc384182ae2feb>:0)
    9. DesktopStandalonePostProcessor.SetupStagingArea (UnityEditor.Modules.BuildPostProcessArgs args, System.Collections.Generic.HashSet`1[T] filesToNotOverwrite) (at <55729f52d042492e9efc384182ae2feb>:0)
    10. DesktopStandalonePostProcessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at <55729f52d042492e9efc384182ae2feb>:0)
    11. Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
    12. DesktopStandalonePostProcessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at <55729f52d042492e9efc384182ae2feb>:0)
    13. UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <55729f52d042492e9efc384182ae2feb>:0)
    14. 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 <55729f52d042492e9efc384182ae2feb>:0)
    15. UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions)
    16. Deployment.Build:LinuxBuild() (at Assets/Scripts/Editor/Deployment/Build.cs:87)
    17. Deployment.Build:PerformBuild() (at Assets/Scripts/Editor/Deployment/Build.cs:24)
    18. MetaEditor:OnInspectorGUI() (at Assets/Scripts/Editor/MetaEditor.cs:42)
    19. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
     
  4. AllanGameSmithing

    AllanGameSmithing

    Joined:
    Aug 10, 2022
    Posts:
    12
    Hey, did you find a solution to this issue? I am running into exactly the same problem, if I switch platforms manually to Linux, it works fine, if I try to build from script, while still in the Windows target, it fails. The only difference is that for me it says:
    Could not find a clang compiler at /usr/bin/clang.exe

    The path is different. The only clang.exe I have is the one that comes with Unity, and since I am building from windows that is not the path its in. Switching the editor build target from my script fails as well since then I guess the whole editor reloads, so my script pretty much interrupts itself, so that is not an option.
     
  5. Snubber

    Snubber

    Joined:
    Jan 20, 2020
    Posts:
    65
  6. ManuelRauber

    ManuelRauber

    Joined:
    Apr 3, 2015
    Posts:
    122
    Last edited: Jan 28, 2024
  7. iamBraska

    iamBraska

    Joined:
    Apr 16, 2023
    Posts:
    7
    I have the same issue.

    Code (CSharp):
    1. error: Could not set up a toolchain for Architecture x64. Make sure you have the right build tools installed for il2cpp builds. Details:
    2. Could not find a clang compiler at /usr/bin/clang.exe
    3. Unity.IL2CPP.Bee.BuildLogic.ToolchainNotFoundException: Could not find a clang compiler at /usr/bin/clang.exe
    4.    at Unity.IL2CPP.Bee.BuildLogic.Linux.LinuxBuildLogic.UserAvailableToolchainFor(Architecture architecture, NPath toolChainPath, NPath sysRootPath)
    5.    at PlayerBuildProgramLibrary.PlayerBuildProgramBase.GetIl2CppToolChain(PlatformBuildLogic platform, Architecture architecture, NPath toolChainPath, NPath sysrootPath)
    6.    at PlayerBuildProgramLibrary.PlayerBuildProgramBase.SetupIl2CppBuild()
    7.    at PlayerBuildProgramLibrary.PlayerBuildProgramBase.<SetupPlayerBuild>b__94_0()
    8.    at Bee.Core.TinyProfiler2Base.Section[T](String label, Func`1 func, Dictionary`2 metadata)
    9.    at PlayerBuildProgramLibrary.PlayerBuildProgramBase.SetupPlayerBuild()
    10.    at LinuxPlayerBuildProgram.SetupPlayerBuild()
    11.    at PlayerBuildProgramLibrary.PlayerBuildProgramBase.RunBuildProgram()
    12.    at PlayerBuildProgramTypeWrapper.Run(String[] args)
    13.    at Program.Main(String[] args)
    14. UnityEngine.Debug:ExtractStackTraceNoAlloc (byte*,int,string)
    15. UnityEngine.StackTraceUtility:ExtractStackTrace ()
    16. UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
    17. UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    18. UnityEngine.Logger:Log (UnityEngine.LogType,object)
    19. UnityEngine.Debug:LogError (object)
    20. UnityEditor.Modules.BeeBuildPostprocessor:ReportBuildResults ()
    21. UnityEditor.Modules.BeeBuildPostprocessor:PostProcess (UnityEditor.Modules.BuildPostProcessArgs)
    22. UnityEditor.Modules.BeeBuildPostprocessor:PostProcess (UnityEditor.Modules.BuildPostProcessArgs,UnityEditor.BuildProperties&)
    23. UnityEditor.PostprocessBuildPlayer:Postprocess (UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,string,string,string,UnityEditor.BuildOptions,UnityEditor.RuntimeClassRegistry,UnityEditor.Build.Reporting.BuildReport)
    24. UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck (string[],string,string,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,UnityEditor.BuildOptions,string[],bool)
    25. UnityEditor.BuildPipeline:BuildPlayerInternal (string[],string,string,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,UnityEditor.BuildOptions,string[])
    26. UnityEditor.BuildPipeline:BuildPlayer (string[],string,string,UnityEditor.BuildTargetGroup,UnityEditor.BuildTarget,int,UnityEditor.BuildOptions,string[])
    27. UnityEditor.BuildPipeline:BuildPlayer (UnityEditor.BuildPlayerOptions)
    28. Editor.Build:BuildPlatform<Editor.Platforms.Linux> () (at Assets/Scripts/Editor/Build.cs:38)
    29. Editor.Build:Linux () (at Assets/Scripts/Editor/Build.cs:18)
     
  8. iamBraska

    iamBraska

    Joined:
    Apr 16, 2023
    Posts:
    7
    I got around it by specifying the build target in the Unity command, even though I also set it in the C# code:


    Unity.exe -quit -batchmode -nographics -executeMethod BuildLinux -buildTarget linux64


    I have created a Powershell script to build a Windows and Linux build. Each calls its own Unity build command. Meaning, I don't build both targets in the same Unity command.
     
  9. iamBraska

    iamBraska

    Joined:
    Apr 16, 2023
    Posts:
    7
    Scratch that, I was talking too fast. Turns out, what fixed it for me was upgrading to Unity 2023.2.14f1. I had previously used 2023.2.12f1.
     
  10. iamBraska

    iamBraska

    Joined:
    Apr 16, 2023
    Posts:
    7
    Nevermind. I did manage to compile a Linux build using my tiny C# build system but now I'm back to the same error. Unity chooses the right version sometimes. I can't figure out when though.