Skip to content

Commit f0911d8

Browse files
jared-marsauGitHub Enterprise
authored and
GitHub Enterprise
committed
Apple.Core support for plug-ins without native libraries (apple#35)
* Adding support for Apple Unity Plug-Ins which don't require native libraries and may or may not define a custom build step. * Version bump
1 parent 5dba688 commit f0911d8

File tree

8 files changed

+123
-53
lines changed

8 files changed

+123
-53
lines changed

Diff for: plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# CHANGELOG
22
All notable changes to this project will be documented in this file.
33

4-
## [3.1.0] - 2024-2-23
4+
## [3.1.1] - 2024-04-08
5+
### Added
6+
- Adding support for tracking of Apple Unity plug-ins without native libraries.
7+
8+
## [3.1.0] - 2024-02-23
59
### Added
610
Support for visionOS
711

8-
## [3.0.0] - 2024-2-15
12+
## [3.0.0] - 2024-02-15
913
### Added
1014
- Support for iPhone simulator and AppleTV Simulator
1115
- Release builds now generate .dSYM files for enhanced debugging abilities

Diff for: plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Editor/AppleBuildProfile.cs

+18
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ public void ResolveBuildSteps()
109109
}
110110
}
111111
}
112+
113+
/// <summary>
114+
/// Find a build step based upon it's DisplayName property.
115+
/// </summary>
116+
/// <param name="displayName">A string which corresponds to a given build step's DisplayName property.</param>
117+
/// <returns></returns>
118+
public AppleBuildStep FindBuildStep(string displayName)
119+
{
120+
foreach (var buildStep in buildSteps.Values)
121+
{
122+
if (buildStep.DisplayName == displayName)
123+
{
124+
return buildStep;
125+
}
126+
}
127+
128+
return null;
129+
}
112130
}
113131
}
114132
#endif // (UNITY_EDITOR_OSX && (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX || UNITY_VISIONOS))

Diff for: plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Editor/AppleBuildStep.cs

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public class AppleBuildStep : ScriptableObject
2828
/// </summary>
2929
public virtual BuildTarget[] SupportedTargets => Array.Empty<BuildTarget>();
3030

31+
/// <summary>
32+
/// Convenience property to determine if the plug-in has associated native libraries.
33+
/// </summary>
34+
public bool IsNativePlugIn => SupportedTargets.Length > 0;
35+
3136
/// <summary>
3237
/// Returns an enumerable collection of all objects in the project which derive from AppleBuildStep
3338
/// </summary>

Diff for: plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Editor/ApplePlugInEnvironment.cs

+64-48
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,18 @@ private static void OnEditorUpdate()
196196
// If this is one of the development Apple plug-in Unity projects, it needs to be handled as a special case because
197197
// it isn't loaded/managed by the package manager; all of the assets are local under Assets/
198198
// All Apple plug-ins will have an AppleBuildStep implementation, so check for build steps that haven't been added already
199-
foreach (var buildStepEntry in _defaultProfile.buildSteps)
199+
foreach (var buildStep in _defaultProfile.buildSteps.Values)
200200
{
201-
if (buildStepEntry.Value.SupportedTargets.Length > 0 && !_appleUnityPackages.ContainsKey(buildStepEntry.Value.DisplayName))
201+
if (!_appleUnityPackages.ContainsKey(buildStep.DisplayName))
202202
{
203-
_appleUnityPackages[buildStepEntry.Value.DisplayName] = new AppleUnityPackage("Local Project", buildStepEntry.Value.DisplayName, Application.dataPath);
203+
if (buildStep.IsNativePlugIn)
204+
{
205+
_appleUnityPackages[buildStep.DisplayName] = new AppleUnityPackage("Local Project", buildStep.DisplayName, Application.dataPath);
206+
}
207+
else
208+
{
209+
_appleUnityPackages[buildStep.DisplayName] = new AppleUnityPackage("Local Project", buildStep.DisplayName);
210+
}
204211
}
205212
}
206213

