-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NativeAOT] Support exporting methods from referenced assemblies in a…
- Loading branch information
1 parent
2e8148c
commit b69b359
Showing
14 changed files
with
152 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/tests/nativeaot/GenerateUnmanagedEntryPoints/GenerateUnmanagedEntryPoints.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace GenerateUnmanagedEntryPoints | ||
{ | ||
unsafe class Program | ||
{ | ||
[UnmanagedCallersOnly(EntryPoint = "MainAssemblyMethod")] | ||
static void MainAssemblyMethod() => Console.WriteLine($"Hello from {nameof(MainAssemblyMethod)}"); | ||
|
||
static int Main() | ||
{ | ||
IntPtr methodAddress = IntPtr.Zero; | ||
IntPtr programHandle = IntPtr.Zero; | ||
|
||
programHandle = NativeLibrary.GetMainProgramHandle(); | ||
if (programHandle == IntPtr.Zero) | ||
{ | ||
return 1; | ||
} | ||
|
||
if (NativeLibrary.TryGetExport(programHandle, "MainAssemblyMethod", out methodAddress)) | ||
{ | ||
var MainAssemblyMethodPtr = (delegate* unmanaged <void>) methodAddress; | ||
MainAssemblyMethodPtr(); | ||
} | ||
else | ||
{ | ||
return 2; | ||
} | ||
|
||
if (NativeLibrary.TryGetExport(programHandle, "ReferencedAssembly1Method", out methodAddress)) | ||
{ | ||
var ReferencedAssembly1MethodPtr = (delegate* unmanaged <void>) methodAddress; | ||
ReferencedAssembly1MethodPtr(); | ||
} | ||
else | ||
{ | ||
return 3; | ||
} | ||
|
||
if (NativeLibrary.TryGetExport(programHandle, "ReferencedAssembly2Method", out methodAddress)) | ||
{ | ||
// must not be exposed from ReferencedAssembly2 assembly | ||
return 4; | ||
} | ||
|
||
return 100; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/tests/nativeaot/GenerateUnmanagedEntryPoints/GenerateUnmanagedEntryPoints.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<CLRTestKind>BuildAndRun</CLRTestKind> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<IlcExportUnmanagedEntrypoints>true</IlcExportUnmanagedEntrypoints> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="GenerateUnmanagedEntryPoints.cs" /> | ||
<ProjectReference Include="$(MSBuildThisFileDirectory)ReferencedAssembly1\ReferencedAssembly1.csproj" /> | ||
<ProjectReference Include="$(MSBuildThisFileDirectory)ReferencedAssembly2\ReferencedAssembly2.csproj" /> | ||
</ItemGroup> | ||
|
||
<!-- Expose additional unmanaged entry points from ReferencedAssembly1 --> | ||
<ItemGroup> | ||
<UnmanagedEntryPointsAssembly Include="ReferencedAssembly1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
15 changes: 15 additions & 0 deletions
15
src/tests/nativeaot/GenerateUnmanagedEntryPoints/ReferencedAssembly1/ReferencedAssembly1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace ReferencedAssembly1 | ||
{ | ||
public class ClassLibrary | ||
{ | ||
[UnmanagedCallersOnly(EntryPoint = "ReferencedAssembly1Method")] | ||
public static void ReferencedAssembly1Method() => Console.WriteLine($"Hello from {nameof(ReferencedAssembly1Method)}"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...sts/nativeaot/GenerateUnmanagedEntryPoints/ReferencedAssembly1/ReferencedAssembly1.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="ReferencedAssembly1.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
15 changes: 15 additions & 0 deletions
15
src/tests/nativeaot/GenerateUnmanagedEntryPoints/ReferencedAssembly2/ReferencedAssembly2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace ReferencedAssembly2 | ||
{ | ||
public class ClassLibrary | ||
{ | ||
[UnmanagedCallersOnly(EntryPoint = "ReferencedAssembly2Method")] | ||
public static void ReferencedAssembly2Method() => Console.WriteLine($"Hello from {nameof(ReferencedAssembly2Method)}"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...sts/nativeaot/GenerateUnmanagedEntryPoints/ReferencedAssembly2/ReferencedAssembly2.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="ReferencedAssembly2.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |