Skip to content
Draft
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
1 change: 1 addition & 0 deletions dotnet/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ $(1)_NUGET_TARGETS = \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Microsoft.$(1).Sdk.Versions.props \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Microsoft.$(1).Sdk.targets \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Microsoft.Sdk.Eol.targets \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Microsoft.Sdk.R2R.targets \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Xamarin.Shared.Sdk.DefaultItems.targets \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Xamarin.Shared.Sdk.Publish.targets \
$(DOTNET_DESTDIR)/$($(1)_NUGET_SDK_NAME)/targets/Xamarin.Shared.Sdk.TargetFrameworkInference.props \
Expand Down
334 changes: 334 additions & 0 deletions dotnet/targets/Microsoft.Sdk.R2R.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,334 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Workaround for https://github.com/dotnet/runtime/issues/79902 -->
<Target Name="_FixR2ROutputPaths" AfterTargets="_PrepareForReadyToRunCompilation">
<ItemGroup>
<_ReadyToRunFilesToPublishFixed Include="@(_ReadyToRunFilesToPublish->'$(_ReadyToRunOutputPath)/%(Filename)%(Extension)')" />
<_ReadyToRunFilesToPublish Remove="@(_ReadyToRunFilesToPublish)" />
<_ReadyToRunFilesToPublish Include="@(_ReadyToRunFilesToPublishFixed)" />
</ItemGroup>
</Target>

<!-- TODO: Remove ResolveReadyToRunCompilers target -->
<!-- This shouldn't be necessary once we get https://github.com/dotnet/dotnet/pull/3754 -->
<Target Name="ResolveReadyToRunCompilers" Condition="'$(PublishReadyToRun)' == 'true' And '$(UseMonoRuntime)' != 'true'">
<PropertyGroup>
<_Crossgen2Path Condition="'$(Crossgen2Path)' != ''">$(Crossgen2Path)</_Crossgen2Path>
<_FlattenedCrossgen2Packs>@(ResolvedCrossgen2Pack->'%(PackageDirectory)')</_FlattenedCrossgen2Packs>
<_Crossgen2Path Condition="'$(Crossgen2Path)' == ''">$(_FlattenedCrossgen2Packs)/tools/crossgen2</_Crossgen2Path>

<_TargetArch>$(RuntimeIdentifier.Split('-')[1])</_TargetArch>
<_TargetOS>$(RuntimeIdentifier.Split('-')[0])</_TargetOS>
</PropertyGroup>

<ItemGroup>
<Crossgen2Tool Include="$(_Crossgen2Path)"
TargetArch="$(_TargetArch)"
TargetOS="$(_TargetOS)"
PerfmapFormatVersion="$(PublishReadyToRunPerfmapFormatVersion)"/>
</ItemGroup>

<Message Text="Using crossgen2: $(_Crossgen2Path)" Importance="high" />
<Message Text=" RuntimeIdentifier: $(RuntimeIdentifier)" Importance="high" />
<Message Text=" TargetArch: $(_TargetArch)" Importance="high" />
<Message Text=" TargetOS: $(_TargetOS)" Importance="high" />

<Error Condition="!Exists('$(_Crossgen2Path)')" Text="The crossgen2 executable '$(_Crossgen2Path)' does not exist." />
</Target>

<!-- Set some default properties -->
<PropertyGroup Condition="'$(PublishReadyToRun)' == 'true' And '$(UseMonoRuntime)' == 'false' And '$(_UseNativeAot)' != 'true'">
<CreateR2RFramework Condition="'$(CreateR2RFramework)' == '' ">true</CreateR2RFramework>
<CreateR2RDylib Condition="'$(CreateR2RDylib)' == '' And '$(CreateR2RFramework)' != 'true'">true</CreateR2RDylib>

<FilterReadyToRunAssemblies Condition="'$(FilterReadyToRunAssemblies)' == '' And '$(Configuration)' == 'Release'">true</FilterReadyToRunAssemblies>

<!-- This shouldn't be necessary once we get https://github.com/dotnet/dotnet/pull/3754 -->
<PublishReadyToRunCrossgen2ExtraArgs>--obj-format:macho</PublishReadyToRunCrossgen2ExtraArgs>
</PropertyGroup>


