From e5a785e39574e03efb64ff278255cb7868ad9f20 Mon Sep 17 00:00:00 2001 From: Chris Handzlik Date: Mon, 2 Sep 2024 09:22:45 +0100 Subject: [PATCH 1/7] VisionOS will build native lib for IOS but will change XDKRoot in xcode project after to xros --- Editor/CompileCesiumForUnityNative.cs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Editor/CompileCesiumForUnityNative.cs b/Editor/CompileCesiumForUnityNative.cs index 1b8657ab..7dd29ec1 100644 --- a/Editor/CompileCesiumForUnityNative.cs +++ b/Editor/CompileCesiumForUnityNative.cs @@ -120,6 +120,8 @@ private static string GetSharedLibraryFilename(string baseName, BuildTarget targ return $"{baseName}.dll"; case BuildTarget.iOS: return $"lib{baseName}.a"; + case BuildTarget.VisionOS: + return $"lib{baseName}.a"; case BuildTarget.StandaloneOSX: return $"lib{baseName}.dylib"; default: @@ -349,7 +351,9 @@ public static LibraryToBuild GetLibraryToBuild(PlatformToBuild platform, Library library.ExtraConfigureArgs.Add("-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a"); } - if (platform.platformGroup == BuildTargetGroup.iOS) + if (platform.platformGroup == BuildTargetGroup.iOS + //VisionOS will use IOS config and SDKROOT will be changed after as currently 3rd party libs could not be compiled for xros + || platform.platformGroup == BuildTargetGroup.VisionOS) { library.Toolchain = "extern/ios-toolchain.cmake"; library.ExtraConfigureArgs.Add("-GXcode"); @@ -407,6 +411,11 @@ private static bool IsIOS(BuildTargetGroup platformGroup, BuildTarget platform) { return platformGroup == BuildTargetGroup.iOS && platform == BuildTarget.iOS; } + + private static bool IsVisionOS(BuildTargetGroup platformGroup, BuildTarget platform) + { + return platformGroup == BuildTargetGroup.VisionOS && platform == BuildTarget.VisionOS; + } private static string GetDirectoryNameForPlatform(PlatformToBuild platform) { @@ -419,6 +428,8 @@ private static string GetDirectoryNameForPlatform(BuildTargetGroup platformGroup return "Editor"; else if (IsIOS(platformGroup, platform)) return "iOS"; + else if (IsVisionOS(platformGroup, platform)) + return "VisionOS"; // Make sure we use "WSA" and not "Metro" else if (platformGroup == BuildTargetGroup.WSA) return "WSA"; @@ -450,7 +461,7 @@ internal static void BuildNativeLibrary(LibraryToBuild library) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.UseShellExecute = false; - if (library.Platform == BuildTarget.StandaloneOSX || library.Platform == BuildTarget.iOS) + if (library.Platform == BuildTarget.StandaloneOSX || library.Platform == BuildTarget.iOS || library.Platform == BuildTarget.VisionOS) { startInfo.FileName = File.Exists("/Applications/CMake.app/Contents/bin/cmake") ? "/Applications/CMake.app/Contents/bin/cmake" : "cmake"; } @@ -483,7 +494,15 @@ internal static void BuildNativeLibrary(LibraryToBuild library) startInfo.Arguments = string.Join(' ', args); RunAndLog(startInfo, log, logFilename); - + + if (IsVisionOS(library.PlatformGroup, library.Platform)) + { + var xcodeProjectPath = Path.Combine(library.BuildDirectory, "CesiumForUnityNative.xcodeproj/project.pbxproj"); + var originalXcodeContents = File.ReadAllText(xcodeProjectPath); + var xcodeContentsTargetedToXros = originalXcodeContents.Replace("SDKROOT = iphoneos;", "SDKROOT = xros;"); + File.WriteAllText(xcodeProjectPath, xcodeContentsTargetedToXros); + } + args = new List() { "--build", @@ -499,7 +518,7 @@ internal static void BuildNativeLibrary(LibraryToBuild library) startInfo.Arguments = string.Join(' ', args); RunAndLog(startInfo, log, logFilename); - if (library.Platform == BuildTarget.iOS) + if (library.Platform == BuildTarget.iOS || library.Platform == BuildTarget.VisionOS) AssetDatabase.Refresh(); } } From ab1f6350d4b8d352abae259e8f31bc86df4b515e Mon Sep 17 00:00:00 2001 From: Chris Handzlik Date: Mon, 2 Sep 2024 09:24:11 +0100 Subject: [PATCH 2/7] reinterop will run for VisionOS --- Editor/ConfigureReinterop.cs | 4 +++- Runtime/ConfigureReinterop.cs | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Editor/ConfigureReinterop.cs b/Editor/ConfigureReinterop.cs index 5f5fc3a0..edc012ac 100644 --- a/Editor/ConfigureReinterop.cs +++ b/Editor/ConfigureReinterop.cs @@ -22,6 +22,8 @@ internal partial class ConfigureReinterop public const string CppOutputPath = "../native~/Editor/generated-Android"; #elif UNITY_IOS public const string CppOutputPath = "../native~/Editor/generated-iOS"; +#elif UNITY_VISIONOS + public const string CppOutputPath = "../native~/Editor/generated-VisionOS"; #elif UNITY_WSA public const string CppOutputPath = "../native~/Runtime/generated-WSA"; #elif UNITY_64 @@ -37,7 +39,7 @@ internal partial class ConfigureReinterop // The name of the DLL or SO containing the C++ code. public const string NativeLibraryName = "CesiumForUnityNative-Editor"; - + // Comma-separated types to treat as non-blittable, even if their fields would // otherwise cause Reinterop to treat them as blittable. public const string NonBlittableTypes = "Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle,Unity.Collections.NativeArray,UnityEngine.MeshData,UnityEngine.MeshDataArray"; diff --git a/Runtime/ConfigureReinterop.cs b/Runtime/ConfigureReinterop.cs index c674fbc0..95657603 100644 --- a/Runtime/ConfigureReinterop.cs +++ b/Runtime/ConfigureReinterop.cs @@ -31,6 +31,8 @@ internal partial class ConfigureReinterop public const string CppOutputPath = "../native~/Runtime/generated-Android"; #elif UNITY_IOS public const string CppOutputPath = "../native~/Runtime/generated-iOS"; +#elif UNITY_VISIONOS + public const string CppOutputPath = "../native~/Runtime/generated-VisionOS"; #elif UNITY_WSA public const string CppOutputPath = "../native~/Runtime/generated-WSA"; #elif UNITY_64 @@ -45,7 +47,7 @@ internal partial class ConfigureReinterop public const string BaseNamespace = "DotNet"; // The name of the DLL or SO containing the C++ code. -#if UNITY_IOS && !UNITY_EDITOR +#if (UNITY_IOS || UNITY_VISIONOS) && !UNITY_EDITOR public const string NativeLibraryName = "__Internal"; #else public const string NativeLibraryName = "CesiumForUnityNative-Runtime"; @@ -336,7 +338,7 @@ public void ExposeToCPP() CesiumWebMapTileServiceRasterOverlay webMapTileServiceRasterOverlay = go.GetComponent(); - webMapTileServiceRasterOverlay.baseUrl = webMapTileServiceRasterOverlay.baseUrl; + webMapTileServiceRasterOverlay.baseUrl = webMapTileServiceRasterOverlay.baseUrl; webMapTileServiceRasterOverlay.layer = webMapTileServiceRasterOverlay.layer; webMapTileServiceRasterOverlay.style = webMapTileServiceRasterOverlay.style; webMapTileServiceRasterOverlay.format = webMapTileServiceRasterOverlay.format; From 288e128592cd2c65cfa00ad2745675824d722745 Mon Sep 17 00:00:00 2001 From: Chris Handzlik Date: Tue, 3 Sep 2024 12:06:56 +0100 Subject: [PATCH 3/7] vision os libs will have their CPU set to ARM64 otherwise they won't be copied to xcode Libraries folder --- Editor/CompileCesiumForUnityNative.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Editor/CompileCesiumForUnityNative.cs b/Editor/CompileCesiumForUnityNative.cs index 7dd29ec1..90cd7723 100644 --- a/Editor/CompileCesiumForUnityNative.cs +++ b/Editor/CompileCesiumForUnityNative.cs @@ -170,6 +170,10 @@ private static void ConfigurePlugin(LibraryToBuild library, PluginImporter impor UnityEngine.Debug.LogAssertion("Unsupported processor: " + library.Cpu); importer.SetPlatformData(library.Platform, "CPU", wsaPlatform); } + else if (library.Platform == BuildTarget.VisionOS) + { + importer.SetPlatformData(library.Platform, "CPU", "ARM64"); + } } private static void OnPostprocessAllAssets( From a08337ab35fcc29517173994e5f890c4846c619a Mon Sep 17 00:00:00 2001 From: Chris Handzlik Date: Tue, 3 Sep 2024 12:08:17 +0100 Subject: [PATCH 4/7] added xcode proj file existence check before adjustments --- Editor/CompileCesiumForUnityNative.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Editor/CompileCesiumForUnityNative.cs b/Editor/CompileCesiumForUnityNative.cs index 90cd7723..49e47cd7 100644 --- a/Editor/CompileCesiumForUnityNative.cs +++ b/Editor/CompileCesiumForUnityNative.cs @@ -502,9 +502,16 @@ internal static void BuildNativeLibrary(LibraryToBuild library) if (IsVisionOS(library.PlatformGroup, library.Platform)) { var xcodeProjectPath = Path.Combine(library.BuildDirectory, "CesiumForUnityNative.xcodeproj/project.pbxproj"); - var originalXcodeContents = File.ReadAllText(xcodeProjectPath); - var xcodeContentsTargetedToXros = originalXcodeContents.Replace("SDKROOT = iphoneos;", "SDKROOT = xros;"); - File.WriteAllText(xcodeProjectPath, xcodeContentsTargetedToXros); + if (File.Exists(xcodeProjectPath)) + { + var originalXcodeContents = File.ReadAllText(xcodeProjectPath); + var xcodeContentsTargetedToXros = originalXcodeContents.Replace("SDKROOT = iphoneos;", "SDKROOT = xros;"); + File.WriteAllText(xcodeProjectPath, xcodeContentsTargetedToXros); + } + else + { + UnityEngine.Debug.Log("Xcode project does not exist, unable to change target to VisionOs"); + } } args = new List() From 26a414558f3bf9e05bbb55ce0b7b538365ab9609 Mon Sep 17 00:00:00 2001 From: Chris Handzlik Date: Tue, 3 Sep 2024 12:41:51 +0100 Subject: [PATCH 5/7] additional libraries will also have ARM64 CPU set for them on Vision Pro --- Editor/CompileCesiumForUnityNative.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Editor/CompileCesiumForUnityNative.cs b/Editor/CompileCesiumForUnityNative.cs index 49e47cd7..2bc1ff1c 100644 --- a/Editor/CompileCesiumForUnityNative.cs +++ b/Editor/CompileCesiumForUnityNative.cs @@ -173,6 +173,18 @@ private static void ConfigurePlugin(LibraryToBuild library, PluginImporter impor else if (library.Platform == BuildTarget.VisionOS) { importer.SetPlatformData(library.Platform, "CPU", "ARM64"); + + var projectPath = Application.dataPath.Replace("Assets", ""); + foreach (var libFilePath in Directory.EnumerateFiles(library.InstallDirectory, "*.a", SearchOption.AllDirectories)) + { + var libRelativeFilePath = libFilePath.Replace(projectPath, ""); + var libPluginImporter = AssetImporter.GetAtPath(libRelativeFilePath) as PluginImporter; + + if (libPluginImporter != null) + { + libPluginImporter.SetPlatformData(library.Platform, "CPU", "ARM64"); + } + } } } From f5e79cf83d76540225f585db1ad5113267476195 Mon Sep 17 00:00:00 2001 From: Chris Handzlik Date: Tue, 3 Sep 2024 12:46:48 +0100 Subject: [PATCH 6/7] added duplicate symbol libs workaround so they are not included in xcode build - likely will cause issues --- Editor/CompileCesiumForUnityNative.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Editor/CompileCesiumForUnityNative.cs b/Editor/CompileCesiumForUnityNative.cs index 2bc1ff1c..45af5b34 100644 --- a/Editor/CompileCesiumForUnityNative.cs +++ b/Editor/CompileCesiumForUnityNative.cs @@ -8,6 +8,7 @@ using System.Text; using System; using System.Collections.Generic; +using System.Linq; #if UNITY_ANDROID using UnityEditor.Android; #endif @@ -174,9 +175,18 @@ private static void ConfigurePlugin(LibraryToBuild library, PluginImporter impor { importer.SetPlatformData(library.Platform, "CPU", "ARM64"); + // TODO: WARN: this will likely cause issues, why native build generates those libs? Where are they needed? + var duplicatedSymbolsExcludeLibs = new string[] { + "libjpeg.a", + "libwebp.a" + }; + var projectPath = Application.dataPath.Replace("Assets", ""); foreach (var libFilePath in Directory.EnumerateFiles(library.InstallDirectory, "*.a", SearchOption.AllDirectories)) { + if(duplicatedSymbolsExcludeLibs.Any(l => libFilePath.EndsWith(l))) + continue; + var libRelativeFilePath = libFilePath.Replace(projectPath, ""); var libPluginImporter = AssetImporter.GetAtPath(libRelativeFilePath) as PluginImporter; From 163dbcd23fe032fcc1b63465ce1d891e495645df Mon Sep 17 00:00:00 2001 From: Chris Handzlik Date: Tue, 3 Sep 2024 12:47:13 +0100 Subject: [PATCH 7/7] visionOs will use same config as IOS --- Editor/CompileCesiumForUnityNative.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Editor/CompileCesiumForUnityNative.cs b/Editor/CompileCesiumForUnityNative.cs index 45af5b34..99d5d7b2 100644 --- a/Editor/CompileCesiumForUnityNative.cs +++ b/Editor/CompileCesiumForUnityNative.cs @@ -377,9 +377,7 @@ public static LibraryToBuild GetLibraryToBuild(PlatformToBuild platform, Library library.ExtraConfigureArgs.Add("-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a"); } - if (platform.platformGroup == BuildTargetGroup.iOS - //VisionOS will use IOS config and SDKROOT will be changed after as currently 3rd party libs could not be compiled for xros - || platform.platformGroup == BuildTargetGroup.VisionOS) + if (platform.platformGroup == BuildTargetGroup.iOS || platform.platformGroup == BuildTargetGroup.VisionOS) { library.Toolchain = "extern/ios-toolchain.cmake"; library.ExtraConfigureArgs.Add("-GXcode");