diff --git a/samples/unity-of-bugs/Assets/Editor/XcodeProjectUpdater.cs b/samples/unity-of-bugs/Assets/Editor/XcodeProjectUpdater.cs new file mode 100644 index 000000000..290e5522f --- /dev/null +++ b/samples/unity-of-bugs/Assets/Editor/XcodeProjectUpdater.cs @@ -0,0 +1,42 @@ +#if UNITY_IOS && !UNITY_2021_1_OR_NEWER +using UnityEditor; +using UnityEditor.Callbacks; +using UnityEditor.iOS.Xcode; +using UnityEngine; + +namespace Editor +{ + /// + /// Unity adds the '-mno-thumb' compiler flag by default to iOS builds, but this flag is outdated + /// and no longer supported by modern versions of Xcode. Leaving this flag in the project will cause + /// Xcode builds to fail with an "unsupported option '-mno-thumb' for target" error. This post-process + /// build step removes the flag to ensure the sample works on all versions of Unity. + /// + public static class XcodeProjectUpdater + { + [PostProcessBuild] + public static void OnPostProcessBuild(BuildTarget target, string pathToBuildProject) + { + if (target != BuildTarget.iOS) + { + return; + } + + Debug.Log("XcodeUpdater.OnPostProcessBuild started."); + + var pbxProjectPath = PBXProject.GetPBXProjectPath(pathToBuildProject); + var project = new PBXProject(); + project.ReadFromFile(pbxProjectPath); + + var targetGuid = project.GetUnityMainTargetGuid(); + + Debug.Log("Removing '-mno-thumb' from 'OTHER_CFLAGS'."); + project.UpdateBuildProperty(targetGuid, "OTHER_CFLAGS", null, new[] { "-mno-thumb" }); + + project.WriteToFile(pbxProjectPath); + + Debug.Log("XcodeUpdater.OnPostProcessBuild finished."); + } + } +} +#endif diff --git a/samples/unity-of-bugs/Assets/Editor/XcodeProjectUpdater.cs.meta b/samples/unity-of-bugs/Assets/Editor/XcodeProjectUpdater.cs.meta new file mode 100644 index 000000000..693166430 --- /dev/null +++ b/samples/unity-of-bugs/Assets/Editor/XcodeProjectUpdater.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b7813384669334de4b56cc22b1e3384e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/pack.ps1 b/scripts/pack.ps1 index 7bf828043..640f536d5 100644 --- a/scripts/pack.ps1 +++ b/scripts/pack.ps1 @@ -23,7 +23,6 @@ Copy-Item "LICENSE.md" -Destination "package-release/LICENSE.md" # Copy samples Copy-Item "samples/unity-of-bugs/Assets/Scenes*" -Destination "package-release/Samples~/unity-of-bugs/" -Recurse -Copy-Item "samples/unity-of-bugs/Assets/Editor*" -Destination "package-release/Samples~/unity-of-bugs/" -Recurse Copy-Item "samples/unity-of-bugs/Assets/Scripts*" -Destination "package-release/Samples~/unity-of-bugs/" -Recurse # Create zip