Skip to content

Merge main into live #7046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-code-metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
dir: ${{ './github-actions/DotNet.GitHubAction' }}

- name: Create pull request
uses: peter-evans/create-pull-request@v7.0.8
uses: dotnet/actions-create-pull-request@v4
if: ${{ steps.dotnet-code-metrics.outputs.updated-metrics }} == 'true'
with:
title: '${{ steps.dotnet-code-metrics.outputs.summary-title }}'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/markdownlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #@v2
- name: Use Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a #@v1
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 #@v1
with:
node-version: 12.x
- name: Run Markdownlint
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/quest-bulk.yml

This file was deleted.

63 changes: 0 additions & 63 deletions .github/workflows/quest.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/snippets5000.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:

# Update build output json file
- name: Upload build results
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 #@v4.6.1
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #@v4.6.2
with:
name: build
path: ./output.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest" Version="3.8.3" />
</ItemGroup>

<ItemGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@

<!-- Uncomment to publish as a native executable -->
<!-- <PublishAOT>true</PublishAOT> -->
</PropertyGroup>

<PropertyGroup Condition="'$(PublishAOT)' != 'true'">
<!-- Enable DNNE to dynamically load the managed .dll -->
<EnableDynamicLoading Condition="'$(PublishAOT)' != 'true'">true</EnableDynamicLoading>
<EnableDynamicLoading>true</EnableDynamicLoading>
<!-- Use our own .def file to export the COM methods as PRIVATE. The Windows native linker (Link.exe) warns when exported COM methods are not PRIVATE. -->
<DnneWindowsExportsDef>Server.def</DnneWindowsExportsDef>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DNNE" Version="2.*" Condition="'$(PublishAOT)' != 'true'"/>
<PackageReference Include="DNNE" Version="2.0.7" Condition="'$(PublishAOT)' != 'true'"/>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<!-- When publishing AOT, use our own .def file to export the COM methods as PRIVATE. The Windows native linker (Link.exe) warns when exported COM methods are not PRIVATE. -->
<LinkerArg Include="/DEF:&quot;Server.def&quot;" Condition="'$(PublishAOT)' == 'true'"/>
Expand Down
56 changes: 0 additions & 56 deletions core/nativeaot/NativeLibrary/Class1.cs

This file was deleted.

54 changes: 54 additions & 0 deletions core/nativeaot/NativeLibrary/LibraryFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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.InteropServices;

namespace NativeLibrary;

public class LibraryFunctions
{
[UnmanagedCallersOnly(EntryPoint = "aotsample_add")]
public static int Add(int a, int b)
{
return a + b;
}

[UnmanagedCallersOnly(EntryPoint = "aotsample_write_line")]
public static int WriteLine(IntPtr pString)
{
// The marshalling code is typically auto-generated by a custom tool in larger projects.
try
{
// UnmanagedCallersOnly methods only accept primitive arguments. The primitive arguments
// have to be marshalled manually if necessary.
string str = Marshal.PtrToStringAnsi(pString);

Console.WriteLine(str);
}
catch
{
// Exceptions escaping out of UnmanagedCallersOnly methods are treated as unhandled exceptions.
// The errors have to be marshalled manually if necessary.
return -1;
}
return 0;
}

[UnmanagedCallersOnly(EntryPoint = "aotsample_sumstring")]
public static IntPtr sumstring(IntPtr first, IntPtr second)
{
// Parse strings from the passed pointers
string my1String = Marshal.PtrToStringAnsi(first);
string my2String = Marshal.PtrToStringAnsi(second);

// Concatenate strings
string sum = my1String + my2String;

// Assign pointer of the concatenated string to sumPointer
IntPtr sumPointer = Marshal.StringToHGlobalAnsi(sum);

// Return pointer
return sumPointer;
}
}
44 changes: 28 additions & 16 deletions core/nativeaot/NativeLibrary/LoadLibrary.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
int callSumFunc(char *path, char *funcName, int a, int b);
char *callSumStringFunc(char *path, char *funcName, char *a, char *b);

void* loadSymbol(char *path, char *funcName);

int main()
{
// Check if the library file exists
Expand All @@ -54,43 +56,53 @@ int main()
CoTaskMemFree(sumstring);
}

int callSumFunc(char *path, char *funcName, int firstInt, int secondInt)
void *loadSymbol(char *path, char *funcName)
{
// Call sum function defined in C# shared library
// Library loading
#ifdef _WIN32
HINSTANCE handle = LoadLibraryA(path);
#else
void *handle = dlopen(path, RTLD_LAZY);
#endif
if (!handle)
{
#ifdef _WIN32
int errorCode = GetLastError();
printf("Failed to load library at specified path. Error code: %d\n", errorCode);
#else
puts("Failed to load library at specified path");
#endif
return NULL;
}

// Declare a typedef
typedef char *(*myFunc)(char*,char*);

// Import Symbol named funcName

// NativeAOT libraries do not support unloading
// See https://github.com/dotnet/corert/issues/7887
return symLoad(handle, funcName);
}

int callSumFunc(char *path, char *funcName, int firstInt, int secondInt)
{
typedef int(*myFunc)(int,int);
myFunc MyImport = (myFunc)symLoad(handle, funcName);
myFunc MyImport = (myFunc)loadSymbol(path, funcName);

int result = MyImport(firstInt, secondInt);

// NOTE: Native AOT libraries do not support unloading
return result;
}

char *callSumStringFunc(char *path, char *funcName, char *firstString, char *secondString)
{
// Library loading
#ifdef _WIN32
HINSTANCE handle = LoadLibraryA(path);
#else
void *handle = dlopen(path, RTLD_LAZY);
#endif

// Declare a typedef
typedef char *(*myFunc)(char*,char*);

// Import Symbol named funcName
myFunc MyImport = (myFunc)symLoad(handle, funcName);
myFunc MyImport = (myFunc)loadSymbol(path, funcName);

// The C# function will return a pointer
char *result = MyImport(firstString, secondString);

// CoreRT libraries do not support unloading
// See https://github.com/dotnet/corert/issues/7887
return result;
}
Loading