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

WIP Added Vision Pro build support #502

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
58 changes: 54 additions & 4 deletions Editor/CompileCesiumForUnityNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_ANDROID
using UnityEditor.Android;
#endif
Expand Down Expand Up @@ -120,6 +121,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:
Expand Down Expand Up @@ -168,6 +171,31 @@ 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");

// 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;

if (libPluginImporter != null)
{
libPluginImporter.SetPlatformData(library.Platform, "CPU", "ARM64");
}
}
}
}

private static void OnPostprocessAllAssets(
Expand Down Expand Up @@ -349,7 +377,7 @@ 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 || platform.platformGroup == BuildTargetGroup.VisionOS)
{
library.Toolchain = "extern/ios-toolchain.cmake";
library.ExtraConfigureArgs.Add("-GXcode");
Expand Down Expand Up @@ -407,6 +435,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)
{
Expand All @@ -419,6 +452,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";
Expand Down Expand Up @@ -450,7 +485,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";
}
Expand Down Expand Up @@ -483,7 +518,22 @@ 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");
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<string>()
{
"--build",
Expand All @@ -499,7 +549,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();
}
}
Expand Down
4 changes: 3 additions & 1 deletion Editor/ConfigureReinterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down
6 changes: 4 additions & 2 deletions Runtime/ConfigureReinterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down Expand Up @@ -336,7 +338,7 @@ public void ExposeToCPP()

CesiumWebMapTileServiceRasterOverlay webMapTileServiceRasterOverlay =
go.GetComponent<CesiumWebMapTileServiceRasterOverlay>();
webMapTileServiceRasterOverlay.baseUrl = webMapTileServiceRasterOverlay.baseUrl;
webMapTileServiceRasterOverlay.baseUrl = webMapTileServiceRasterOverlay.baseUrl;
webMapTileServiceRasterOverlay.layer = webMapTileServiceRasterOverlay.layer;
webMapTileServiceRasterOverlay.style = webMapTileServiceRasterOverlay.style;
webMapTileServiceRasterOverlay.format = webMapTileServiceRasterOverlay.format;
Expand Down