From 9323bda846623ea1d0e3ac2f618e45fcf2613845 Mon Sep 17 00:00:00 2001 From: Jerome Haltom Date: Wed, 6 Jul 2022 13:39:15 -0500 Subject: [PATCH] Preload the required Mono.Unix native library at the top of IkvmCompiler, since MSBuild isn't going to let us do it correctly, currently. Held up on https://github.com/dotnet/msbuild/issues/5037 --- src/IKVM.MSBuild.Tasks/IKVM.MSBuild.Tasks.csproj | 4 +++- src/IKVM.MSBuild.Tasks/IkvmCompiler.cs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/IKVM.MSBuild.Tasks/IKVM.MSBuild.Tasks.csproj b/src/IKVM.MSBuild.Tasks/IKVM.MSBuild.Tasks.csproj index f6a393a0c5..04a32432b1 100644 --- a/src/IKVM.MSBuild.Tasks/IKVM.MSBuild.Tasks.csproj +++ b/src/IKVM.MSBuild.Tasks/IKVM.MSBuild.Tasks.csproj @@ -12,11 +12,13 @@ + + - + diff --git a/src/IKVM.MSBuild.Tasks/IkvmCompiler.cs b/src/IKVM.MSBuild.Tasks/IkvmCompiler.cs index c6c52437d9..459c0d9436 100644 --- a/src/IKVM.MSBuild.Tasks/IkvmCompiler.cs +++ b/src/IKVM.MSBuild.Tasks/IkvmCompiler.cs @@ -1,6 +1,8 @@ using System; using System.IO; using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; using System.Threading; using IKVM.Tool.Compiler; @@ -17,6 +19,20 @@ namespace IKVM.MSBuild.Tasks public class IkvmCompiler : Task { +#if NETCOREAPP + + /// + /// Initializes the static instance. + /// + static IkvmCompiler() + { + // preload Mono.Unix native library, MSBuild isn't capable of following dependency context + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && Environment.Is64BitProcess) + NativeLibrary.Load(Path.Combine(Path.GetDirectoryName(typeof(IkvmCompiler).Assembly.Location), "runtimes", "linux-x64", "native", "libMono.Unix.so")); + } + +#endif + /// /// Root of the tools director. ///