diff --git a/src/UnityNuGet.Tests/RegistryTests.cs b/src/UnityNuGet.Tests/RegistryTests.cs index 288c791..60def18 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 8eb50f3..75e6cac 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) {