Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,47 @@
<!--
This target hooks into the dotnet CLI publish pipeline. That pipeline has
a target called ComputeFilesToPublish which produces the ItemGroup
ResolvedFileToPublish based on the inputs of @(IntermediateAssembly)
and @(ResolvedAssembliesToPublish). We modify those two item groups
to control what gets published after NativeAOT optimizes the application.
ResolvedFileToPublish. We modify this item group to control what gets
published after NativeAOT optimizes the application.
-->
<Target Name="ComputeLinkedFilesToPublish"
BeforeTargets="ComputeResolvedFilesToPublishList"
AfterTargets="ComputeResolvedFilesToPublishList"
DependsOnTargets="_ComputeAssembliesToCompileToNative;LinkNative">

<ItemGroup>
<_ResolvedCopyLocalPublishAssets Remove="@(_AssembliesToSkipPublish)" />
<_ResolvedCopyLocalPublishAssets Include="@(_LinkedResolvedAssemblies)" />
<_DebugSymbolsIntermediatePath Remove="@(_DebugSymbolsIntermediatePath)" />
<ResolvedFileToPublish Remove="@(_AssembliesToSkipPublish)" />
<!-- dotnet CLI produces managed debug symbols, which we will replace with native symbols instead -->
<ResolvedFileToPublish Remove="@(_DebugSymbolsIntermediatePath)" />
<!-- replace apphost with binary we generated during native compilation -->
<ResolvedFileToPublish Include="@(IntermediateAssembly->'$(NativeOutputPath)%(Filename)$(NativeBinaryExt)')">
<RelativePath>%(Filename)$(NativeBinaryExt)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>

<ItemGroup>
<_NativeIntermediateAssembly Include="@(IntermediateAssembly->'$(NativeOutputPath)%(Filename)$(NativeBinaryExt)')" />
<IntermediateAssembly Remove="@(IntermediateAssembly)" />
<IntermediateAssembly Include="@(_NativeIntermediateAssembly)" />
<PropertyGroup Condition="'$(CopyOutputSymbolsToPublishDirectory)' == 'true'">
<_symbolExt Condition="'$(OS)' == 'Windows_NT'">$(NativeSymbolExt)</_symbolExt>
<_symbolExt Condition="'$(OS)' != 'Windows_NT'">$(NativeBinaryExt)$(NativeSymbolExt)</_symbolExt>
<_symbolSourcePath>$(NativeOutputPath)$(TargetName)$(_symbolExt)</_symbolSourcePath>
<_symbolTargetPath>$(PublishDir)\$(TargetName)$(_symbolExt)</_symbolTargetPath>
</PropertyGroup>

<ItemGroup Condition="'$(CopyOutputSymbolsToPublishDirectory)' == 'true'">
<_symbolRecursivePath Include="$(NativeOutputPath)$(TargetName)$(_symbolExt)/**/*" />

<!-- Add native symbol file if it exists. On Mac, the symbol path may be a folder-->
<ResolvedFileToPublish Include="$(_symbolSourcePath)"
Condition="'$(NativeSymbolExt)' != '.dSYM' and Exists('$(_symbolSourcePath)')">
<RelativePath>$(TargetName)$(_symbolExt)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>

<!-- Add folder otherwise. If the symbol is a dSYM bundle, it's a folder not a file. -->
<ResolvedFileToPublish Include="@(_symbolRecursivePath)"
Condition="'$(NativeSymbolExt)' == '.dSYM' and Exists('$(_symbolSourcePath)')">
<RelativePath>$(TargetName)$(_symbolExt)/%(RecursiveDir)%(Filename)%(Extension)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>
</ItemGroup>
</Target>

Expand Down Expand Up @@ -72,7 +95,7 @@
<Error Condition="'@(FrameworkAssemblies)' == '' and '$(PublishAotUsingRuntimePack)' != 'true'" Text="The FrameworkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative" />

<ComputeManagedAssembliesToCompileToNative
Assemblies="@(_ResolvedCopyLocalPublishAssets)"
Assemblies="@(ResolvedFileToPublish)"
DotNetAppHostExecutableName="$(_DotNetAppHostExecutableName)"
DotNetHostFxrLibraryName="$(_DotNetHostFxrLibraryName)"
DotNetHostPolicyLibraryName="$(_DotNetHostPolicyLibraryName)"
Expand All @@ -86,40 +109,7 @@

</Target>

<Target Name="CopyNativeBinary" AfterTargets="Publish">
<!-- replace apphost with binary we generated during native compilation -->
<Delete Files="$(PublishDir)\$(TargetName)$(NativeBinaryExt)" />
<Copy SourceFiles="$(NativeOutputPath)$(TargetName)$(NativeBinaryExt)" DestinationFolder="$(PublishDir)" />
</Target>

<Target Name="_CopyAotSymbols" AfterTargets="Publish"
Condition="'$(CopyOutputSymbolsToPublishDirectory)' == 'true'">
<!-- dotnet CLI produces managed debug symbols, which we will delete and copy native symbols instead -->
<Delete Files="$(PublishDir)\$(TargetName).pdb" />

