Skip to content

Commit 8e22fe1

Browse files
authored
Use RuntimeInformation to determine the Processor architecture. (#108)
See https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.architecture?view=net-6.0 Now that we ship an arm based native library on windows we need to be able to determine the underlying library to load. We can use the `RuntimeInformation.ProcessArchitecture` value to get this data. Then based on that we can load from `x86`, `x64` or `arm64` subdirectories. Note we will still fallback to loading from the current directory , but the preference is to load from on of the architecture specific sub directories.
1 parent 33f5b01 commit 8e22fe1

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎LibZipSharp/Xamarin.LibZipSharp.targets‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<_LibZipNativeLibsInclude="$(MSBuildThisFileDirectory)..\runtimes\win-x64\native\libZipSharpNative.*">
7-
<Link>lib64\%(FileName)%(Extension)</Link>
7+
<Link>x64\%(FileName)%(Extension)</Link>
88
</_LibZipNativeLibs>
99
<_LibZipNativeLibsInclude="$(MSBuildThisFileDirectory)..\runtimes\win-arm64\native\libZipSharpNative.*">
10-
<Link>%(FileName)%(Extension)</Link>
10+
<Link>arm64\%(FileName)%(Extension)</Link>
1111
</_LibZipNativeLibs>
1212
<_LibZipNativeLibsInclude="$(MSBuildThisFileDirectory)..\runtimes\win-x86\native\libZipSharpNative.*">
13-
<Link>%(FileName)%(Extension)</Link>
13+
<Link>x86\%(FileName)%(Extension)</Link>
1414
</_LibZipNativeLibs>
1515
<_LibZipNativeLibsInclude="$(MSBuildThisFileDirectory)..\runtimes\osx\native\libZipSharpNative.dylib">
1616
<Link>%(FileName)%(Extension)</Link>

‎LibZipSharp/Xamarin.Tools.Zip/Native.cs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,17 @@ static Native ()
455455
{
456456
if(Environment.OSVersion.Platform==PlatformID.Win32NT){
457457
stringexecutingDirectory=System.IO.Path.GetDirectoryName(typeof(Native).Assembly.Location);
458-
SetDllDirectory(Environment.Is64BitProcess?System.IO.Path.Combine(executingDirectory,"lib64"):executingDirectory);
458+
#if !NET45
459+
stringarch=RuntimeInformation.ProcessArchitecture.ToString().ToLower();
460+
stringpath=System.IO.Path.Combine(executingDirectory,arch);
461+
#else
462+
stringpath=System.IO.Path.Combine(executingDirectory,Environment.Is64BitProcess?"x64":"x86");
463+
#endif
464+
if(System.IO.Directory.Exists(path)){
465+
SetDllDirectory(path);
466+
return;
467+
}
468+
SetDllDirectory(executingDirectory);
459469
}
460470
}
461471
}

0 commit comments

Comments
 (0)