<!-- Exclude user assemblies from R2R composite so they run interpreted for debugging -->
<Target Name="_SelectR2RAssemblies"
Condition="'$(FilterReadyToRunAssemblies)' == 'true'"
BeforeTargets="ResolveReadyToRunCompilers">
<ItemGroup>
<_ResolvedAssembliesToPublish Include="@(ResolvedFileToPublish)" Condition="'%(Extension)' == '.dll' And '%(ResolvedFileToPublish.Culture)' == '' And '%(ResolvedFileToPublish.DestinationSubDirectory)' == ''" />
<_NonUserAssemblies
Include="@(_ResolvedAssembliesToPublish)"
Condition="(
'%(_ResolvedAssembliesToPublish.NuGetPackageId)' == 'Microsoft.NETCore.App.Ref' Or
'%(_ResolvedAssembliesToPublish.NuGetPackageId)' == '$(_MonoNugetPackageId)' Or
'%(_ResolvedAssembliesToPublish.NuGetPackageId)' == '$(_XamarinNugetPackageId)' Or
'%(_ResolvedAssembliesToPublish.NuGetPackageId)' == '$(_XamarinNugetManagedPackageId)'
)" />
<_UserAssemblies Include="@(_ResolvedAssembliesToPublish)" Exclude="@(_NonUserAssemblies)" />
<PublishReadyToRunExcludeTest Include="@(_UserAssemblies -> '%(Filename)')" />
</ItemGroup>
</Target>

<!--
The following section is to create either a .dylib or a .framework from the Composite
ReadyToRun output (which is an object file, which must be linked into a dynamic library).
-->

<!-- Create a framework from the composite R2R output -->
<PropertyGroup>
<_CreateR2RFrameworkDependsOn>
_PrepareR2RFrameworkCreation;
_CreateR2RFrameworkStructure;
_ForceLinkR2RFramework;
_LinkR2RFramework;
</_CreateR2RFrameworkDependsOn>
</PropertyGroup>

<!-- Prepare properties and item groups for r2r framework creation -->
<Target Name="_PrepareR2RFrameworkCreation"
DependsOnTargets="CreateReadyToRunImages"
>
<PropertyGroup>
<_DesktopFramework Condition="'$(_PlatformName)' == 'macOS' Or '$(_PlatformName)' == 'MacCatalyst'">true</_DesktopFramework>
<_DesktopFramework Condition="'$(_PlatformName)' != 'macOS' And '$(_PlatformName)' != 'MacCatalyst'">false</_DesktopFramework>

<_R2RFrameworkBinaryInfix Condition="'$(_DesktopFramework)' == 'true'">/Versions/A</_R2RFrameworkBinaryInfix>
<_R2RFrameworkResourcesInfix Condition="'$(_DesktopFramework)' == 'true'">/Versions/A/Resources</_R2RFrameworkResourcesInfix>

<_R2RFrameworkIntermediateOutputPath Condition="'$(_R2RFrameworkIntermediateOutputPath)' == ''">$(DeviceSpecificIntermediateOutputPath)r2rframework/</_R2RFrameworkIntermediateOutputPath>
<_R2RFrameworkName Condition="'$(_R2RFrameworkName)' == ''">$(AssemblyName)</_R2RFrameworkName>
<_R2RFrameworkPath Condition="'$(_R2RFrameworkPath)' == ''">$(_R2RFrameworkIntermediateOutputPath)$(_R2RFrameworkName).framework</_R2RFrameworkPath>
<_R2RFrameworkOutput Condition="'$(_R2RFrameworkOutput)' == ''">$(_R2RFrameworkPath)$(_R2RFrameworkBinaryInfix)/$(_R2RFrameworkName)</_R2RFrameworkOutput>

<_R2RFrameworkStructureStampFile>$(_R2RFrameworkIntermediateOutputPath)$(_R2RFrameworkName)-structure.stamp</_R2RFrameworkStructureStampFile>

<_R2RFrameworkInfoPlistPath>$(_R2RFrameworkPath)$(_R2RFrameworkResourcesInfix)/Info.plist</_R2RFrameworkInfoPlistPath>
</PropertyGroup>

<ItemGroup>
<_R2RFrameworkDirectories Include="$(_R2RFrameworkPath)" />

<_R2RFrameworkInputs Include="@(_ReadyToRunCompileList->'%(OutputR2RImage)')" />
<_R2RFrameworkLinkerFlags Include="-dynamiclib" />
<_R2RFrameworkLinkerFlags Include="-Wl,-dead_strip" />
<_R2RFrameworkLinkerFlags Include="-Wl,-install_name,@rpath/$(_R2RFrameworkName).framework/$(_R2RFrameworkName)" />

<_FrameworkNativeReference Include="$(_R2RFrameworkPath)/$(_R2RFrameworkName)" Kind="Framework" />
</ItemGroup>

