Skip to content

NativeAOT support in source-build #2885

Closed

Description

@crummel

From dotnet/runtime#69611, there is more work here than just building llvm in source-build - we have to make some decisions about how different native packages are linked. Currently NativeAOT will not work in source-build because of the assumptions it makes about these linkages.

Activity

  1. added
    area-product-experience
    on Jun 2, 2022
  2. MichaelSimons commented on Jun 2, 2022

    @MichaelSimons
    Member

    [Triage] one suggestion is to try an run it today w/the prebuilt to see how much is functional and what is broken.

  3. tmds commented on Aug 26, 2022

    @tmds
    Member

    Is NativeAOT a feature that gets delivered from the SDK, or does it ship out-of-band from nuget.org?

    I've downloaded preview 7, and for NativeAOT I need a to add a reference to Microsoft.DotNet.ILCompiler.

    If this ships out-of-band we can skip compiling it on source-build .NET.
    Or do we still need to build a part? Or do we need it to build .NET itself?

    cc @omajid

  4. tmds commented on Aug 28, 2022

    @tmds
    Member

    @jkotas can you answer my questions above?

  5. jkotas commented on Aug 28, 2022

    @jkotas
    Member

    Is NativeAOT a feature that gets delivered from the SDK, or does it ship out-of-band from nuget.org?

    If you specify <PublishAot>true</PublishAot> property in your .csproj, SDK will add native AOT package for you and the package gets downloaded from nuget during project restore.

    It is same scheme as what's used for publishing self-contained apps (SDK adds Microsoft.NETCore.App.Runtime.* package reference) or PublishReadyToRun (SDK adds Microsoft.NETCore.App.Crossgen2.* package reference).

    I've downloaded preview 7, and for NativeAOT I need a to add a reference to Microsoft.DotNet.ILCompiler.

    Adding <PublishAot>true</PublishAot> property to your project file is going to be the recommended way to enable publishing as native aot. It should work in preview 7.

    Just like with the crossgen2 package, you can manually add the native aot package reference and it will override the one added by the SDK. The explicit package reference should be only used as last resort (e.g. to workaround bugs in the runtime). It tends to produce version mismatches when people upgrade to new runtime, but forget to bump the aot package version.

    The manual package overriding is broken in preview 7. It should be fixed in rc builds.

    Or do we need it to build .NET itself?

    It is not required to build .NET itself.

    We use nativeaot to optimize crossgen2 where possible, but this optimization is disabled for source build currently: https://github.com/dotnet/runtime/blob/main/src/coreclr/tools/aot/crossgen2/crossgen2.csproj#L9

  6. tmds commented on Aug 29, 2022

    @tmds
    Member

    @jkotas thanks. I think this means we have no need to build NativeAOT support for source-build in .NET 7.

    It is same scheme as what's used for publishing self-contained apps (SDK adds Microsoft.NETCore.App.Runtime.* package reference) or PublishReadyToRun (SDK adds Microsoft.NETCore.App.Crossgen2.* package reference).

    Source-build doesn't need to build the end-user NativeAOT support.

    Like self-contained apps in .NET 6, the SDK uses packages published by Microsoft on nuget.org.

    I do think these should become features of source-built .NET (#1215). That's not for .NET 7.

    It is not required to build .NET itself.

    When we build .NET from source, we still need crossgen2 to perform R2R compilation on the runtime assemblies.

    And crossgen2 gets built without NativeAOT to do this.

    We use nativeaot to optimize crossgen2 where possible

    This applies NativeAOT to crossgen2 application itself. We don't ship it.

    This optimization doesn't improve the resulting runtime assemblies after R2R compilation (I assume).

  7. jkotas commented on Aug 29, 2022

    @jkotas
    Member

    I think this means we have no need to build NativeAOT support for source-build in .NET 7.

    I agree.

    This optimization doesn't improve the resulting runtime assemblies after R2R compilation (I assume).

    Correct.

  8. tmds commented on Sep 14, 2022

    @tmds
    Member

    If you specify true property in your .csproj, SDK will add native AOT package for you and the package gets downloaded from nuget during project restore.

    @jkotas, Microsoft's .NET 7 preview 7 includes ./sdk/7.0.100-preview.7.22377.5/Sdks/Microsoft.DotNet.ILCompiler.

    Does that mean it doesn't get downloaded from nuget, and we should build it from source?

  9. jkotas commented on Sep 14, 2022

    @jkotas
    Member

    Microsoft's .NET 7 preview 7 includes ./sdk/7.0.100-preview.7.22377.5/Sdks/Microsoft.DotNet.ILCompiler

    I have discovered that just a few days ago as well. Related problem is that we are bundling more stuff into the SDK than what should be required (dotnet/runtime#75468 is opened on that).

    We either need to figure out how to remove the binaries from what we are bundling into SDK and/or we need to start building the package as part of the source build.

    @LakshanF Could you please look into this?

  10. sbomer commented on Sep 14, 2022

    @sbomer
    Member

    From my point of view, it would make sense to source-build the Microsoft.DotNet.ILCompiler package for 7.0. This would put us into a similar situation to crossgen, where the .target files are also bundled with the SDK (the difference is the crossgen targets actually live in SDK instead of flowing in from runtime).

    I agree that we should eventually move the targets out of the bundled package to fix versioning issues, but I would hesitate to do so in 7.0 because the SDK doesn't have a way to import targets from the dynamically-downloaded "runtime packs" (the mechanism used for crossgen). We would need to work around this limitation and replace it with an implicit PackageReference, which could require changes to the targets logic. I'm happy to help in case we do want this to get fixed in 7.0.

  11. tmds commented on Sep 15, 2022

    @tmds
    Member

    Is it correct that the SDK doesn't actually contain the ILCompiler (that is: the thing that does nativeaot), but it contains parts of the ILCompiler package so the SDK knows how to get the actual ILCompiler from nuget.org?

  12. sbomer commented on Sep 15, 2022

    @sbomer
    Member

    Yes, roughly. The Microsoft.DotNet.ILCompiler package doesn't include the ILCompiler executable. It has logic for locating the version of the actual compiler bits downloaded by the SDK from nuget. It also contains some MSBuild logic: tasks like ComputeManagedAssembliesToCompileToNative, and .targets that compute the command-line arguments to the compiler.

  13. moved this from 7.0 Backlog to WIP in .NET Source Buildon Sep 22, 2022
  14. crummel commented on Sep 26, 2022

    @crummel
    ContributorAuthor

    I've summarized what I believe to be the current state of play and the agreed-upon solution for NativeAOT in 7.0 in dotnet/runtime#76206. Please check this out and let me know if you have any concerns.

  15. MichaelSimons commented on Oct 11, 2022

    @MichaelSimons
    Member

    NativeAOT support removed from net 7.0 source-build with dotnet/installer#14697 - closing

  16. Repository owner moved this from WIP to Done in .NET Source Buildon Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-product-experience

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions