Skip to content
Merged
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
34 changes: 34 additions & 0 deletions src/UnityNuGet.Tests/RegistryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestCaseData[]> AllRegistries()
{
LoggerFactory loggerFactory = new();
Expand Down
24 changes: 16 additions & 8 deletions src/UnityNuGet/NativeLibraries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)
{
Expand Down