-
Notifications
You must be signed in to change notification settings - Fork 35
Migrate Unity iOS/macOS native integration #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
50908b5
b46f3d4
c42b106
b4cb06a
67f97e2
2c57486
876a9d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,117 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if UNITY_IOS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.IO; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Linq; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using UnityEditor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using UnityEditor.Callbacks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using UnityEditor.iOS.Xcode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using UnityEditor.iOS.Xcode.Extensions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using UnityEngine; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace Backtrace.Unity.Editor.iOS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Links Backtrace.xcframework and CrashReporter.xcframework | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// embeds, signs Backtrace and sets Swift/iOS settings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static class BacktraceXcodePostBuild | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Runs late after post-processors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private const int PostBuildOrder = 500; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [PostProcessBuild(PostBuildOrder)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (buildTarget != BuildTarget.iOS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var projectPath = PBXProject.GetPBXProjectPath(buildPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var project = new PBXProject(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| project.ReadFromFile(projectPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if UNITY_2019_3_OR_NEWER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string appTargetGuid = project.GetUnityMainTargetGuid(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string unityFrameworkTargetGuid = project.GetUnityFrameworkTargetGuid(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string appTargetGuid = project.TargetGuidByName("Unity-iPhone"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string unityFrameworkTargetGuid = appTargetGuid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small nit: what do you think about?
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (string.IsNullOrEmpty(appTargetGuid) || string.IsNullOrEmpty(unityFrameworkTargetGuid)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Debug.LogError("[Backtrace] iOS post-build: could not resolve Xcode targets."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Locate exported xcframeworks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string FindXCFramework(string folderName) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we move it to class instance? It's not popular in C# to have a function declaration inside another function. its also inconsistent with the rest of the library code |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var matches = Directory.GetDirectories(buildPath, folderName, SearchOption.AllDirectories); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return matches.FirstOrDefault(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var backtraceXCPath = FindXCFramework("Backtrace.xcframework"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var crashReporterXCPath = FindXCFramework("CrashReporter.xcframework"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (string.IsNullOrEmpty(backtraceXCPath)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Debug.LogError($"[Backtrace] Could not locate Backtrace.xcframework under: {buildPath}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (string.IsNullOrEmpty(crashReporterXCPath)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Debug.LogError($"[Backtrace] Could not locate CrashReporter.xcframework under: {buildPath}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+52
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small nit:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Project-relative paths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string relBacktraceXC = ToProjectRelative(buildPath, backtraceXCPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string relCrashReporterXC = ToProjectRelative(buildPath, crashReporterXCPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add file references | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string backtraceFileGuid = project.FindFileGuidByProjectPath(relBacktraceXC); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (string.IsNullOrEmpty(backtraceFileGuid)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| backtraceFileGuid = project.AddFile(relBacktraceXC, relBacktraceXC, PBXSourceTree.Source); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string crashReporterFileGuid = project.FindFileGuidByProjectPath(relCrashReporterXC); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (string.IsNullOrEmpty(crashReporterFileGuid)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| crashReporterFileGuid = project.AddFile(relCrashReporterXC, relCrashReporterXC, PBXSourceTree.Source); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+68
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small nit:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Linking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| project.AddFileToBuild(unityFrameworkTargetGuid, backtraceFileGuid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| project.AddFileToBuild(unityFrameworkTargetGuid, crashReporterFileGuid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Embedding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PBXProjectExtensions.AddFileToEmbedFrameworks(project, appTargetGuid, backtraceFileGuid); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AddBuildPropertyUnique(project, appTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AddBuildPropertyUnique(project, appTargetGuid, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Swift std | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| project.SetBuildProperty(appTargetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Obj-C Linker Flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AddBuildPropertyUnique(project, unityFrameworkTargetGuid, "OTHER_LDFLAGS", "-ObjC"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| project.WriteToFile(projectPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Debug.Log("[Backtrace] iOS post-build: frameworks linked/embedded. Swift stdlib enabled."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static string ToProjectRelative(string buildPath, string absolutePath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var rel = absolutePath.Replace('\\', '/'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var root = (buildPath + "/").Replace('\\', '/'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return rel.StartsWith(root) ? rel.Substring(root.Length) : rel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static void AddBuildPropertyUnique(PBXProject proj, string targetGuid, string key, string value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var current = proj.GetBuildPropertyForAnyConfig(targetGuid, key); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (current == null || !current.Split(' ').Contains(value)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| proj.AddBuildProperty(targetGuid, key, value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Versions/Current/Backtrace |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Versions/Current/Resources |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>BuildMachineOSBuild</key> | ||
| <string>24B83</string> | ||
| <key>CFBundleDevelopmentRegion</key> | ||
| <string>en</string> | ||
| <key>CFBundleIdentifier</key> | ||
| <string>Backtrace.io.BacktraceResources</string> | ||
| <key>CFBundleInfoDictionaryVersion</key> | ||
| <string>6.0</string> | ||
| <key>CFBundleName</key> | ||
| <string>BacktraceResources</string> | ||
| <key>CFBundlePackageType</key> | ||
| <string>BNDL</string> | ||
| <key>CFBundleShortVersionString</key> | ||
| <string>2.1.0</string> | ||
| <key>CFBundleSupportedPlatforms</key> | ||
| <array> | ||
| <string>MacOSX</string> | ||
| </array> | ||
| <key>CFBundleVersion</key> | ||
| <string>1</string> | ||
| <key>DTCompiler</key> | ||
| <string>com.apple.compilers.llvm.clang.1_0</string> | ||
| <key>DTPlatformBuild</key> | ||
| <string>24B75</string> | ||
| <key>DTPlatformName</key> | ||
| <string>macosx</string> | ||
| <key>DTPlatformVersion</key> | ||
| <string>15.1</string> | ||
| <key>DTSDKBuild</key> | ||
| <string>24B75</string> | ||
| <key>DTSDKName</key> | ||
| <string>macosx15.1</string> | ||
| <key>DTXcode</key> | ||
| <string>1610</string> | ||
| <key>DTXcodeBuild</key> | ||
| <string>16B40</string> | ||
| <key>LSMinimumSystemVersion</key> | ||
| <string>12.4</string> | ||
| </dict> | ||
| </plist> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>BuildMachineOSBuild</key> | ||
| <string>24B83</string> | ||
| <key>CFBundleDevelopmentRegion</key> | ||
| <string>en</string> | ||
| <key>CFBundleDisplayName</key> | ||
| <string>Backtrace</string> | ||
| <key>CFBundleExecutable</key> | ||
| <string>Backtrace</string> | ||
| <key>CFBundleIdentifier</key> | ||
| <string>Backtrace.io.Backtrace</string> | ||
| <key>CFBundleInfoDictionaryVersion</key> | ||
| <string>6.0</string> | ||
| <key>CFBundleName</key> | ||
| <string>Backtrace</string> | ||
| <key>CFBundlePackageType</key> | ||
| <string>FMWK</string> | ||
| <key>CFBundleShortVersionString</key> | ||
| <string>2.1.0</string> | ||
| <key>CFBundleSupportedPlatforms</key> | ||
| <array> | ||
| <string>MacOSX</string> | ||
| </array> | ||
| <key>CFBundleVersion</key> | ||
| <string>1</string> | ||
| <key>DTCompiler</key> | ||
| <string>com.apple.compilers.llvm.clang.1_0</string> | ||
| <key>DTPlatformBuild</key> | ||
| <string>24B75</string> | ||
| <key>DTPlatformName</key> | ||
| <string>macosx</string> | ||
| <key>DTPlatformVersion</key> | ||
| <string>15.1</string> | ||
| <key>DTSDKBuild</key> | ||
| <string>24B75</string> | ||
| <key>DTSDKName</key> | ||
| <string>macosx15.1</string> | ||
| <key>DTXcode</key> | ||
| <string>1610</string> | ||
| <key>DTXcodeBuild</key> | ||
| <string>16B40</string> | ||
| <key>LSMinimumSystemVersion</key> | ||
| <string>12.4</string> | ||
| </dict> | ||
| </plist> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad formatting