<PropertyGroup>
<_symbolExt Condition="'$(OS)' == 'Windows_NT'">$(NativeSymbolExt)</_symbolExt>
<_symbolExt Condition="'$(OS)' != 'Windows_NT'">$(NativeBinaryExt)$(NativeSymbolExt)</_symbolExt>
<_symbolSourcePath>$(NativeOutputPath)$(TargetName)$(_symbolExt)</_symbolSourcePath>
<_symbolTargetPath>$(PublishDir)\$(TargetName)$(_symbolExt)</_symbolTargetPath>
<!-- If the symbol is a dSYM bundle, it's a folder not a file. -->
<_symbolIsFile Condition="'$(NativeSymbolExt)' == '.dSYM'">false</_symbolIsFile>
<_symbolIsFile Condition="'$(_symbolIsFile)' == ''">true</_symbolIsFile>
</PropertyGroup>

<ItemGroup>
<_symbolRecursivePath Include="$(NativeOutputPath)$(TargetName)$(_symbolExt)/**/*" />
</ItemGroup>

<!-- replace native symbol file if it exists. On Mac, the symbol path may be a folder-->
<Delete Files="$(_symbolTargetPath)" Condition="'$(_symbolIsFile)' == 'true' and Exists('$(_symbolTargetPath)')" />
<Copy SourceFiles="$(_symbolSourcePath)" DestinationFolder="$(PublishDir)"
Condition="'$(_symbolIsFile)' == 'true' and Exists('$(_symbolSourcePath)')" />

<!-- Copy folder otherwise -->
<RemoveDir Directories="$(_symbolTargetPath)" Condition="'$(_symbolIsFile)' == 'false' and Exists('$(_symbolTargetPath)')" />
<Copy SourceFiles="@(_symbolRecursivePath)" DestinationFolder="$(_symbolTargetPath)/%(RecursiveDir)"
Condition="'$(_symbolIsFile)' == 'false' and Exists('$(_symbolSourcePath)')" />
</Target>
<!-- Empty target to provide back-compat for other targets that run before/after CopyNativeBinary. -->
<Target Name="CopyNativeBinary" AfterTargets="Publish" />

</Project>
1 change: 1 addition & 0 deletions src/mono/msbuild/apple/build/AppleBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$(_ProcessRuntimeComponentsForLibraryMode);
$(_AotCompileTargetName);
_BuildNativeLibrary;
_PublishNativeBinary;
Copy link
Member

Choose a reason for hiding this comment

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

Remove this change, see my comment below.

_AppleGenerateAppBundle;
_AfterAppleBuild
</AppleBuildDependsOn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
<OutputPath>$([MSBuild]::NormalizeDirectory($(TestRootDir), '..', 'bin'))</OutputPath>
<PublishDir>$(OriginalPublishDir)</PublishDir>
<_IlcLibraryBuildDependsOn>LinkNative;CopyNativeBinary</_IlcLibraryBuildDependsOn>
<_IlcLibraryBuildDependsOn>LinkNative</_IlcLibraryBuildDependsOn>
<!-- we should not strip symbols from the generated library as xcode build will attempt to strip already stripped symbols -->
<StripSymbols>false</StripSymbols>
</PropertyGroup>
Expand Down
11 changes: 11 additions & 0 deletions src/mono/msbuild/common/LibraryBuilder.targets
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@
</LibraryBuilderTask>
</Target>

<Target Name="_PublishNativeBinary">
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should put this target here.

LibraryBuilder.props/targets are intended for Mono's library mode support, and none of the MSBuild targets from this file should be needed for NativeAOT (I admit there are other hacks which are advocating against this).

If I understand correctly, you added this target so that NativeAOT library mode has the previous CopyNativeBinary behavior, correct?

If that is the case, then I would:

  1. Move this target into AppleBuild.targets
  2. Remove it from AppleBuildDependsOn (see my comment above)
  3. Add it manually as a last dependency at:
    DependsOnTargets="SetupProperties;ComputeIlcCompileInputs;IlcCompile;$(_IlcLibraryBuildDependsOn)" />
  4. Put a condition on it: Condition="'$(_IsLibraryMode)' == 'true' and '$(UseNativeAOTRuntime)' == 'true'"

This way it does not affect: Mono app or lib builds, and it does not affect NativeAOT app builds. We will eventually clean all of this up in the internal props/targets as we now have experimental CoreCLR support for Apple as well.


<ItemGroup>
<_NativeBinaryFiles Include="@(IntermediateAssembly->'$(NativeOutputPath)%(Filename)$(NativeBinaryExt)')" />
</ItemGroup>

<Copy SourceFiles="@(_NativeBinaryFiles)"

Check failure on line 55 in src/mono/msbuild/common/LibraryBuilder.targets

View check run for this annotation

Azure Pipelines / runtime (Build maccatalyst-x64 Release AllSubsets_Mono)

src/mono/msbuild/common/LibraryBuilder.targets#L55

src/mono/msbuild/common/LibraryBuilder.targets(55,5): error MSB3023: (NETCORE_ENGINEERING_TELEMETRY=Build) No destination specified for Copy. Please supply either "DestinationFiles" or "DestinationFolder".
DestinationFolder="$(OriginalPublishDir)" />

</Target>

<Target Name="_GenerateBundle"
Condition="'$(BundlesResources)' != 'false'">
<PropertyGroup>
Expand Down
Loading