UE4 - Building shipping package on Mac M1 for Intel architecture

Hi, I’m trying to create a shipping build for Mac of our game on Unreal 4.27.2. I have changed my Mac to a M1 macmini, and this is the first time I create the shipping build on it. I can compile and run the game properly from Xcode, but with RunUAT.command BuildCookRun I get the following error:

  [1/13] Link UnrealHeaderTool-TraceLog.dylib
  [2/13] Link UnrealHeaderTool-Core.dylib
  ld: warning: ignoring file /Users/luke/UnrealEngine/Engine/Binaries/Mac/UnrealHeaderTool-BuildSettings.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
  Undefined symbols for architecture x86_64:
    "BuildSettings::GetBuildDate()", referenced from:
        FApp::GetBuildDate() in Module.Core.9_of_15.cpp.o
    "BuildSettings::GetBranchName()", referenced from:
        FApp::GetBranchName() in Module.Core.9_of_15.cpp.o
        FGlobalEngineVersions::FGlobalEngineVersions() in Module.Core.10_of_15.cpp.o
    "BuildSettings::GetBuildVersion()", referenced from:
        FApp::GetBuildVersion() in Module.Core.9_of_15.cpp.o
        FApp::PrintStartupLogMessages() in Module.Core.9_of_15.cpp.o
    "BuildSettings::IsPromotedBuild()", referenced from:
        FApp::GetEngineIsPromotedBuild() in Module.Core.9_of_15.cpp.o
    "BuildSettings::IsLicenseeVersion()", referenced from:
        FMacCrashContext::GenerateCrashInfoAndLaunchReporter() const in Module.Core.7_of_15.cpp.o
        FMacCrashContext::GenerateEnsureInfoAndLaunchReporter() const in Module.Core.7_of_15.cpp.o
        FGlobalEngineVersions::FGlobalEngineVersions() in Module.Core.10_of_15.cpp.o
    "BuildSettings::GetCurrentChangelist()", referenced from:
        FGlobalEngineVersions::FGlobalEngineVersions() in Module.Core.10_of_15.cpp.o
    "BuildSettings::GetCompatibleChangelist()", referenced from:
        FNetworkVersion::GetNetworkCompatibleChangelist() in Module.Core.10_of_15.cpp.o
        FGlobalEngineVersions::FGlobalEngineVersions() in Module.Core.10_of_15.cpp.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
Took 12.99878s to run mono, ExitCode=6
UnrealBuildTool failed. See log for more details. (/Users/luke/Library/Logs/Unreal Engine/LocalBuildLogs/UBT-PSUnrealEditor-Mac-Development.txt)
AutomationTool exiting with ExitCode=6 (6)
RunUAT ERROR: AutomationTool was unable to run successfully.

I have added to the build command this switch:

-architecture=x86_64

and I also tried to set the terminal environment to x86_64 with this command

$env /usr/bin/arch -x86_64 /bin/zsh --login

Still I get the above error, any ideas?

I fixed it by applying this commit from 4.27.2-plus branch.

https://github.com/EpicGames/UnrealEngine/commit/0b07894ce453d3dab72afd037b9d7fa5fe82c090

set this env variables:

   export ARCHS=x86_64
   export VALID_ARCHS=x86_64

and I didn’t use the $env command to switch to x86 mode above.