forked from valentinbreiz/nativeaot-patcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
101 lines (85 loc) · 7.7 KB
/
Directory.Build.targets
File metadata and controls
101 lines (85 loc) · 7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<Project>
<PropertyGroup>
<ToolCommonPath>$(MSBuildThisFileDirectory)dotnet\runtime\src\coreclr\tools\Common\</ToolCommonPath>
<AotCommonPath>$(MSBuildThisFileDirectory)dotnet\runtime\src\coreclr\nativeaot\Common\src\</AotCommonPath>
<AotRuntimeBasePath>$(MSBuildThisFileDirectory)dotnet\runtime\src\coreclr\nativeaot\Runtime.Base\src\</AotRuntimeBasePath>
<CompilerCommonPath>$(MSBuildThisFileDirectory)dotnet\runtime\src\coreclr\nativeaot\Common\src\</CompilerCommonPath>
</PropertyGroup>
<Target Name="EnforceKernelReferenceRules" BeforeTargets="BeforeBuild">
<PropertyGroup>
<IsExcluded>$(MSBuildProjectName).StartsWith('Cosmos.Kernel')</IsExcluded>
</PropertyGroup>
<ItemGroup>
<ForbiddenReference Include="@(ProjectReference)"
Condition="$(IsExcluded) == false and $([System.String]::Copy('%(ProjectReference.Identity)').Contains('Cosmos.Kernel.Boot'))" />
</ItemGroup>
<Error Condition="@(ForbiddenReference) != ''"
Text="Only the Cosmos.Kernel project may reference Cosmos.Kernel.Boot.* projects."
/>
</Target>
<!-- Pre-flight resolver to locate Homebrew cross-compilers before the SDK's GetGCC target runs -->
<Target Name="ResolveHomebrewGCC" Condition="'$(OS)' != 'Windows_NT'" BeforeTargets="GetGCC">
<PropertyGroup>
<!-- Mirror the architecture inference used by the GCC targets -->
<TargetArchitecture Condition="'$(RuntimeIdentifier)' != '' and '$(TargetArchitecture)' == ''">$([System.String]::Copy('$(RuntimeIdentifier)').Split('-')[1])</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(CosmosArch)' != ''">$(CosmosArch)</TargetArchitecture>
<!-- Detect common Homebrew prefixes (Apple Silicon and Intel) -->
<HomebrewPrefix Condition="'$(HomebrewPrefix)' == '' and Exists('/opt/homebrew/bin/brew')">/opt/homebrew</HomebrewPrefix>
<HomebrewPrefix Condition="'$(HomebrewPrefix)' == '' and Exists('/usr/local/bin/brew')">/usr/local</HomebrewPrefix>
</PropertyGroup>
<!-- macOS x64 cross toolchains installed via Homebrew (keg opt + linked bin) -->
<PropertyGroup>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'x64' and '$(HomebrewPrefix)' != '' and Exists('$(HomebrewPrefix)/opt/x86_64-elf-gcc/bin/x86_64-elf-gcc')">$(HomebrewPrefix)/opt/x86_64-elf-gcc/bin/x86_64-elf-gcc</GCCPath>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'x64' and '$(HomebrewPrefix)' != '' and Exists('$(HomebrewPrefix)/bin/x86_64-elf-gcc')">$(HomebrewPrefix)/bin/x86_64-elf-gcc</GCCPath>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'x64'">x86_64-elf-gcc</GCCPath>
</PropertyGroup>
<!-- macOS arm64 cross toolchains installed via Homebrew (keg opt + linked bin) -->
<PropertyGroup>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'arm64' and '$(HomebrewPrefix)' != '' and Exists('$(HomebrewPrefix)/opt/aarch64-elf-gcc/bin/aarch64-elf-gcc')">$(HomebrewPrefix)/opt/aarch64-elf-gcc/bin/aarch64-elf-gcc</GCCPath>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'arm64' and '$(HomebrewPrefix)' != '' and Exists('$(HomebrewPrefix)/bin/aarch64-elf-gcc')">$(HomebrewPrefix)/bin/aarch64-elf-gcc</GCCPath>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'arm64' and '$(HomebrewPrefix)' != '' and Exists('$(HomebrewPrefix)/opt/aarch64-linux-gnu-gcc/bin/aarch64-linux-gnu-gcc')">$(HomebrewPrefix)/opt/aarch64-linux-gnu-gcc/bin/aarch64-linux-gnu-gcc</GCCPath>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'arm64' and '$(HomebrewPrefix)' != '' and Exists('$(HomebrewPrefix)/bin/aarch64-linux-gnu-gcc')">$(HomebrewPrefix)/bin/aarch64-linux-gnu-gcc</GCCPath>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'arm64'">aarch64-elf-gcc</GCCPath>
</PropertyGroup>
<Message Text="[ResolveHomebrewGCC] TargetArchitecture=$(TargetArchitecture); GCCPath=$(GCCPath)" Importance="Low" Condition="'$(GCCPath)' != ''" />
</Target>
<!-- Stronger cross-compiler selection and validation ahead of BuildGCC -->
<Target Name="EnsureCrossCompiler" Condition="'$(OS)' != 'Windows_NT'" BeforeTargets="BuildGCC">
<PropertyGroup>
<!-- Normalize architecture if still unset -->
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(RuntimeIdentifier)' != ''">$([System.String]::Copy('$(RuntimeIdentifier)').Split('-')[1])</TargetArchitecture>
<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and '$(CosmosArch)' != ''">$(CosmosArch)</TargetArchitecture>
<!-- Gather Homebrew prefix (Apple Silicon first, then Intel) -->
<HomebrewPrefix Condition="'$(HomebrewPrefix)' == '' and Exists('/opt/homebrew/bin/brew')">/opt/homebrew</HomebrewPrefix>
<HomebrewPrefix Condition="'$(HomebrewPrefix)' == '' and Exists('/usr/local/bin/brew')">/usr/local</HomebrewPrefix>
<!-- Default executable names by architecture -->
<GCCExecutableName Condition="'$(TargetArchitecture)' == 'x64'">x86_64-elf-gcc</GCCExecutableName>
<GCCExecutableName Condition="'$(TargetArchitecture)' == 'arm64'">aarch64-elf-gcc</GCCExecutableName>
</PropertyGroup>
<!-- Set GCCPath from known Homebrew locations if caller has not set it -->
<PropertyGroup>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'x64' and '$(HomebrewPrefix)' != '' and Exists('$(HomebrewPrefix)/opt/x86_64-elf-gcc/bin/x86_64-elf-gcc')">$(HomebrewPrefix)/opt/x86_64-elf-gcc/bin/x86_64-elf-gcc</GCCPath>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'x64' and '$(HomebrewPrefix)' != '' and Exists('$(HomebrewPrefix)/bin/x86_64-elf-gcc')">$(HomebrewPrefix)/bin/x86_64-elf-gcc</GCCPath>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'arm64' and '$(HomebrewPrefix)' != '' and Exists('$(HomebrewPrefix)/opt/aarch64-elf-gcc/bin/aarch64-elf-gcc')">$(HomebrewPrefix)/opt/aarch64-elf-gcc/bin/aarch64-elf-gcc</GCCPath>
<GCCPath Condition="'$(GCCPath)' == '' and '$(TargetArchitecture)' == 'arm64' and '$(HomebrewPrefix)' != '' and Exists('$(HomebrewPrefix)/bin/aarch64-elf-gcc')">$(HomebrewPrefix)/bin/aarch64-elf-gcc</GCCPath>
</PropertyGroup>
<!-- Normalize any whitespace around GCCPath before validating/executing -->
<PropertyGroup>
<GCCPath Condition="'$(GCCPath)' != ''">$([System.String]::Copy('$(GCCPath)').Trim())</GCCPath>
</PropertyGroup>
<!-- Final fallback to executable name on PATH -->
<PropertyGroup>
<GCCPath Condition="'$(GCCPath)' == '' and '$(GCCExecutableName)' != ''">$(GCCExecutableName)</GCCPath>
</PropertyGroup>
<!-- Validate existence if GCCPath is an absolute path -->
<PropertyGroup>
<GCCPathExists Condition="'$(GCCPath)' != '' and $([System.IO.Path]::IsPathRooted('$(GCCPath)')) and Exists('$(GCCPath)')">true</GCCPathExists>
<GCCPathExists Condition="'$(GCCPathExists)' == ''">false</GCCPathExists>
</PropertyGroup>
<Message Text="[EnsureCrossCompiler] TargetArchitecture=$(TargetArchitecture); GCCPath=$(GCCPath); Exists=$(GCCPathExists)" Importance="High" />
<Error Condition="'$(TargetArchitecture)' == ''" Text="Unable to determine TargetArchitecture for GCC. Set CosmosArch or RuntimeIdentifier." />
<Error Condition="'$(GCCPath)' == ''" Text="No GCCPath resolved for $(TargetArchitecture). Install the cross-compiler or set -p:GCCPath explicitly." />
<Error Condition="'$(GCCPath)' != '' and '$(GCCPathExists)' == 'false' and $([System.IO.Path]::IsPathRooted('$(GCCPath)'))"
Text="$(GCCExecutableName) not found at $(GCCPath). Install via Homebrew (brew install $(GCCExecutableName))." />
</Target>
</Project>