From 7a55aa3dbca9dd91956a2ec34e67d09d23156f13 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 17 Jan 2026 11:31:58 +0900 Subject: [PATCH] Add macOS Universal Binary runtime support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support osx (without architecture suffix) runtime identifier for native libraries, enabling Universal Binary packages that work on both Intel and Apple Silicon Macs. Changes: - Modified NativeLibraries.cs to accept osx runtime identifier without architecture - Use UnityCpu.AnyCpu for osx Universal Binary native libraries - Added test case for osx Universal Binary native libraries Related: https://github.com/GlitchEnzo/NuGetForUnity/pull/744 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/UnityNuGet.Tests/RegistryTests.cs | 34 +++++++++++++++++++++++++++ src/UnityNuGet/NativeLibraries.cs | 24 ++++++++++++------- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/UnityNuGet.Tests/RegistryTests.cs b/src/UnityNuGet.Tests/RegistryTests.cs index 288c791b..60def187 100644 --- a/src/UnityNuGet.Tests/RegistryTests.cs +++ b/src/UnityNuGet.Tests/RegistryTests.cs @@ -124,6 +124,40 @@ public async Task CanParse_PackageWithRuntimes() Assert.That(libFiles.SetEquals(runtimeFiles), Is.True); } + [Test] + public async Task CanParse_PackageWithOsxUniversalNative() + { + NuGetConsoleTestLogger logger = new(); + SourceCacheContext cache = new(); + ISettings settings = Settings.LoadDefaultSettings(root: null); + SourceRepository repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json"); + + // Fetch a package that has osx (Universal Binary) native libraries + // Example: MongoDB.Libmongocrypt or similar packages with runtimes/osx/native/*.dylib + DownloadResourceResult downloadResult = await PackageDownloader.GetDownloadResourceResultAsync( + [repository], + new PackageIdentity("MongoDB.Libmongocrypt", new NuGetVersion(1, 11, 0)), + new PackageDownloadContext(cache), + SettingsUtility.GetGlobalPackagesFolder(settings), + logger, CancellationToken.None); + + // Make sure we have native libraries for osx (Universal Binary) + List<(string file, string[] folders, UnityOs os, UnityCpu cpu)> nativeLibs = await NativeLibraries + .GetSupportedNativeLibsAsync(downloadResult.PackageReader, logger) + .ToListAsync(); + + // Should have at least one osx native library + Assert.That(nativeLibs, Is.Not.Empty); + + // Make sure we have osx native libraries with AnyCpu (Universal Binary) + PlatformDefinition platformDefs = PlatformDefinition.CreateAllPlatforms(); + PlatformDefinition? osxUniversal = platformDefs.Find(UnityOs.OSX, UnityCpu.AnyCpu); + Assert.That(osxUniversal, Is.Not.Null, "OSX Universal Binary platform definition should exist"); + + bool hasOsxUniversal = nativeLibs.Any(lib => lib.os == UnityOs.OSX && lib.cpu == UnityCpu.AnyCpu); + Assert.That(hasOsxUniversal, Is.True, "Should have at least one osx Universal Binary native library"); + } + static async Task AllRegistries() { LoggerFactory loggerFactory = new(); diff --git a/src/UnityNuGet/NativeLibraries.cs b/src/UnityNuGet/NativeLibraries.cs index 8eb50f3b..75e6cacd 100644 --- a/src/UnityNuGet/NativeLibraries.cs +++ b/src/UnityNuGet/NativeLibraries.cs @@ -30,9 +30,9 @@ static class NativeLibraries string[] system = folders[1].Split('-'); - if (system.Length != 2) + if (system.Length < 1) { - logger.LogInformation($"Skipping file located in the runtime folder that does not specify platform and architecture: {file} ..."); + logger.LogInformation($"Skipping file located in the runtime folder that does not specify platform: {file} ..."); continue; } @@ -51,13 +51,21 @@ static class NativeLibraries continue; } - UnityCpu? cpu = system[1] switch + UnityCpu? cpu = null; + if (system.Length > 1) { - "x86" => UnityCpu.X86, - "x64" => UnityCpu.X64, - "arm64" => UnityCpu.ARM64, - _ => null - }; + cpu = system[1] switch + { + "x86" => UnityCpu.X86, + "x64" => UnityCpu.X64, + "arm64" => UnityCpu.ARM64, + _ => null + }; + } + else if (os == UnityOs.OSX) + { + cpu = UnityCpu.AnyCpu; + } if (cpu is null) {