Skip to content
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

Allow building with PublishAot set #28495

Closed
wants to merge 12 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Microsoft.DotNet.Build.Tasks
/// and then update the stage 0 back.
///
/// Override NETCoreSdkVersion to stage 0 sdk version like 6.0.100-dev
///
///
/// Use a task to override since it was generated as a string literal replace anyway.
/// And using C# can have better error when anything goes wrong.
/// </summary>
Expand Down Expand Up @@ -123,6 +123,12 @@ void CheckAndReplaceAttribute(XAttribute attribute)
crossgen2Rids.Value += ";osx-x64";
}

// Currently has too many RIDs. We only want to include the RIDs of actual packages we
// produce, as if don't try to download a missing package then restore will succeed and
// we can give a better error during publish that the given RID is not supported.
var ilcompilerRids = itemGroup.Elements(ns + "KnownILCompilerPack").First().Attribute("ILCompilerRuntimeIdentifiers");
ilcompilerRids.Value = "linux-x64;linux-musl-x64;linux-arm64;linux-musl-arm64;win-x64;win-arm64;osx-x64";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we shouldn't hard-code the supported RuntimeIdentifiers in a C# task. What's the reason for the mismatch between the values coming from the item and what's actually supported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mismatch is that we were trying to avoid blocking people who wanted to use unsupported, but available packages.

But being too broad here actually causes problems because attempting to download a missing package blocks restore/build.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to have browser-wasm here for NativeAOT-LLVM support.


CheckAndReplaceAttribute(itemGroup
.Elements(ns + "KnownRuntimePack").First().Attribute("LatestRuntimeFrameworkVersion"));

Expand Down
4 changes: 4 additions & 0 deletions src/Tasks/Common/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -875,4 +875,8 @@ You may need to build the project on another operating system or architecture, o
<value>NETSDK1192: Targeting .NET 7.0 or higher in Visual Studio 2022 17.3 is not supported.</value>
<comment>{StrBegin="NETSDK1192: "}</comment>
</data>
<data name="PublishAotRidNotSupported" xml:space="preserve">
<value>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</value>
<comment>{StrBegin="NETSDK1193: "}</comment>
</data>
</root>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: Nástroje projektu (DotnetCliTool) podporují jen cílení na .NET Core 2.2 a nižší.</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: Kompilace ReadyToRun se přeskočí, protože se podporuje jen pro architekturu .NET Core 3.0 a vyšší.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: Projekttools (DotnetCliTool) unterstützen als Ziel nur .NET Core 2.2 und früher.</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: Die ReadyToRun-Kompilierung wird übersprungen, weil sie nur für .NET Core 3.0 oder höher unterstützt wird.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: Las herramientas de proyecto (DotnetCliTool) solo admiten como destino .NET Core 2.2 y versiones inferiores.</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: Se omitirá la compilación de ReadyToRun porque solo se admite para .NET Core 3.0 o versiones posteriores.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: les outils de projet (DotnetCliTool) prennent uniquement en charge le ciblage de .NET Core 2.2 et des versions antérieures.</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: la compilation ReadyToRun va être ignorée, car elle est uniquement prise en charge pour .NET Core 3.0 ou une version ultérieure.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: gli strumenti del progetto (DotnetCliTool) supportano come destinazione solo .NET Core 2.2 e versioni precedenti.</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: la compilazione eseguita con ReadyToRun verrà ignorata perché è supportata solo per .NET Core 3.0 o versioni successive.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: プロジェクト ツール (DotnetCliTool) は、ターゲットが .NET Core 2.2 以下の場合のみサポートされます。</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: ReadyToRun コンパイルは、.NET Core 3.0 以降でのみサポートされているため、スキップされます。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: 프로젝트 도구(DotnetCliTool)는 .NET Core 2.2 이하를 대상으로 하는 경우만 지원합니다.</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: ReadyToRun 컴파일은 .NET Core 3.0 이상에서만 지원되므로 건너뜁니다.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: Narzędzia projektu (DotnetCliTool) obsługują tylko ukierunkowanie na program .NET Core w wersji 2.2 lub niższej.</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: Kompilacja ReadyToRun zostanie pominięta, ponieważ jest obsługiwana tylko w przypadku platformy .NET Core 3.0 lub nowszej.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: as ferramentas do projeto (DotnetCliTool) dão suporte somente para o direcionamento ao .NET Core 2.2 e inferior.</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: a compilação de ReadyToRun será ignorada porque ela é compatível apenas com o .NET Core 3.0 ou superior.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: средства проекта (DotnetCliTool) поддерживают только целевую платформу .NET Core 2.2 и более ранних версий.</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: компиляция ReadyToRun будет пропущена, так как она поддерживается только для .NET Core 3.0 или более поздних версий.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: Proje araçları (DotnetCliTool) yalnızca .NET Core 2.2 veya daha düşük sürümünü hedeflemeyi destekliyor.</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: ReadyToRun derlemesi, yalnızca .NET Core 3.0 veya üzeri için desteklendiğinden atlanacak.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: NETSDK1093: 项目工具(DotnetCliTool)仅支持面向 .NET Core 2.2 及更低版本。</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: 将跳过 ReadyToRun 编译,因为只有 .NET Core 3.0 或更高版本才支持该编译。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ The following are names of parameters or literal values and should not be transl
<target state="translated">NETSDK1093: 專案工具 (DotnetCliTool) 僅支援以 .NET Core 2.2 或更低版本作為目標。</target>
<note>{StrBegin="NETSDK1093: "}</note>
</trans-unit>
<trans-unit id="PublishAotRidNotSupported">
<source>NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</source>
<target state="new">NETSDK1193: AOT publishing with RID '{0}' is not currently supported.</target>
<note>{StrBegin="NETSDK1193: "}</note>
</trans-unit>
<trans-unit id="PublishReadyToRunRequiresVersion30">
<source>NETSDK1122: ReadyToRun compilation will be skipped because it is only supported for .NET Core 3.0 or higher.</source>
<target state="translated">NETSDK1122: 將跳過 ReadyToRun 編譯,原因是只有 .NET Core 3.0 或更高版本支援此作業。</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,9 @@ var runtimeRequiredByDeployment

