Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Aug 29, 2024
1 parent c01a7ab commit 81dcdaf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 43 deletions.
14 changes: 7 additions & 7 deletions src/Imageflow.AllPlatforms/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
},
"Microsoft.IO.RecyclableMemoryStream": {
"type": "Transitive",
"resolved": "3.0.0",
"contentHash": "irv0HuqoH8Ig5i2fO+8dmDNdFdsrO+DoQcedwIlb810qpZHBNQHZLW7C/AHBQDgLLpw2T96vmMAy/aE4Yj55Sg==",
"resolved": "3.0.1",
"contentHash": "s/s20YTVY9r9TPfTrN5g8zPF1YhwxyqO6PxUkrYTGI2B+OGPe9AdajWZrLhFqXIvqIW23fnUE4+ztrUWNU1+9g==",
"dependencies": {
"System.Memory": "4.5.5"
}
Expand Down Expand Up @@ -150,14 +150,14 @@
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[8.0.2, )",
"resolved": "8.0.2",
"contentHash": "hKTrehpfVzOhAz0mreaTAZgbz0DrMEbWq4n3hAo8Ks6WdxdqQhNPvzOqn9VygKuWf1bmxPdraqzTaXriO/sn0A=="
"requested": "[8.0.5, )",
"resolved": "8.0.5",
"contentHash": "4ISW1Ndgz86FkIbu5rVlMqhhtojdy5rUlxC/N+9kPh9qbYcvHiCvYbHKzAPVIx9OPYIjT9trXt7JI42Y5Ukq6A=="
},
"Microsoft.IO.RecyclableMemoryStream": {
"type": "Transitive",
"resolved": "3.0.0",
"contentHash": "irv0HuqoH8Ig5i2fO+8dmDNdFdsrO+DoQcedwIlb810qpZHBNQHZLW7C/AHBQDgLLpw2T96vmMAy/aE4Yj55Sg=="
"resolved": "3.0.1",
"contentHash": "s/s20YTVY9r9TPfTrN5g8zPF1YhwxyqO6PxUkrYTGI2B+OGPe9AdajWZrLhFqXIvqIW23fnUE4+ztrUWNU1+9g=="
},
"System.Runtime.CompilerServices.Unsafe": {
"type": "Transitive",
Expand Down
72 changes: 45 additions & 27 deletions src/Imageflow/Bindings/NativeLibraryLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,23 @@ internal static class RuntimeFileLocator

internal static readonly Lazy<string> SharedLibraryExtension = new Lazy<string>(() =>
{
switch (Environment.OSVersion.Platform)
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
case PlatformID.MacOSX:
return "dylib";
case PlatformID.Unix:
return "so";
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
case PlatformID.Xbox:
return "dll";
default:
return "dll";
return "dylib";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))

Check failure on line 162 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

'OSPlatform' does not contain a definition for 'FreeBSD'

Check failure on line 162 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

'OSPlatform' does not contain a definition for 'FreeBSD'

Check failure on line 162 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

'OSPlatform' does not contain a definition for 'FreeBSD'

Check failure on line 162 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

'OSPlatform' does not contain a definition for 'FreeBSD'

Check failure on line 162 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

'OSPlatform' does not contain a definition for 'FreeBSD'

Check failure on line 162 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

'OSPlatform' does not contain a definition for 'FreeBSD'
{
return "so";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return "dll";
}
else
{
// Default to dll for unknown platforms
return "dll";
}
}, LazyThreadSafetyMode.PublicationOnly);

Expand Down Expand Up @@ -196,22 +199,37 @@ internal static class RuntimeFileLocator
/// </summary>
internal static readonly Lazy<string> ArchitectureSubdir = new Lazy<string>(() =>
{
// ReSharper disable once InvertIf
if (!IsUnix)
var processArchitecture = RuntimeInformation.ProcessArchitecture;
var archString = processArchitecture switch
{
var architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
if (string.Equals(architecture, "ia64", StringComparison.OrdinalIgnoreCase))
{
return "ia64";
}
if (string.Equals(architecture, "arm", StringComparison.OrdinalIgnoreCase))
{
return Environment.Is64BitProcess ? "arm64" : "arm";
}
// We don't currently support unlisted/unknown architectures. We default to x86/x64 as backup
Architecture.X86 => "x86",
Architecture.X64 => "x64",
Architecture.Arm => "arm",
Architecture.Arm64 => "arm64",
Architecture.Armv6 => "armv6",

Check failure on line 209 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

'Architecture' does not contain a definition for 'Armv6'

Check failure on line 209 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

'Architecture' does not contain a definition for 'Armv6'

Check failure on line 209 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

'Architecture' does not contain a definition for 'Armv6'

Check failure on line 209 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

'Architecture' does not contain a definition for 'Armv6'

Check failure on line 209 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

'Architecture' does not contain a definition for 'Armv6'

Check failure on line 209 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

'Architecture' does not contain a definition for 'Armv6'
Architecture.LoongArch64 => "loongarch64",

Check failure on line 210 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

'Architecture' does not contain a definition for 'LoongArch64'

Check failure on line 210 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

'Architecture' does not contain a definition for 'LoongArch64'

Check failure on line 210 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

'Architecture' does not contain a definition for 'LoongArch64'

Check failure on line 210 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

'Architecture' does not contain a definition for 'LoongArch64'

Check failure on line 210 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

'Architecture' does not contain a definition for 'LoongArch64'

Check failure on line 210 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

'Architecture' does not contain a definition for 'LoongArch64'
Architecture.Ppc64le => "ppc64le",

Check failure on line 211 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

'Architecture' does not contain a definition for 'Ppc64le'

Check failure on line 211 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

'Architecture' does not contain a definition for 'Ppc64le'

Check failure on line 211 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

'Architecture' does not contain a definition for 'Ppc64le'

Check failure on line 211 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

'Architecture' does not contain a definition for 'Ppc64le'

Check failure on line 211 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

'Architecture' does not contain a definition for 'Ppc64le'

Check failure on line 211 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

'Architecture' does not contain a definition for 'Ppc64le'
Architecture.S390x => "s390x",

Check failure on line 212 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

'Architecture' does not contain a definition for 'S390x'

Check failure on line 212 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

'Architecture' does not contain a definition for 'S390x'

Check failure on line 212 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

'Architecture' does not contain a definition for 'S390x'
Architecture.Wasm => "wasm",

Check failure on line 213 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, true)

'Architecture' does not contain a definition for 'Wasm'

Check failure on line 213 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 8.0.1)

'Architecture' does not contain a definition for 'Wasm'

Check failure on line 213 in src/Imageflow/Bindings/NativeLibraryLoading.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, true, true, true, true)

