Skip to content

Commit

Permalink
Preload the required Mono.Unix native library at the top of IkvmCompi…
Browse files Browse the repository at this point in the history
…ler, since MSBuild isn't going to let us do it correctly, currently.

Held up on dotnet/msbuild#5037
  • Loading branch information
wasabii committed Jul 6, 2022
1 parent cd77e2a commit 9323bda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/IKVM.MSBuild.Tasks/IKVM.MSBuild.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
<PackageReference Include="Microsoft.Build" Version="16.9.0" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.9.0" />
<PackageReference Include="System.Reflection.Metadata" Version="6.0.1" />
<PackageReference Include="Mono.Posix" Version="7.1.0-final.1.21458.1" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IKVM.Java\IKVM.Java.csproj" />
<ProjectReference Include="..\IKVM.Tool\IKVM.Tool.csproj" AdditionalProperties="IncludeTools=false" />
<ProjectReference Include="..\IKVM.Tool\IKVM.Tool.csproj" />
<ProjectReference Include="..\IKVM.Util\IKVM.Util.csproj" />
</ItemGroup>

Expand Down
16 changes: 16 additions & 0 deletions src/IKVM.MSBuild.Tasks/IkvmCompiler.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,6 +19,20 @@ namespace IKVM.MSBuild.Tasks
public class IkvmCompiler : Task
{

#if NETCOREAPP

/// <summary>
/// Initializes the static instance.
/// </summary>
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

/// <summary>
/// Root of the tools director.
/// </summary>
Expand Down

0 comments on commit 9323bda

Please sign in to comment.