Repository navigation
Enable cached file-based run in Native AOT CLI - #55529
Conversation
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR enables a NativeAOT dotnet fast path for file-based apps by reusing validated cached launch contracts (and synthetic CSC output for --no-build) so warm runs can avoid hosting the managed CLI when safe.
Changes:
- Introduces shared, AOT-safe planning + cache model (
FileBasedAppRunPlan) and a conservative directive-byte probe to decide between native cached launch vs managed fallback. - Adds
AotRunCommandand wires NativeAOT dispatch to preserve external-command precedence, launch profiles, environment/args semantics, and fallback behavior. - Adds/updates comprehensive tests across managed + AOT paths, plus harness/docs updates for the native library naming.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet.Tests/CommandTests/Run/RunFileTests_CscOnlyAndApi.cs | Adds managed regression tests for missing CSC launch artifacts (recompile vs fail under --no-build). |
| test/dotnet.Tests/CommandTests/Run/RunFileTestBase.cs | Switches implicit-build-file collection to the new shared FileBasedAppRunPlan helper. |
| test/dotnet.Tests/CommandTests/Run/FileBasedAppDirectiveProbeTests.cs | New managed tests ensuring the probe’s “None” result is one-way safe vs Roslyn directive discovery. |
| test/dotnet-aot.Tests/NativeEntryPointTests.cs | Updates/extends entrypoint tests for fallback behavior and external-command precedence over shorthand file-based apps. |
| test/dotnet-aot.Tests/FileBasedAppRunPlanTests.cs | New unit tests covering run-plan analysis and cache validation behavior. |
| test/dotnet-aot.Tests/FileBasedAppDirectiveProbeTests.cs | New unit tests for the directive byte probe behavior and edge cases. |
| test/dotnet-aot.Tests/AotRunCommandTests.cs | New unit tests for native run invocation planning, launch-profile application, and env/arg handling. |
| test/dotnet-aot.Tests/AotParserTests.cs | Extends AOT parser tests for shorthand reparse-as-run and run help/fallback shapes. |
| test/dotnet-aot.Tests/AotIntegrationTests.cs | Adds end-to-end integration tests exercising native cached launch and conservative fallbacks via dn. |
| src/Cli/dotnet/Program.cs | Uses TryParseFileBasedAppAsRun() to re-dispatch shorthand file-based invocations to run --file. |
| src/Cli/dotnet/Parser.cs | Wires AotRunCommand into the AOT action configuration for run. |
| src/Cli/dotnet/Extensions/ParseResultExtensions.cs | Adds TryParseFileBasedAppAsRun() helper for consistent shorthand reparse behavior. |
| src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs | Refactors build-level/cache logic to use FileBasedAppRunPlan and shared cache serialization. |
| src/Cli/dotnet/Commands/Run/RunProperties.cs | Makes RunProperties JSON-deserializable for shared cache usage and gates MSBuild-only APIs under !CLI_AOT. |
| src/Cli/dotnet/Commands/Run/RunCommand.cs | Improves --no-build behavior for missing synthetic CSC launch artifacts and centralizes apphost path derivation. |
| src/Cli/dotnet/Commands/Run/FileBasedAppRunPlan.cs | New shared cache model + run planning logic used by managed and AOT paths. |
| src/Cli/dotnet/Commands/Run/FileBasedAppDirectiveProbe.cs | New conservative streaming probe for potential #: directive bytes. |
| src/Cli/dotnet/Commands/Run/CSharpCompilerCommand.cs | Centralizes CSC output artifact paths via FileBasedAppRunPlan. |
| src/Cli/dotnet/Commands/Run/AotRunCommand.cs | New NativeAOT run gate/launcher that performs cache analysis + launch profile application + process execution. |
| src/Cli/dotnet-aot/NativeEntryPoint.cs | Enables shorthand file-based run after external resolution fails, using AotRunCommand for eligible shapes. |
| src/Cli/dotnet-aot/DESIGN.md | Documents the new narrow AOT file-based run paths and decision points. |
| src/Cli/dotnet-aot/AotSourceFiles.props | Adds shared run/cache/probe sources to the AOT compilation closure. |
| src/Cli/dn/run-dn.ps1 | Updates harness docs/behavior and native library naming; explicitly sets DOTNET_CLI_ENABLEAOT=false for managed mode. |
| src/Cli/dn/Program.cs | Updates comments and native library name resolution for dotnet-aot on macOS/Linux. |
| .github/skills/add-dotnet-aot-command/SKILL.md | Updates contributor guidance to include the new AOT run fast path and new test/harness knobs. |
9a6f6b9 to
3c6bbc9
Compare
|
CI follow-up for the original failed run (build 1531989):
Updated commit: |
3c6bbc9 to
49e4054
Compare
|
Linux x64 CI failure follow-up (task log):
Exact Linux validation for commit |
49e4054 to
3427f5b
Compare
|
CI follow-up for build 1532210:
Focused local result: 1 passed, 0 failed. Updated commit: |
|
Replacement CI follow-up for build 1532389:
This is an unrelated Helix test hang, so I am requesting a clean rerun without changing commit |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
|
Reruns are now attached to the unchanged commit: |
99a7a19 to
fb598a6
Compare
Appreciate all of your effort. :) |
jjonescz
left a comment
There was a problem hiding this comment.
LGTM but it looks like there are some test failures in CI
|
CI follow-up for build 1541457:
Requesting a clean rerun on unchanged commit |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
Executive summary
This PR enables the Native AOT-compiled
dotnetCLI to run warm file-based applications without hosting the managed CLI when it can prove that an existing launch contract is safe to reuse.It implements native cached launch for:
dotnet run --file app.csdotnet run app.cswhen the current directory does not contain a projectdotnet app.csafter external-command resolution confirms no command takes precedence--no-buildreuse of complete synthetic CSC outputRunPropertiescachesThe native path preserves application arguments, environment-variable precedence, working directory,
DOTNET_ROOT_*, exit codes, Ctrl-C handling, project-discovery compatibility, and external-command precedence. Unsupported options, stale or ambiguous inputs, incomplete outputs, and uncertain directive content fall back to the managed CLI before launch or other non-idempotent side effects.Development measurements on Windows x64 Release showed the implemented cached paths at roughly 56-65 ms p50 versus 243-276 ms through managed fallback, reducing repeat-run latency by about 180-210 ms. The reusable benchmark and activity-instrumentation changes are intentionally split from this product PR.
Implementation
VirtualProjectBuildingCommandinto a shared AOT-safeFileBasedAppRunPlan.RunPropertiesbetween managed and Native AOT paths without bringing the MSBuild object model into the native closure.#:bytes is eligible; unsupported encodings, read failures, concurrent changes, and possible directives defer.AotRunCommandfor cache analysis, launch-profile application, and terminal process launch.run --fileonly after the AOT resolver set finds no external command.dnharness and explicitly disable AOT in managed comparison mode.This builds on the Native AOT infrastructure added in #55441.
Validation
build.cmd -c Releaseredist builddotnet-aot.Testsforwin-x64git diff --checkLinux and macOS product validation remain required before merge; ambiguous or unsupported shapes continue to use managed fallback in this change.
Executive summary: additional functionality plan
The next increment is direct compilation through Roslyn's
BuildClientprotocol, preserving compiler-server analyzer and generator behavior without linking the compiler implementation into the native CLI. It will include explicit handling for unavailable servers, cancellation, compiler-version mismatch, andCS0006handoff to a forced full managed build without duplicate compilation.After direct compilation, a restricted path (A) can evaluate default virtual projects and recover
ComputeRunArgumentslaunch contracts when no build is requested and imported customization is conservatively ruled out. Full in-process Native AOT MSBuild execution (B) will remain behind managed fallback until it passes trimming/AOT warning, custom-task, cross-platform, binary-size, and latency gates; direct invocation of the MSBuildRuntarget remains out of scope because it changes stream, exit-code, and target-side-effect semantics. A separate follow-up PR will carry the benchmark harness and activity instrumentation, and each expansion will be validated on Windows, Linux, and macOS before broadening eligibility.