Fix macos framework bindings#1409
Conversation
Signed-off-by: Linus Meierhoefer <linusmeierhoefer@protonmail.com>
…dings Signed-off-by: Linus Meierhoefer <linusmeierhoefer@protonmail.com>
|
Hi @Lxixnxuxs, the pipeline is failing during the Windows build. After inspection, it seems the CI environment is using C# 5, but the |
|
Hi @RubenNatanael, thanks for flagging this. I just looked into the Windows CI and realized that the issue is deeper, i.e. that the project is linked against .NET Framework/mono, which does not expose the |
|
I think the best approach is to make it compatible with the current version until is decided to move to a newer version, but let's wait for a answer from @dNechita |
|
Let's keep the C# 5 for now. |
Replace NativeLibrary.SetDllImportResolver (requires .NET Core / C# 7+) with a platform-specific DllMap entry in libiio-sharp.dll.config, which is compatible with the project's Mono / C# 5 target. Signed-off-by: Linus Meierhoefer <linusmeierhoefer@protonmail.com>
|
Hi @RubenNatanael, @dNechita, thanks for the feedback. I've replaced the However, |
|
@Lxixnxuxs, Do you think this issue could be resolved using preprocessor symbols instead? For example, we could use |
|
Hi @RubenNatanael, I looked into this but unfortunately directly using preprocessor symbols like We could work around that by passing a custom Supporting both paths ( |
|
Thanks @Lxixnxuxs, I was asking because we already have used a similar approach in UTF8Marshaler.cs file (https://github.com/analogdevicesinc/libiio/blob/main/bindings/csharp/UTF8Marshaler.cs#L31) |
|
@RubenNatanael Ok i see, in that case (i.e. parts of the C# code assuming there is a .NET core build system), would it also make sense to add a proper |
|
Hi @Lxixnxuxs, thank you for your analysis and explanation; it's good to know all this. Currently, we don't have a request to move to .NET Core or a higher C# version. Creating and maintaining two different builds would require a significant amount of work, so we will leave it as it is for now. Thanks again! |
|
Hi @RubenNatanael, alright makes sense. So should I change anything else concerning this PR? |
Everything looks good from my side. Just waiting for a final approval from a reviewer before we move forward. |
PR Description
Fixes #1408
On macOS, libiio installs as a framework by default (
OSX_FRAMEWORK=ON). Both the Python and C# bindings fail to load the library in this case:Python (
bindings/python/iio/__init__.py):find_library("iio")returns a framework path like/Library/Frameworks/iio.framework/Versions/1.0/iiowhere the basename is justiio. The code unconditionally splits on.so.to extract the version, causing anIndexError._path.islink()was called before theNonecheck on the library path..so.first, fall back to extracting the version from the/Versions/component of the framework path, and move theNoneguard up.C# (
bindings/csharp/IioLib.cs):DllImport("libiio1.dll")fails because .NET's native loader does not search/Library/Frameworks/on macOS, resulting in aDllNotFoundException.NativeLibrary.SetDllImportResolverin a static constructor that resolves to the framework path on macOS. This is the standard .NET mechanism for custom native library resolution (available since .NET Core 3.0).Both fixes are no-ops on Linux and Windows. I did not add any in-code documentation because of isolated nature of the bug.
PR Type
PR Checklist