Skip to content
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

iOS: native support #254

Merged
merged 57 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
1ca5f10
added build post process for xcode
bitsandfoxes Jul 13, 2021
e7e8479
fixed pathing
bitsandfoxes Jul 13, 2021
88ef4d5
moved ios post processing into new proj
bitsandfoxes Jul 15, 2021
0908f67
cleanup
bitsandfoxes Jul 15, 2021
61e7737
Merge branch 'main' into feat/ios_native
bitsandfoxes Jul 15, 2021
1bbc257
added Editor.iOS to solution
bitsandfoxes Jul 15, 2021
ef0fa15
renamed post process
bitsandfoxes Jul 15, 2021
c01b417
stabilize
bitsandfoxes Jul 22, 2021
75326d3
stabilize cleanup
bitsandfoxes Jul 22, 2021
64f6b30
first wip dictionary
bitsandfoxes Jul 23, 2021
20c4fbd
Merge branch 'main' into feat/ios_native
bitsandfoxes Jul 26, 2021
f929999
split build post process up
bitsandfoxes Jul 26, 2021
e2d6653
split main modifier and added tests
bitsandfoxes Jul 27, 2021
1996527
removed temp files
bitsandfoxes Jul 27, 2021
dd91db5
added cocoa as submodule
bitsandfoxes Jul 27, 2021
65c0381
added cocoa build to buildtargets
bitsandfoxes Jul 29, 2021
5d716e9
removed .framework from assets
bitsandfoxes Jul 29, 2021
644ba52
removed framework meta from gitignore for iOS targeting
bitsandfoxes Jul 29, 2021
62884dd
fixed cocoa clean
bitsandfoxes Jul 29, 2021
3849c0f
fixed plugin path
bitsandfoxes Jul 29, 2021
9a99d5c
added native options generation tests
bitsandfoxes Jul 29, 2021
45af472
tweaked native options generation
bitsandfoxes Jul 29, 2021
fc025b2
added more options to native options
bitsandfoxes Jul 30, 2021
db2d3bb
newlines are the worst.. -.-
bitsandfoxes Jul 30, 2021
718108a
csproj cleanup
bitsandfoxes Jul 30, 2021
bd2d0e2
cocoa build script cleanup
bitsandfoxes Jul 30, 2021
1fa6170
added test xcodeproj
bitsandfoxes Aug 2, 2021
9359b58
added sentry xcode project tests & added opt out options for native
bitsandfoxes Aug 2, 2021
79cc104
cleanup
bitsandfoxes Aug 2, 2021
de78c19
added ios opt out to options
bitsandfoxes Aug 3, 2021
c4a3ae2
cleanup
bitsandfoxes Aug 3, 2021
bb2f52d
removed dummy template
bitsandfoxes Aug 3, 2021
bd663e8
updated .gitignore
bitsandfoxes Aug 3, 2021
5cd5353
updated .gitignore
bitsandfoxes Aug 3, 2021
54e1e5d
package dev cleanup
bitsandfoxes Aug 3, 2021
dbef5f6
reverted unity project settings
bitsandfoxes Aug 3, 2021
7ba5cb0
removed unused variable
bitsandfoxes Aug 3, 2021
875fa0e
added framework validation
bitsandfoxes Aug 3, 2021
d380e9b
cleanup
bitsandfoxes Aug 3, 2021
3db5ce8
CI iOS module test
bitsandfoxes Aug 3, 2021
a8a5ac5
review
bitsandfoxes Aug 3, 2021
ca080e7
review #2
bitsandfoxes Aug 3, 2021
0d16af3
Merge branch 'main' into feat/ios_native
bruno-garcia Aug 3, 2021
867fec3
review
bitsandfoxes Aug 4, 2021
edd6ec7
Merge branch 'feat/ios_native' of https://github.com/getsentry/sentry…
bitsandfoxes Aug 4, 2021
67382e8
moved building cocoa into build.targets
bitsandfoxes Aug 5, 2021
7c45a87
moar review
bitsandfoxes Aug 5, 2021
f9896b2
fixed ios tool path for editor.ios
bitsandfoxes Aug 5, 2021
253484a
fixed pii option name in native options
bitsandfoxes Aug 5, 2021
a206db2
skip copying unchanged files
bitsandfoxes Aug 5, 2021
dc822a9
replaced copy testfiles target with built-in itemgroup
bitsandfoxes Aug 5, 2021
484fd99
excluded clang tests for non MacOSX platforms
bitsandfoxes Aug 5, 2021
75b5d44
review fixes
bitsandfoxes Aug 5, 2021
5a07dec
updated CHANGELOG.md
bitsandfoxes Aug 5, 2021
1d8fbde
added missing cocoa submodule restoration
bitsandfoxes Aug 5, 2021
801f50f
fixed inconsistent paths
bitsandfoxes Aug 5, 2021
36b135c
fixed restoring submodules
bitsandfoxes Aug 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/Sentry.Unity.Editor.iOS/BuildPostprocess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;