if (AotEnabled)
{
if (!AddAotOrR2RRuntimePackage(AotPackageType.ILCompiler, _normalizedTargetFrameworkVersion, packagesToDownload))
{
Log.LogError(Strings.AotNoValidRuntimePackageError);
return;
}
// Add the package to the download list if the package is registered, even if the RID isn't officially supported.
// Erroring during restore provides a worse user experience than providing some other error later.
_ = AddAotOrR2RRuntimePackage(AotPackageType.ILCompiler, _normalizedTargetFrameworkVersion, packagesToDownload);
}

if (packagesToDownload.Any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>
</Target>

<PropertyGroup>
<_AotSupportedRids>;linux-x64;linux-arm64;linux-musl-x64;linux-musl-arm64;win-x64;win-arm64;</_AotSupportedRids>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually when we add support for new RuntimeIdentifiers that ends up getting authored in the installer repo and flowing into items such as the KnownFrameworkReference or other items in Microsoft.NETCoreSdk.BundledVersions.props. Should we do that for this? How would we support it if we add support for new RuntimeIdentifiers for AoT, and the list of supported RIDs depends on the target framework?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the list above (which is the supported list that flows from /installer), is not quite the same as the supported rids here, namely that osx-x64 is in the "to download" list but not in the "supported" list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that matters for unsupported architectures is that there is some way for people who want to give it try. It does not need to be pretty. It is ok if it requires extra boilerplate like explicit reference to the osx package.

Does the new SkipAotSupportedCheck property enable that? If yes, I think it would be fine to get rid of this special-casing for available, but officially unsupported architectures.

</PropertyGroup>

<!--
============================================================
PrepareForPublish
Expand Down Expand Up @@ -111,10 +115,15 @@ Copyright (c) .NET Foundation. All rights reserved.
'$(EnableCompressionInSingleFile)' == 'true' And
'$(SelfContained)' != 'true'"
ResourceName="CompressionInSingleFileRequiresSelfContained" />
<NETSdkError Condition="'$(PublishAot)' == 'true' And
'$(_SkipAotSupportedRidCheck)' != 'true' And
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have similar property in
https://github.com/dotnet/runtime/blob/cb6fb60dfc253bc13655fafa15686cb864fd0ea2/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets#L58 .

Would it make sense to use one property to suppress all these supported checks?

  • Rename _SkipAotSupportedRidCheck -> SkipAotSupportedCheck here
  • Rename DisableUnsupportedError to SkipAotSupportedCheck in dotnet/runtime.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, but I'd like to do that as a separate change, as I intend for this to go into .NET 7 as a servicing fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you agree that we should use the same property name in all places, the property should be renamed in this servicing fix.

$(_AotSupportedRids.Contains(';$(NETCoreSdkRuntimeIdentifier);')) != 'true'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking whether a string contains the RuntimeIdentifier, shouldn't we be checking to see whether there is a valid HostILCompilerPack or TargetILCompilerPack instead for this error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because osx-x64 has an ILCompilerPack, but isn't supported.

ResourceName="PublishAotRidNotSupported"
FormatArguments="$(NETCoreSdkRuntimeIdentifier)" />

<!-- Enable warning for trying to use PublishRelease or PackRelease with a solution if env-var is not set.-->
<NETSdkWarning Condition="'$(PublishRelease)' != '' and '$(SolutionExt)' == '.sln' and '$(DOTNET_CLI_ENABLE_PUBLISH_RELEASE_FOR_SOLUTIONS)' == ''"
ResourceName="PReleaseRequiresEnvVarOnSln"
ResourceName="PReleaseRequiresEnvVarOnSln"
FormatArguments="PublishRelease;DOTNET_CLI_ENABLE_PUBLISH_RELEASE_FOR_SOLUTIONS"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<ItemGroup>
<KnownFrameworkReference Remove="Microsoft.Windows.SDK.NET.Ref" />
</ItemGroup>

<!-- Generate KnownFrameworkReference items for the Windows SDK pack -->
<CreateWindowsSdkKnownFrameworkReferences
UseWindowsSDKPreview="$(UseWindowsSDKPreview)"
Expand All @@ -42,7 +42,7 @@ Copyright (c) .NET Foundation. All rights reserved.
WindowsSdkSupportedTargetPlatformVersions="@(WindowsSdkSupportedTargetPlatformVersion)">

<Output TaskParameter="KnownFrameworkReferences" ItemName="KnownFrameworkReference" />

</CreateWindowsSdkKnownFrameworkReferences>
</Target>

Expand Down
Loading