1 <Project Sdk="Microsoft.NET.Sdk">
3 <OutputPath>$(RuntimeBinDir)ilc/</OutputPath>
4 <RuntimeIdentifier>$(PackageRID)</RuntimeIdentifier>
7 <Import Project="ILCompiler.props" />
10 <!-- BEGIN: Workaround for https://github.com/dotnet/runtime/issues/67742 -->
11 <PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
12 <PublishDir>$(RuntimeBinDir)ilc-published/</PublishDir>
13 <!-- Can't use NativeAOT in source build yet https://github.com/dotnet/runtime/issues/66859 -->
14 <NativeAotSupported Condition="'$(DotNetBuildFromSource)' == 'true'">false</NativeAotSupported>
15 <NativeAotSupported Condition="$(OutputRID.StartsWith('tizen')) == 'true'">false</NativeAotSupported>
16 <!-- Disable native AOT on FreeBSD when cross building from Linux. -->
17 <NativeAotSupported Condition="'$(TargetOS)' == 'freebsd' and '$(CrossBuild)' == 'true'">false</NativeAotSupported>
18 <PublishAot Condition="'$(NativeAotSupported)' == 'true'">true</PublishAot>
19 <SysRoot Condition="'$(NativeAotSupported)' == 'true' and '$(CrossBuild)' == 'true' and '$(HostOS)' != 'windows'">$(ROOTFS_DIR)</SysRoot>
20 <PublishReadyToRun Condition="'$(NativeAotSupported)' != 'true'">true</PublishReadyToRun>
21 <PublishSingleFile Condition="'$(NativeAotSupported)' != 'true'">true</PublishSingleFile>
22 <PublishTrimmed Condition="'$(NativeAotSupported)' != 'true'">true</PublishTrimmed>
23 <SuppressGenerateILCompilerExplicitPackageReferenceWarning>true</SuppressGenerateILCompilerExplicitPackageReferenceWarning>
24 <!-- Compute host package name (taken from Microsoft.DotNet.ILCompiler.SingleEntry.targets) -->
25 <_hostOS>$(NETCoreSdkPortableRuntimeIdentifier.SubString(0, $(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-'))))</_hostOS>
26 <_hostArchitecture Condition="'$(OS)' != 'Windows_NT'">$(NETCoreSdkPortableRuntimeIdentifier.SubString($([MSBuild]::Add($(NETCoreSdkPortableRuntimeIdentifier.LastIndexOf('-')), 1))))</_hostArchitecture>
27 <_hostArchitecture Condition="'$(OS)' == 'Windows_NT'">$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant)</_hostArchitecture>
28 <_hostPackageName>runtime.$(_hostOS)-$(_hostArchitecture).Microsoft.DotNet.ILCompiler</_hostPackageName>
31 <ItemGroup Condition="'$(NativeAotSupported)' == 'true'">
32 <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="$(MicrosoftDotNetILCompilerVersion)" />
33 <PackageReference Include="$(_hostPackageName)" Version="$(MicrosoftDotNetILCompilerVersion)" />
36 <!-- Needed for the amd64 -> amd64 musl cross-build to pass the target flag. -->
37 <Target Name="_FixIlcTargetTriple"
38 AfterTargets="SetupOSSpecificProps"
39 Condition="'$(CrossBuild)' == 'true' and '$(HostOS)' != 'windows'">
40 <!-- Compute CrossCompileRid, and copy the downstream logic as-is. -->
42 <CrossCompileRid>$(RuntimeIdentifier)</CrossCompileRid>
45 <CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-x64'))">x86_64</CrossCompileArch>
46 <CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-arm64')) and '$(_IsApplePlatform)' != 'true'">aarch64</CrossCompileArch>
47 <CrossCompileArch Condition="$(CrossCompileRid.EndsWith('-arm64')) and '$(_IsApplePlatform)' == 'true'">arm64</CrossCompileArch>
50 <TargetTriple Condition="'$(CrossCompileArch)' != ''">$(CrossCompileArch)-linux-gnu</TargetTriple>
51 <TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('linux-musl')) or $(CrossCompileRid.StartsWith('alpine')))">$(CrossCompileArch)-alpine-linux-musl</TargetTriple>
52 <TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
56 <LinkerArg Include="--target=$(TargetTriple)" Condition="'$(_IsApplePlatform)' != 'true' and '$(TargetTriple)' != ''" />
60 <Target Name="LocateNativeCompiler"
61 Condition="'$(NativeAotSupported)' == 'true' and '$(HostOS)' != 'windows'"
62 BeforeTargets="SetupOSSpecificProps">
64 <CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
67 <Exec Command="sh -c 'build_arch="$(TargetArchitecture)" compiler="$(CppCompilerAndLinker)" . "$(RepositoryEngineeringDir)/common/native/init-compiler.sh" && echo "$CC;$LDFLAGS"' 2>/dev/null"
69 ConsoleToMsBuild="true"
70 StandardOutputImportance="Low">
71 <Output TaskParameter="ConsoleOutput" PropertyName="_CC_LDFLAGS" />
75 <CppLinker>$(_CC_LDFLAGS.SubString(0, $(_CC_LDFLAGS.IndexOf(';'))))</CppLinker>
76 <_LDFLAGS>$(_CC_LDFLAGS.SubString($([MSBuild]::Add($(_CC_LDFLAGS.IndexOf(';')), 1))))</_LDFLAGS>
77 <LinkerFlavor Condition="$(_LDFLAGS.Contains('lld'))">lld</LinkerFlavor>
81 <ItemGroup Condition="'$(NativeAotSupported)' == 'true'">
82 <CustomLinkerArg Condition="'$(CrossBuild)' == 'true' and '$(_hostArchitecture)' == '$(_targetArchitecture)' and '$(_hostOS)' != 'windows' and '$(_IsApplePlatform)' != 'true'" Include="--gcc-toolchain=$(ROOTFS_DIR)/usr" />
85 <Target Name="PublishCompiler"
86 Condition="'$(BuildingInsideVisualStudio)' != 'true'"
88 DependsOnTargets="Publish;StompSingleFileHostPath" />
90 <!-- HACK: liveBuilds stomps over SingleFileHostSourcePath, setting it to the host that we just built.
91 That's unfortunate because it's not the host we're supposed to use here. -->
92 <Target Name="StompSingleFileHostPath"
93 BeforeTargets="ResolveFrameworkReferences">
95 <SingleFileHostSourcePath></SingleFileHostSourcePath>
98 <!-- END: Workaround for https://github.com/dotnet/runtime/issues/67742 -->