<ItemGroup Condition="'$(_DesktopFramework)' == 'true'">
<_R2RFrameworkDirectories Include="$(_R2RFrameworkPath)/Versions/A/Resources" />

<_R2RFrameworkSymlinks Include="$(_R2RFrameworkPath)/Resources" SymlinkTo="Versions/A/Resources" />
<_R2RFrameworkSymlinks Include="$(_R2RFrameworkPath)/$(_R2RFrameworkName)" SymlinkTo="Versions/A/$(_R2RFrameworkName)" />
<_R2RFrameworkSymlinks Include="$(_R2RFrameworkPath)/Versions/Current" SymlinkTo="A" />
</ItemGroup>

<!-- write a hash of all the relevant input so that we can force a re-link if necessary -->
<PropertyGroup>
<_R2RFrameworkCachePath>$(_R2RFrameworkIntermediateOutputPath)cache.txt</_R2RFrameworkCachePath>
<_R2RFrameworkCachePath2>$(_R2RFrameworkCachePath).uptodate</_R2RFrameworkCachePath2>
</PropertyGroup>
<ItemGroup>
<_R2RFrameworkCache Include="@(_R2RFrameworkInputs)" />
<_R2RFrameworkCache Include="@(_R2RFrameworkLinkerFlags)" />
<_R2RFrameworkCache Include="$(_R2RFrameworkOutput)" />
<_R2RFrameworkCache Include="$(_MinimumOSVersion)" />
</ItemGroup>

<Hash
ItemsToHash="@(_R2RFrameworkCache)"
IgnoreCase="false">
<Output TaskParameter="HashResult" PropertyName="_R2RFrameworkCacheHash" />
</Hash>

<WriteLinesToFile Lines="$(_R2RFrameworkCacheHash)" File="$(_R2RFrameworkCachePath)" Overwrite="true" WriteOnlyWhenDifferent="true" />

<ItemGroup>
<FileWrites Include="$(_R2RFrameworkCachePath)" />
</ItemGroup>
</Target>

<Target Name="_CreateR2RFrameworkStructure"
Outputs="$(_R2RFrameworkStructureStampFile)"
>

<MakeDir
SessionId="$(BuildSessionId)"
Directories="@(_R2RFrameworkDirectories)"
/>

<Exec
SessionId="$(BuildSessionId)"
Command="ln -fs &quot;%(SymlinkTo)&quot; &quot;@(_R2RFrameworkSymlinks)&quot;"
Condition="@(_R2RFrameworkSymlinks->Count()) &gt; 0"
/>

<CompileAppManifest
SessionId="$(BuildSessionId)"
AppBundleName="$(_R2RFrameworkName)"
ApplicationId="$(_BundleIdentifier).r2rframework"
AssemblyName="$(_R2RFrameworkName)"
BundleExecutable="$(_R2RFrameworkName)"
CompiledAppManifest="$(_R2RFrameworkInfoPlistPath)"
Debug="$(_BundlerDebug)"
DefaultSdkVersion="$(_SdkVersion)"
GenerateApplicationManifest="true"
IsAppExtension="false"
IsFramework="true"
MinSupportedOSPlatformVersion="$(MinSupportedOSPlatformVersion)"
ProjectDir="$(MSBuildProjectDirectory)"
ResourcePrefix="$(_ResourcePrefix)"
SdkIsSimulator="$(_SdkIsSimulator)"
SdkVersion="$(_SdkVersion)"
SupportedOSPlatformVersion="$(SupportedOSPlatformVersion)"
TargetArchitectures="$(TargetArchitectures)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
/>

<Touch
Files="$(_R2RFrameworkStructureStampFile)"
AlwaysCreate="True"
/>

<ItemGroup>
<FileWrites Include="@(_R2RFrameworkSymlinks)" />
<FileWrites Include="$(_R2RFrameworkInfoPlistPath)" />
<FileWrites Include="$(_R2RFrameworkStructureStampFile)" />
</ItemGroup>
</Target>

<!-- force the r2r framework executable to be re-created by deleting the executable file-->
<Target Name="_ForceLinkR2RFramework"
Inputs="$(_R2RFrameworkCachePath)"
Outputs="$(_R2RFrameworkCachePath2)"
>
<Delete Files="$(_R2RFrameworkOutput)" />
<Copy SourceFiles="$(_R2RFrameworkCachePath)" DestinationFiles="$(_R2RFrameworkCachePath2)" />
<ItemGroup>
<FileWrites Include="$(_R2RFrameworkCachePath2)" />
</ItemGroup>
</Target>