@@ -244,42 +251,30 @@ private static void ValidateLibraries()
244251
{
245252
foreach (var applePackage in _appleUnityPackages.Values)
246253
{
247-
bool isCurrentPlatformSupported = false;
248-
bool isBuildStepEnabled = false;
249-
foreach(var buildStep in _defaultProfile.buildSteps.Values)
254+
AppleBuildStep buildStep = _defaultProfile.FindBuildStep(applePackage.DisplayName);
255+
if (buildStep != null && buildStep.IsNativePlugIn)
250256
{
251-
if (buildStep.DisplayName == applePackage.DisplayName)
257+
if (Array.IndexOf(buildStep.SupportedTargets, GetUnityBuildTarget(_trackedApplePlatform)) > -1)
252258
{
253-
isBuildStepEnabled = buildStep.IsEnabled;
254-
BuildTarget unityBuildTarget = GetUnityBuildTarget(_trackedApplePlatform);
255-
if (Array.IndexOf(buildStep.SupportedTargets, unityBuildTarget) > -1)
259+
AppleNativeLibrary currLibrary = GetLibrary(applePackage.DisplayName, _trackedAppleConfig.Principal, _trackedApplePlatform);
260+
if (!currLibrary.IsValid)
256261
{
257-
isCurrentPlatformSupported = true;
258-
break;
262+
string warningMessage = $"[Apple Unity Plug-Ins] Missing {_trackedAppleConfig.Principal} {applePackage.DisplayName} native library for {_trackedApplePlatform}\n"
263+
+ $" {_trackedAppleConfig.Fallback} {applePackage.DisplayName} native library for {_trackedApplePlatform} will be used as a fallback.\n"
264+
+ $" To generate the {_trackedAppleConfig.Principal} native library for {applePackage.DisplayName}, try re-building the {applePackage.DisplayName} plug-in with the following command line (assuming the working directory is the Apple Unity Plug-In project root folder):\n\n"
265+
+ $" <b><color=orange>$> python3 ./build.py -p {applePackage.ShortName}</color></b>\n";
266+
267+
Debug.LogWarning(warningMessage);
259268
}
260269
}
261-
}
262-
263-
if (isCurrentPlatformSupported)
264-
{
265-
AppleNativeLibrary currLibrary = GetLibrary(applePackage.DisplayName, _trackedAppleConfig.Principal, _trackedApplePlatform);
266-
if (!currLibrary.IsValid)
270+
else if (buildStep.IsEnabled)
267271
{
268-
string warningMessage = $"[Apple Unity Plug-Ins] Missing {_trackedAppleConfig.Principal} {applePackage.DisplayName} native library for {_trackedApplePlatform}\n"
269-
+ $" {_trackedAppleConfig.Fallback} {applePackage.DisplayName} native library for {_trackedApplePlatform} will be used as a fallback.\n"
270-
+ $" To generate the {_trackedAppleConfig.Principal} native library for {applePackage.DisplayName}, try re-building the {applePackage.DisplayName} plug-in with the following command line (assuming the working directory is the Apple Unity Plug-In project root folder):\n\n"
271-
+ $" <b><color=orange>$> python3 ./build.py -p {applePackage.ShortName}</color></b>\n";
272+
string warningMessage = $"[Apple Unity Plug-Ins] Targeting unsupported platform '{_trackedApplePlatform}' for Apple plug-in package {applePackage.DisplayName}.\n"
273+
+ $" To continue building for the current platform, please disable {applePackage.DisplayName} in the Apple Build Settings window.";
272274

273275
Debug.LogWarning(warningMessage);
274276
}
275277
}
276-
else if (isBuildStepEnabled)
277-
{
278-
string warningMessage = $"[Apple Unity Plug-Ins] Targeting unsupported platform '{_trackedApplePlatform}' for Apple plug-in package {applePackage.DisplayName}.\n"
279-
+ $" To continue building for the current platform, please disable {applePackage.DisplayName} in the Apple Build Settings window.";
280-
281-
Debug.LogWarning(warningMessage);
282-
}
283278
}
284279
}
285280