using UnityEditor.iOS.Xcode;
using UnityEditor.iOS.Xcode.Extensions;

namespace Sentry.Unity.Editor
{
public static class BuildPostprocess
{
private const string Include = "#include <Sentry/Sentry.h>\n";

private const string Init = @" [SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = @""https://94677106febe46b88b9b9ae5efd18a00@o447951.ingest.sentry.io/5439417"";
options.enableAutoSessionTracking = NO;
options.debug = YES;
}];

";

private const string FrameworkLocation = "Frameworks/Plugins/iOS"; // The path where the framework is stored
private const string FrameworkName = "Sentry.framework";

[PostProcessBuild(1)]
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
{
if (target != BuildTarget.iOS)
{
return;
}

var projectPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
var project = new PBXProject();
project.ReadFromString(File.ReadAllText(projectPath));

ModifyMain(pathToBuiltProject);

var targetGuid = project.GetUnityMainTargetGuid();
var fileGuid = project.AddFile(
Path.Combine(FrameworkLocation, FrameworkName),
Path.Combine(FrameworkLocation, FrameworkName));

project.AddFileToBuild(targetGuid, fileGuid); // Ensures that the framework shows up on 'Link Binary with Libraries'
project.AddFileToEmbedFrameworks(targetGuid, fileGuid); // Embedding the framework because it's dynamic and needed at runtime

project.SetBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", "$(inherited)");
project.AddBuildProperty(targetGuid, "FRAMEWORK_SEARCH_PATHS", $"$(PROJECT_DIR)/{FrameworkLocation}/");

// project.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");
bruno-garcia marked this conversation as resolved.
Show resolved Hide resolved

project.WriteToFile(projectPath);
}

private static void ModifyMain(string pathToBuiltProject)
bruno-garcia marked this conversation as resolved.
Show resolved Hide resolved
{
var mainPath = Path.Combine(pathToBuiltProject, "MainApp", "main.mm");
if (!File.Exists(mainPath))
{
return;
}

var text = File.ReadAllText(mainPath);

var includeRegex = new Regex(@"\#include \<Sentry\/Sentry\.h\>");
if (includeRegex.Match(text).Success)
{
return;
}

text = Include + text;

var initRegex = new Regex(@"int main\(int argc, char\* argv\[\]\)\n{\n\s+@autoreleasepool\n.\s+{\n");
var match = initRegex.Match(text);
if (match.Success)
{
Debug.Log($"great success at {match.Index}");
text = text.Insert(match.Index + match.Length, Init);
}

File.WriteAllText(mainPath, text);
}
}
}
3 changes: 3 additions & 0 deletions src/Sentry.Unity.Editor.iOS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Sentry.Unity.Editor.Tests")]
35 changes: 35 additions & 0 deletions src/Sentry.Unity.Editor.iOS/Sentry.Unity.Editor.iOS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- This assembly only stays in the Editor, so embed pdbs in the dll to help debugging -->
<DebugType>embedded</DebugType>
<OutDir>$(PackageEditorPath)/iOS</OutDir>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../sentry-dotnet/src/Sentry/Sentry.csproj">
<Private>false</Private>
</ProjectReference>
<ProjectReference Include="../Sentry.Unity/Sentry.Unity.csproj">
<Private>false</Private>
</ProjectReference>
</ItemGroup>

<!-- Add reference once we figure out where the DLL is (find Unity version and install location) -->
<Target Name="ReferenceUnityEditor" AfterTargets="FindUnity" BeforeTargets="BeforeResolveReferences">
<PropertyGroup>
<IosBuildTools>$(UnityRoot)/../PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.Xcode.dll</IosBuildTools>
</PropertyGroup>

<Error Condition="!Exists('$(IosBuildTools)')" Text="iOS build tools not found."></Error>
<ItemGroup>
<Reference Include="UnityEditor">
<HintPath>$(UnityManagedPath)/UnityEditor.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Xcode">
<HintPath>$(IosBuildTools)</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
</Target>
</Project>