<!-- link the object file created by the r2r compiler into a dynamic library we're going to put into the r2r framework -->
<Target Name="_LinkR2RFramework"
Inputs="@(_R2RFrameworkInputs)"
Outputs="$(_R2RFrameworkOutput)"
>

<MakeDir
SessionId="$(BuildSessionId)"
Directories="$(_R2RFrameworkPath)"
/>

<LinkNativeCode
SessionId="$(BuildSessionId)"
ObjectFiles="@(_R2RFrameworkInputs)"
OutputFile="$(_R2RFrameworkOutput)"
LinkerFlags="@(_R2RFrameworkLinkerFlags)"

MinimumOSVersion="$(_MinimumOSVersion)"
SdkDevPath="$(_SdkDevPath)"
SdkIsSimulator="$(_SdkIsSimulator)"
SdkRoot="$(_SdkRoot)"
TargetArchitectures="$(TargetArchitectures)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
/>
</Target>

<Target Name="_CreateR2RFramework"
Condition="'$(CreateR2RFramework)' == 'true'"
DependsOnTargets="$(_CreateR2RFrameworkDependsOn)"
AfterTargets="CreateReadyToRunImages"
/>

<!-- Create a dylib from the composite R2R output -->
<PropertyGroup>
<_CreateR2RDylibDependsOn>
_PrepareR2RDylibCreation;
_ForceLinkR2RDylib;
_LinkR2RDylib;
</_CreateR2RDylibDependsOn>
</PropertyGroup>

<Target Name="_PrepareR2RDylibCreation"
DependsOnTargets="CreateReadyToRunImages"
>
<PropertyGroup>
<_R2RDylibIntermediateOutputPath Condition="'$(_R2RFrameworkIntermediateOutputPath)' == ''">$(DeviceSpecificIntermediateOutputPath)r2rdylib/</_R2RDylibIntermediateOutputPath>
<_R2RDylibName Condition="'$(_R2RDylibName)' == ''">$(AssemblyName)</_R2RDylibName>
<_R2RDylibPath Condition="'$(_R2RDylibPath)' == ''">$(_R2RDylibIntermediateOutputPath)</_R2RDylibPath>
<_R2RDylibOutput Condition="'$(_R2RDylibOutput)' == ''">$(_R2RDylibPath)$(_R2RDylibName).r2r.dylib</_R2RDylibOutput>
</PropertyGroup>

<ItemGroup>
<_R2RDylibInputs Include="@(_ReadyToRunCompileList->'%(OutputR2RImage)')" />
<_R2RDylibLinkerFlags Include="-dynamiclib" />
<_R2RDylibLinkerFlags Include="-Wl,-dead_strip" />
<_R2RDylibLinkerFlags Include="-Wl,-install_name,@rpath/$(_R2RDylibName).r2r.dylib" />

<_FileNativeReference Include="$(_R2RDylibOutput)" Kind="Dynamic" />
</ItemGroup>

<!-- write a hash of all the relevant input so that we can force a re-link if necessary -->
<PropertyGroup>
<_R2RDylibCachePath>$(_R2RDylibIntermediateOutputPath)cache.txt</_R2RDylibCachePath>
<_R2RDylibCachePath2>$(_R2RDylibCachePath).uptodate</_R2RDylibCachePath2>
</PropertyGroup>
<ItemGroup>
<_R2RDylibCache Include="@(_R2RDylibInputs)" />
<_R2RDylibCache Include="@(_R2RDylibLinkerFlags)" />
<_R2RDylibCache Include="$(_R2RDylibOutput)" />
<_R2RDylibCache Include="$(_MinimumOSVersion)" />
</ItemGroup>

<Hash
ItemsToHash="@(_R2RDylibCache)"
IgnoreCase="false">
<Output TaskParameter="HashResult" PropertyName="_R2RDylibCacheHash" />
</Hash>

<WriteLinesToFile Lines="$(_R2RDylibCacheHash)" File="$(_R2RDylibCachePath)" Overwrite="true" WriteOnlyWhenDifferent="true" />

<ItemGroup>
<FileWrites Include="$(_R2RDylibCachePath)" />
</ItemGroup>
</Target>

<!-- force the r2r dylib to be re-created by deleting the executable file-->
<Target Name="_ForceLinkR2RDylib"
Inputs="$(_R2RDylibCachePath)"
Outputs="$(_R2RDylibCachePath2)"
>
<Delete Files="$(_R2RDylibOutput)" />
<Copy SourceFiles="$(_R2RDylibCachePath)" DestinationFiles="$(_R2RDylibCachePath2)" />
<ItemGroup>
<FileWrites Include="$(_R2RDylibCachePath2)" />
</ItemGroup>
</Target>

