Add logic to muxer to invoke AOT-ed SDK#126596
Add logic to muxer to invoke AOT-ed SDK#126596elinor-fung wants to merge 5 commits intodotnet:mainfrom
Conversation
When the dotnet muxer resolves an SDK, it now checks for a dotnet-aot native library in the SDK directory before falling back to the managed dotnet.dll path. If the library exists and exports a dotnet_execute entry point, the muxer loads it and calls it with the host path, dotnet root, SDK directory, hostfxr path, and user arguments. The AOT library handles its own fallback to the managed runtime path when needed. If the library cannot be loaded or the entry point is missing, the muxer gracefully falls back to the existing managed SDK path. Fixes dotnet#126171 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add DispatchToAotSdk test to verify the muxer correctly loads and invokes the dotnet-aot library from the resolved SDK directory. The test uses a mock AOT SDK shared library that prints the received arguments for validation. - Add mockaotsdk native test library with dotnet_execute entry point - Add DotNetAot entry to Binaries.cs for test discovery - Add DispatchToAotSdk test in SDKLookup.cs - Move 'Using AOT-ed SDK' trace to just before invocation and remove redundant failure trace on load_library Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Tagging subscribers to this area: @agocke, @jeffschwMSFT, @elinor-fung |
| if (!pal::load_library(&sdk_aot_path, &aot_dll)) | ||
| return false; | ||
|
|
||
| typedef int (*dotnet_execute_fn)( |
There was a problem hiding this comment.
Do we have docs somewhere on this signature?
There was a problem hiding this comment.
Updated one of the docs in runtime.
@JeremyKuhne Are there any sdk docs that would make sense to link to here?
There was a problem hiding this comment.
@elinor-fung I don't have any links for you yet. The signature in the issue was copied directly from my wip. I'll be putting a PR up next week and I can add a link/links here after I commit. Copied again from my local changes:
[UnmanagedCallersOnly(EntryPoint = "dotnet_execute")]
static int Execute(
nint hostPathPtr, // const char_t* host_path
nint dotnetRootPtr, // const char_t* dotnet_root
nint sdkDirPtr, // const char_t* sdk_dir
nint hostfxrPathPtr, // const char_t* hostfxr_path
int argc, // int argc (user args, no dotnet exe)
nint argvPtr) // const char_t** argvCo-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| pal::dll_t aot_dll = nullptr; | ||
| if (!pal::load_library(&sdk_aot_path, &aot_dll)) | ||
| return false; | ||
|
|
||
| // See docs/design/features/sharedfx-lookup.md#sdk-search | ||
| typedef int (__cdecl *dotnet_execute_fn)( | ||
| const pal::char_t* host_path, | ||
| const pal::char_t* dotnet_root, | ||
| const pal::char_t* sdk_dir, | ||
| const pal::char_t* hostfxr_path, | ||
| int argc, | ||
| const pal::char_t** argv); | ||
|
|
||
| auto dotnet_execute = reinterpret_cast<dotnet_execute_fn>(pal::get_symbol(aot_dll, "dotnet_execute")); | ||
| if (dotnet_execute == nullptr) | ||
| { | ||
| trace::info(_X("AOT-ed SDK [%s] does not contain 'dotnet_execute' entry point."), sdk_aot_path.c_str()); | ||
| pal::unload_library(aot_dll); | ||
| return false; | ||
| } | ||
|
|
||
| pal::string_t hostfxr_path; | ||
| if (!pal::get_own_module_path(&hostfxr_path)) | ||
| { | ||
| trace::info(_X("Failed to determine hostfxr path.")); | ||
| pal::unload_library(aot_dll); | ||
| return false; | ||
| } | ||
|
|
||
| const pal::char_t* dotnet_root = sdk_root.empty() | ||
| ? host_info.dotnet_root.c_str() | ||
| : sdk_root.c_str(); | ||
|
|
||
| trace::info(_X("Using AOT-ed SDK=[%s]"), sdk_aot_path.c_str()); | ||
|
|
||
| *exit_code = dotnet_execute( | ||
| host_info.host_path.c_str(), | ||
| dotnet_root, | ||
| sdk_dir.c_str(), | ||
| hostfxr_path.c_str(), | ||
| argc - 1, // skip 'dotnet' (first argument) | ||
| argv + 1); | ||
|
|
||
| return true; | ||
| } |
There was a problem hiding this comment.
try_invoke_aot_sdk unloads the library on the failure paths, but on the success path it returns without calling pal::unload_library(aot_dll). In long-lived hosts that call hostfxr_main multiple times, this can accumulate loaded modules / memory and can keep the SDK’s dotnet-aot file in use. Consider ensuring the handle is released on the success path too (ideally via a small RAII wrapper so all early-returns are covered).
Fixes #126171
Updates the muxer to look for and natively invoke a \dotnet-aot\ shared library when it exists in the resolved SDK directory. When present, the muxer loads the library, resolves the \dotnet_execute\ entry point, and calls it with the host path, dotnet root, SDK directory, hostfxr path, and user arguments. If the AOT library is not available or doesn't have the expected entry point, the muxer falls back to the existing managed SDK path.
Changes
Native host
try_invoke_aot_sdkhelper infx_muxer_t::handle_clithat attempts to loaddotnet-aotfrom the resolved SDK directorydotnet.dllpath if the AOT library is absentTests
mockaotsdknative test library that implements thedotnet_executeentry point and prints received argumentsDispatchToAotSdktest inSDKLookup.csvalidating the muxer dispatches to the AOT SDK with the correct argumentscc @JeremyKuhne @dotnet/appmodel @AaronRobinsonMSFT