@@ -391,10 +386,16 @@ public static AppleNativeLibrary GetLibrary(string packageDisplayName, string ap
391386
/// <param name="packageCollection">An iterable collection of PackageInfo structs</param>
392387
private static void AddPackagesFromCollection(IEnumerable<UnityEditor.PackageManager.PackageInfo> packageCollection, bool logPackagesAfterUpdate = true)
393388
{
389+
// Ensure collection of build steps is current; package names will be validated against build step names.
390+
_defaultProfile.ResolveBuildSteps();
391+
394392
bool packagesAdded = false;
395393
foreach (var unityPackage in packageCollection)
396394
{
397-
if (unityPackage.name.StartsWith(AppleUnityPackageNamePrefix) && unityPackage.author.name == AppleUnityPackageAuthorName && !_appleUnityPackages.ContainsKey(unityPackage.displayName))
395+
AppleBuildStep buildStep = _defaultProfile.FindBuildStep(unityPackage.displayName);
396+
397+
// Apple packages with native libraries will always have a build step defined for handling those libraries, so validate here.
398+
if (buildStep != null && buildStep.IsNativePlugIn && buildStep.DisplayName == unityPackage.displayName && unityPackage.author.name == AppleUnityPackageAuthorName && !_appleUnityPackages.ContainsKey(unityPackage.displayName))
398399
{
399400
AppleUnityPackage applePackage = new AppleUnityPackage(unityPackage.name, unityPackage.displayName, unityPackage.resolvedPath);
400401
if (!applePackage.PlayModeSupportLibrary.IsValid)
@@ -407,6 +408,14 @@ private static void AddPackagesFromCollection(IEnumerable<UnityEditor.PackageMan
407408
_appleUnityPackages[applePackage.DisplayName] = applePackage;
408409
packagesAdded = true;
409410
}
411+
// If there's no build step or the build step isn't associated with a native plug-in track the library-free (C# only) package.
412+
else if (unityPackage.name.StartsWith(AppleUnityPackageNamePrefix) && unityPackage.author.name == AppleUnityPackageAuthorName && !_appleUnityPackages.ContainsKey(unityPackage.displayName))
413+
{
414+
AppleUnityPackage applePackage = new AppleUnityPackage(unityPackage.name, unityPackage.displayName);
415+
_appleUnityPackages[applePackage.DisplayName] = applePackage;
416+
packagesAdded = true;
417+
}
418+
410419
}
411420

412421
if (packagesAdded && logPackagesAfterUpdate)
@@ -471,35 +480,42 @@ private static void SyncronizePlayModeSupportLibraries()
471480
/// </summary>
472481
private static void LogLibrarySummary()
473482
{
474-
string summary = "[Apple Unity Plug-ins] Apple native plug-ins updated.\nTracking the following plug-in packages and native libraries:\n\n";
483+
string summary = "[Apple Unity Plug-ins] Apple native plug-ins updated.\nTracking the following plug-in packages and native libraries:\n";
475484
bool librariesFound = false;
476485
foreach (AppleUnityPackage package in _appleUnityPackages.Values)
477486
{
478-
summary += $"\n<b>{package.DisplayName}</b> [{package.Name}]:\n Package Source Path: {package.SourcePath}\n";
479-
var debugLibraries = package.GetLibraries(AppleConfigID.Debug);
480-
if (debugLibraries.Length > 0)
487+
if (package.IsNativePackage)
481488
{
482-
summary += " Debug Libraries (file name - platform):\n";
483-
foreach (var debugLibrary in debugLibraries)
489+
summary += $"\n<b>{package.DisplayName}</b> [{package.Name}]:\n Package Source Path: {package.SourcePath}\n";
490+
var debugLibraries = package.GetLibraries(AppleConfigID.Debug);
491+
if (debugLibraries.Length > 0)
484492
{
485-
summary += $" {debugLibrary.FileName} - {debugLibrary.Platform}\n";
493+
summary += " Debug Libraries (file name - platform):\n";
494+
foreach (var debugLibrary in debugLibraries)
495+
{
496+
summary += $" {debugLibrary.FileName} - {debugLibrary.Platform}\n";
497+
}
498+
librariesFound = true;
486499
}
487-
librariesFound = true;
488-
}
489500

490-
var releaseLibraries = package.GetLibraries(AppleConfigID.Release);
491-
if (releaseLibraries.Length > 0)
492-
{
493-
summary += " Release Libraries (file name - platform):\n";
494-
foreach (var releaseLibrary in releaseLibraries)
501+
var releaseLibraries = package.GetLibraries(AppleConfigID.Release);
502+
if (releaseLibraries.Length > 0)
495503
{
496-
summary += $" {releaseLibrary.FileName} - {releaseLibrary.Platform}\n";
497-
if (releaseLibrary.DebugSymbolsFileName != string.Empty)
504+
summary += " Release Libraries (file name - platform):\n";
505+
foreach (var releaseLibrary in releaseLibraries)
498506
{
499-
summary += $" {releaseLibrary.DebugSymbolsFileName} - {releaseLibrary.Platform}\n";
507+
summary += $" {releaseLibrary.FileName} - {releaseLibrary.Platform}\n";
508+
if (releaseLibrary.DebugSymbolsFileName != string.Empty)
509+
{
510+
summary += $" {releaseLibrary.DebugSymbolsFileName} - {releaseLibrary.Platform}\n";
511+
}
500512
}
513+
librariesFound = true;
501514
}
502-
librariesFound = true;
515+
}
516+
else
517+
{
518+
summary += $"\n<b>{package.DisplayName}</b> [{package.Name}]:\n Non-native (C# Script or asset only) plug-in/extension.\n <b>No libraries to list.</b>\n";
503519
}
504520
}
505521

Diff for: plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Editor/AppleSecurityBuildStep.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Apple.Core
99
{
1010
public class AppleSecurityBuildStep : AppleBuildStep
1111
{
12-
public override string DisplayName => "Security";
12+
public override string DisplayName => "Apple.Core.Security";
1313

1414
[Tooltip("If true, will add the com.apple.security.app-sandbox entitlement.")]
1515
public bool AppSandboxEntitlement = true;

Diff for: plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Editor/AppleUnityPackage.cs

+27
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public AppleUnityPackage(string name, string displayName, string packageSystemPa
2323
DisplayName = displayName;
2424
PlayModeSupportLibrary = AppleNativeLibrary.Invalid;
2525
SourcePath = packageSystemPath;
26+
IsNativePackage = true;
2627

2728
_nativeLibraryCollection = new Dictionary<string, Dictionary<string, AppleNativeLibrary>>();
2829

@@ -97,6 +98,22 @@ public AppleUnityPackage(string name, string displayName, string packageSystemPa
9798
}
9899
}
99100

101+
/// <summary>
102+
/// Create a package with default values to act as a representation of a package without native libraries.
103+
/// </summary>
104+
/// <param name="name">Matches the 'name' field of the associated package's <c>package.json</c> file. Should be of the form <c>com.apple.unityplugin.XXX</c>.</param>
105+
/// <param name="displayName">Matches the 'displayName' field of the associated package's <c>package.json</c> file</param>
106+
public AppleUnityPackage(string name, string displayName)
107+
{
108+
Name = name;
109+
DisplayName = displayName;
110+
IsNativePackage = false;
111+
112+
PlayModeSupportLibrary = AppleNativeLibrary.Invalid;
113+
SourcePath = string.Empty;
114+
_nativeLibraryCollection = new Dictionary<string, Dictionary<string, AppleNativeLibrary>>();
115+
}
116+
100117
/// <summary>
101118
/// Matches the 'name' field of the associated package's <c>package.json</c> file.
102119
/// </summary>
@@ -129,6 +146,11 @@ public AppleUnityPackage(string name, string displayName, string packageSystemPa
129146
/// Records the source of the package in the local file system.
130147
/// </summary>
131148
public string SourcePath { get; private set; }
149+
150+
/// <summary>
151+
/// True when this package references native libraries.
152+
/// </summary>
153+
public bool IsNativePackage { get; private set; }
132154

133155
/// <summary>
134156
/// Helper will get an AppleNativeLibrary for the provided config and platform combination, returning an invalid AppleNativeLibrary if none exists.
@@ -152,6 +174,11 @@ public AppleNativeLibrary GetLibrary(string appleConfig, string applePlatform)
152174
/// <returns>The flattened array of AppleNativeLibrary elements for this package.</returns>
153175
public AppleNativeLibrary[] GetLibraries(string appleConfig = "")
154176
{
177+
if (!IsNativePackage)
178+
{
179+
return Array.Empty<AppleNativeLibrary>();
180+
}
181+
155182
List<AppleNativeLibrary> libraries = new List<AppleNativeLibrary>();
156183
if (appleConfig == AppleConfigID.Debug || appleConfig == AppleConfigID.Release)
157184
{

Diff for: plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/Editor/AppleUserManagementBuildStep.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Apple.Core
99
{
1010
public class AppleUserManagementBuildStep : AppleBuildStep
1111
{
12-
public override string DisplayName => "tvOS User Management";
12+
public override string DisplayName => "Apple.Core.UserManagementForAppleTV";
1313

1414
[Tooltip("The value that grants access to TVUserManager, so you can map your own profiles to users in the system.")]
1515
public bool AllowGetCurrentUser = false;

Diff for: plug-ins/Apple.Core/Apple.Core_Unity/Assets/Apple.Core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.apple.unityplugin.core",
33
"displayName": "Apple.Core",
44
"description": "Provides project settings, post-build automation tools, and other shared functionality for Apple Unity Plug-ins.",
5-
"version": "3.1.0",
5+
"version": "3.1.1",
66
"unity": "2022.3",
77
"keywords": [
88
"apple"

0 commit comments

Comments
 (0)