'Architecture' does not contain a definition for 'Wasm'
_ => null
};

if (archString != null)
{
return archString;
}
//TODO: Add support for arm/arm64 on linux
return Environment.Is64BitProcess ? "x64" : "x86";

// Fallback to environment variable if RuntimeInformation.ProcessArchitecture is not conclusive
var envArchitecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
return envArchitecture?.ToUpperInvariant() switch
{
"AMD64" => "x64",
"IA64" => "ia64",
"ARM64" => "arm64",
"EM64T" => "x64", // Treating EM64T as x64
"X86" => "x86",
_ => Environment.Is64BitProcess ? "x64" : "x86" // Default fallback
};
}, LazyThreadSafetyMode.PublicationOnly);

/// <summary>
Expand Down
18 changes: 9 additions & 9 deletions src/Imageflow/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"Microsoft.IO.RecyclableMemoryStream": {
"type": "Direct",
"requested": "[3.*, 4.0.0)",
"resolved": "3.0.0",
"contentHash": "irv0HuqoH8Ig5i2fO+8dmDNdFdsrO+DoQcedwIlb810qpZHBNQHZLW7C/AHBQDgLLpw2T96vmMAy/aE4Yj55Sg==",
"resolved": "3.0.1",
"contentHash": "s/s20YTVY9r9TPfTrN5g8zPF1YhwxyqO6PxUkrYTGI2B+OGPe9AdajWZrLhFqXIvqIW23fnUE4+ztrUWNU1+9g==",
"dependencies": {
"System.Memory": "4.5.5"
}
Expand Down Expand Up @@ -124,8 +124,8 @@
"Microsoft.IO.RecyclableMemoryStream": {
"type": "Direct",
"requested": "[3.*, 4.0.0)",
"resolved": "3.0.0",
"contentHash": "irv0HuqoH8Ig5i2fO+8dmDNdFdsrO+DoQcedwIlb810qpZHBNQHZLW7C/AHBQDgLLpw2T96vmMAy/aE4Yj55Sg=="
"resolved": "3.0.1",
"contentHash": "s/s20YTVY9r9TPfTrN5g8zPF1YhwxyqO6PxUkrYTGI2B+OGPe9AdajWZrLhFqXIvqIW23fnUE4+ztrUWNU1+9g=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
Expand Down Expand Up @@ -221,14 +221,14 @@
"Microsoft.IO.RecyclableMemoryStream": {
"type": "Direct",
"requested": "[3.*, 4.0.0)",
"resolved": "3.0.0",
"contentHash": "irv0HuqoH8Ig5i2fO+8dmDNdFdsrO+DoQcedwIlb810qpZHBNQHZLW7C/AHBQDgLLpw2T96vmMAy/aE4Yj55Sg=="
"resolved": "3.0.1",
"contentHash": "s/s20YTVY9r9TPfTrN5g8zPF1YhwxyqO6PxUkrYTGI2B+OGPe9AdajWZrLhFqXIvqIW23fnUE4+ztrUWNU1+9g=="
},
"Microsoft.NET.ILLink.Tasks": {
"type": "Direct",
"requested": "[8.0.2, )",
"resolved": "8.0.2",
"contentHash": "hKTrehpfVzOhAz0mreaTAZgbz0DrMEbWq4n3hAo8Ks6WdxdqQhNPvzOqn9VygKuWf1bmxPdraqzTaXriO/sn0A=="
"requested": "[8.0.5, )",
"resolved": "8.0.5",
"contentHash": "4ISW1Ndgz86FkIbu5rVlMqhhtojdy5rUlxC/N+9kPh9qbYcvHiCvYbHKzAPVIx9OPYIjT9trXt7JI42Y5Ukq6A=="
},
"Microsoft.SourceLink.GitHub": {
"type": "Direct",
Expand Down

0 comments on commit 81dcdaf

Please sign in to comment.