kaby76 / swigged.llvm

A SWIG-generated wrapper of LLVM-C for C#. http://domemtech.com/_site/api/Swigged.LLVM.html
https://www.nuget.org/packages/swigged.llvm/
MIT License
6 stars 2 forks source link

Add code to dynamically select which native runtime to use #6

Open kaby76 opened 7 years ago

kaby76 commented 7 years ago

According to https://www.nuget.org/packages/LLVM/ (and https://www.nuget.org/packages/LLVM.NativeLibrary/ ), "To get the native library itself, you can reference LLVM.NativeLibrary from NuGet, and call LLVMDLL.Load. This will preload an LLVM DLL that matches your current processor architecture." However, if you clone these libraries, there is no LLVMDLL.Load(). But, the concept is sound.

To do: add code that will select the appropriate native runtime based on the host running, and avoid the problematic request to the user to copy the native library over. This seems to be done already in Mono/Xamarin/Android where the system does that, and outputs the search for the appropriate runtime. To do that, a call to SetEnvironmentVariable() or SetDllDirectory() must be done prior to the function call. See https://stackoverflow.com/questions/2864673/specify-the-search-path-for-dllimport-in-net or https://msdn.microsoft.com/en-us/library/ms686203.aspx?f=255&MSPPError=-2147217396 .

kaby76 commented 7 years ago

https://www.nuget.org/packages/LLVM/ ===> https://bitbucket.org/lost/llvm.net/wiki/Home ===> https://www.nuget.org/packages/Lost.Native/ ===> https://bitbucket.org/lost/native/

kaby76 commented 7 years ago

Note, https://github.com/NETMF/Llvm.NET.git , which has been updated within the last 6 months, is not the same, although identically named, and not released in NuGet.org.

kaby76 commented 7 years ago

LLVMDLL.Load is platform dependent (uses kernel32.dll). https://bitbucket.org/lost/native/src/8ad3850680dd1094baa1c61268c14e9b88d8532f/DynamicLibrary.cs?at=default&fileviewer=file-view-default

'Environment.SetEnvironmentVariable("PATH", path);' works.