<!-- link the object file created by the r2r compiler into a dynamic library -->
<Target Name="_LinkR2RDylib"
Inputs="@(_R2RDylibInputs)"
Outputs="$(_R2RDylibOutput)"
>

<LinkNativeCode
SessionId="$(BuildSessionId)"
ObjectFiles="@(_R2RDylibInputs)"
OutputFile="$(_R2RDylibOutput)"
LinkerFlags="@(_R2RDylibLinkerFlags)"

MinimumOSVersion="$(_MinimumOSVersion)"
SdkDevPath="$(_SdkDevPath)"
SdkIsSimulator="$(_SdkIsSimulator)"
SdkRoot="$(_SdkRoot)"
TargetArchitectures="$(TargetArchitectures)"
TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)"
/>
</Target>

<Target Name="_CreateR2RDylib"
Condition="'$(CreateR2RDylib)' == 'true'"
DependsOnTargets="$(_CreateR2RDylibDependsOn)"
AfterTargets="CreateReadyToRunImages"
/>
</Project>
11 changes: 11 additions & 0 deletions dotnet/targets/Xamarin.Shared.Sdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@
<CustomNativeMain Condition="'$(OutputType)' == 'Exe'">true</CustomNativeMain>
</PropertyGroup>

<!-- ReadyToRun configuration for CoreCLR -->
<PropertyGroup Condition="'$(UseMonoRuntime)' == 'false' And '$(_PlatformName)' != 'macOS' And '$(_UseNativeAot)' != 'true'">
<PublishReadyToRun Condition="'$(PublishReadyToRun)' == ''">true</PublishReadyToRun>
<PublishReadyToRunComposite Condition="'$(PublishReadyToRunComposite)' == '' And '$(PublishReadyToRun)' == 'true'">true</PublishReadyToRunComposite>
<PublishReadyToRunContainerFormat Condition="'$(PublishReadyToRunContainerFormat)' == '' And '$(PublishReadyToRun)' == 'true'">macho</PublishReadyToRunContainerFormat>
</PropertyGroup>

<ItemGroup Condition="'$(UseMonoRuntime)' == 'false' And '$(_PlatformName)' != 'macOS' And '$(PublishReadyToRun)' != 'true'">
<_BundlerEnvironmentVariables Include="DOTNET_ReadyToRun" Value="0" />
</ItemGroup>

<!-- Compute _SdkIsSimulator from the RuntimeIdentifier -->
<PropertyGroup>
<_SdkIsSimulator Condition="'$(RuntimeIdentifier)' != '' And '$(_SdkIsSimulator)' == ''">$(RuntimeIdentifier.Contains('simulator'))</_SdkIsSimulator>
Expand Down
10 changes: 2 additions & 8 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@
PartialStaticRegistrarLibrary=$(_LibPartialStaticRegistrar)
Platform=$(_PlatformName)
PlatformAssembly=$(_PlatformAssemblyName).dll
PublishReadyToRun=$(PublishReadyToRun)
RelativeAppBundlePath=$(_RelativeAppBundlePath)
Registrar=$(Registrar)
@(ReferenceNativeSymbol -> 'ReferenceNativeSymbol=%(SymbolType):%(SymbolMode):%(Identity)')
Expand Down Expand Up @@ -1267,13 +1268,6 @@
"
/>
</ItemGroup>

<!-- CoreCLR: these are variables currently needed to make CoreCLR work -->
<ItemGroup Condition="'$(UseMonoRuntime)' == 'false' And '$(_PlatformName)' != 'macOS'">
<!-- Only the interpreter works so far, so make sure only the interpreter executes and that everything is executed with the interpreter -->
<_BundlerEnvironmentVariables Include="DOTNET_Interpreter" Value="%2A%21%2A" /> <!-- This is the string "*!*" url encoded -->
<_BundlerEnvironmentVariables Include="DOTNET_ReadyToRun" Value="0" />
</ItemGroup>
</Target>

<!-- App bundle creation tasks -->
Expand Down Expand Up @@ -2786,5 +2780,5 @@ global using nfloat = global::System.Runtime.InteropServices.NFloat%3B

<Import Project="dotnet-xcsync.targets" />
<Import Project="Microsoft.MaciOS.Sdk.Xcode.targets" />

<Import Project="Microsoft.Sdk.R2R.targets" />
</Project>
Loading
Loading