|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 3 | + <!-- |
| 4 | + Stride.Native.Windows.Lld.targets |
| 5 | + |
| 6 | + Windows native compilation and linking using Clang+LLD |
| 7 | + This replaces the MSVC-based approach and provides cross-platform |
| 8 | + consistency for Windows builds. |
| 9 | +
|
| 10 | + Note: This file is meant to be included by Stride.Native.targets |
| 11 | + --> |
| 12 | + |
| 13 | + <!-- |
| 14 | + Windows Clang+LLD Compilation Target (x86) |
| 15 | + |
| 16 | + Compiles C/C++ files for 32-bit Windows using clang and links with LLD |
| 17 | + --> |
| 18 | + <Target Name="_StrideCompileNativeWindows_X86_Lld" |
| 19 | + Inputs="@(StrideNativeCFile);@(StrideNativeHFile)" |
| 20 | + Outputs="$(OutputObjectPath)\win-x86\compiled" |
| 21 | + Condition="'$(StrideNativeBuildModeClang)' == 'true'"> |
| 22 | + |
| 23 | + <MakeDir Directories="$(OutputObjectPath)\win-x86"/> |
| 24 | + |
| 25 | + <!-- Compile C files --> |
| 26 | + <Exec Condition="'%(StrideNativeCFile.Extension)' != '.cpp'" |
| 27 | + Command=""$(StrideNativeClangCommand)" -gcodeview -fno-ms-extensions -nobuiltininc -nostdinc++ $(StrideNativeClang) -DNEED_DLL_EXPORT -o "$(OutputObjectPath)\win-x86\%(StrideNativeCFile.Filename).obj" -c "%(StrideNativeCFile.FullPath)" -fms-extensions -DWINDOWS_DESKTOP -target i686-pc-windows-msvc" |
| 28 | + ContinueOnError="false" /> |
| 29 | + |
| 30 | + <!-- Compile C++ files --> |
| 31 | + <Exec Condition="'%(StrideNativeCFile.Extension)' == '.cpp'" |
| 32 | + Command=""$(StrideNativeClangCommand)" -gcodeview -fno-ms-extensions -nobuiltininc -nostdinc++ $(StrideNativeClangCPP) $(StrideNativeClang) -DNEED_DLL_EXPORT -o "$(OutputObjectPath)\win-x86\%(StrideNativeCFile.Filename).obj" -c "%(StrideNativeCFile.FullPath)" -fms-extensions -DWINDOWS_DESKTOP -target i686-pc-windows-msvc" |
| 33 | + ContinueOnError="false" /> |
| 34 | + |
| 35 | + <!-- Create marker file --> |
| 36 | + <Touch AlwaysCreate="true" Files="$(OutputObjectPath)\win-x86\compiled" /> |
| 37 | + </Target> |
| 38 | + |
| 39 | + <!-- |
| 40 | + Windows Clang+LLD Linking Target (x86) |
| 41 | +
|
| 42 | + Links compiled .obj files for 32-bit Windows using LLVM LLD with MSVC ABI |
| 43 | + --> |
| 44 | + <Target Name="_StrideLinkNativeWindows_X86_Lld" |
| 45 | + Inputs="$(OutputObjectPath)\win-x86\compiled" |
| 46 | + Outputs="$(StrideNativeOutputPath)\runtimes\win-x86\native\$(StrideNativeOutputName).dll" |
| 47 | + Condition="'$(StrideNativeBuildModeClang)' == 'true'"> |
| 48 | + |
| 49 | + <MakeDir Directories="$(StrideNativeOutputPath)\runtimes\win-x86\native"/> |
| 50 | + |
| 51 | + <!-- Link DLL using Clang driver with LLD --> |
| 52 | + <Exec Command=""$(StrideNativeClangCommand)" -shared -fuse-ld=lld -target i686-pc-windows-msvc -o "$(StrideNativeOutputPath)\runtimes\win-x86\native\$(StrideNativeOutputName).dll" -Wl,-subsystem:windows -Wl,-nxcompat -L"$(MSBuildThisFileDirectory)..\..\deps\NativePath\dotnet\win-x86" @(StrideNativeCFile->'"$(OutputObjectPath)\win-x86\%(Filename).obj"', ' ') "$(MSBuildThisFileDirectory)..\..\deps\NativePath\dotnet\win-x86\libNativePath.lib" "$(StrideNativePathLibsWindows_x86)" -lkernel32 -luser32 -lole32 -loleaut32 -luuid -ladvapi32 -lshell32" |
| 53 | + ContinueOnError="false" /> |
| 54 | + |
| 55 | + <Message Text="[Stride] Linked $(StrideNativeOutputName).dll for Windows x86" Importance="normal" /> |
| 56 | + </Target> |
| 57 | + |
| 58 | + <!-- |
| 59 | + Windows Clang+LLD Compilation Target (x64) |
| 60 | + |
| 61 | + Compiles C/C++ files for 64-bit Windows using clang and links with LLD |
| 62 | + --> |
| 63 | + <Target Name="_StrideCompileNativeWindows_X64_Lld" |
| 64 | + Inputs="@(StrideNativeCFile);@(StrideNativeHFile)" |
| 65 | + Outputs="$(OutputObjectPath)\win-x64\compiled" |
| 66 | + Condition="'$(StrideNativeBuildModeClang)' == 'true'"> |
| 67 | + |
| 68 | + <MakeDir Directories="$(OutputObjectPath)\win-x64"/> |
| 69 | + |
| 70 | + <!-- Compile C files --> |
| 71 | + <Exec Condition="'%(StrideNativeCFile.Extension)' != '.cpp'" |
| 72 | + Command=""$(StrideNativeClangCommand)" -gcodeview -fno-ms-extensions -nobuiltininc -nostdinc++ $(StrideNativeClang) -DNEED_DLL_EXPORT -o "$(OutputObjectPath)\win-x64\%(StrideNativeCFile.Filename).obj" -c "%(StrideNativeCFile.FullPath)" -fms-extensions -DWINDOWS_DESKTOP -target x86_64-pc-windows-msvc" |
| 73 | + ContinueOnError="false" /> |
| 74 | + |
| 75 | + <!-- Compile C++ files --> |
| 76 | + <Exec Condition="'%(StrideNativeCFile.Extension)' == '.cpp'" |
| 77 | + Command=""$(StrideNativeClangCommand)" -gcodeview -fno-ms-extensions -nobuiltininc -nostdinc++ $(StrideNativeClangCPP) $(StrideNativeClang) -DNEED_DLL_EXPORT -o "$(OutputObjectPath)\win-x64\%(StrideNativeCFile.Filename).obj" -c "%(StrideNativeCFile.FullPath)" -fms-extensions -DWINDOWS_DESKTOP -target x86_64-pc-windows-msvc" |
| 78 | + ContinueOnError="false" /> |
| 79 | + |
| 80 | + <!-- Create marker file --> |
| 81 | + <Touch AlwaysCreate="true" Files="$(OutputObjectPath)\win-x64\compiled" /> |
| 82 | + </Target> |
| 83 | + |
| 84 | + <!-- |
| 85 | + Windows Clang+LLD Linking Target (x64) |
| 86 | + |
| 87 | + Links compiled .obj files for 64-bit Windows using LLVM LLD with MSVC ABI |
| 88 | + --> |
| 89 | + <Target Name="_StrideLinkNativeWindows_X64_Lld" |
| 90 | + Inputs="$(OutputObjectPath)\win-x64\compiled" |
| 91 | + Outputs="$(StrideNativeOutputPath)\runtimes\win-x64\native\$(StrideNativeOutputName).dll" |
| 92 | + Condition="'$(StrideNativeBuildModeClang)' == 'true'"> |
| 93 | + |
| 94 | + <MakeDir Directories="$(StrideNativeOutputPath)\runtimes\win-x64\native"/> |
| 95 | + |
| 96 | + <!-- Debug: Show what libraries are being linked --> |
| 97 | + <Message Text="[Stride] Linking libraries: libNativePath.lib $(StrideNativePathLibsWindows)" Importance="high" /> |
| 98 | + <Message Text="[Stride] Object files: @(StrideNativeCFile->'$(OutputObjectPath)\win-x64\%(Filename).obj')" Importance="high" /> |
| 99 | + |
| 100 | + <!-- Link DLL using Clang driver with LLD --> |
| 101 | + <Exec Command=""$(StrideNativeClangCommand)" -shared -fuse-ld=lld -target x86_64-pc-windows-msvc -o "$(StrideNativeOutputPath)\runtimes\win-x64\native\$(StrideNativeOutputName).dll" -Wl,-subsystem:windows -Wl,-nxcompat -L"$(MSBuildThisFileDirectory)..\..\deps\NativePath\dotnet\win-x64" @(StrideNativeCFile->'"$(OutputObjectPath)\win-x64\%(Filename).obj"', ' ') "$(MSBuildThisFileDirectory)..\..\deps\NativePath\dotnet\win-x64\libNativePath.lib" "$(StrideNativePathLibsWindows_x64)" -lkernel32 -luser32 -lole32 -loleaut32 -luuid -ladvapi32 -lshell32" |
| 102 | + ContinueOnError="false" /> |
| 103 | + |
| 104 | + <Message Text="[Stride] Linked $(StrideNativeOutputName).dll for Windows x64" Importance="normal" /> |
| 105 | + </Target> |
| 106 | + |
| 107 | + <!-- |
| 108 | + Windows Clang+LLD Compilation Target (ARM64) |
| 109 | + |
| 110 | + Compiles C/C++ files for ARM64 Windows using clang and links with LLD |
| 111 | + Conditional: Only if StrideNativeWindowsArm64Enabled is true |
| 112 | + --> |
| 113 | + <Target Name="_StrideCompileNativeWindows_ARM64_Lld" |
| 114 | + Inputs="@(StrideNativeCFile);@(StrideNativeHFile)" |
| 115 | + Outputs="$(OutputObjectPath)\win-arm64\compiled" |
| 116 | + Condition="'$(StrideNativeBuildModeClang)' == 'true' AND '$(StrideNativeWindowsArm64Enabled)' == 'true'"> |
| 117 | + |
| 118 | + <MakeDir Directories="$(OutputObjectPath)\win-arm64"/> |
| 119 | + |
| 120 | + <!-- Compile C files --> |
| 121 | + <Exec Condition="'%(StrideNativeCFile.Extension)' != '.cpp'" |
| 122 | + Command=""$(StrideNativeClangCommand)" -gcodeview -fno-ms-extensions -nobuiltininc -nostdinc++ $(StrideNativeClang) -DNEED_DLL_EXPORT -o "$(OutputObjectPath)\win-arm64\%(StrideNativeCFile.Filename).obj" -c "%(StrideNativeCFile.FullPath)" -fms-extensions -DWINDOWS_DESKTOP -target aarch64-pc-windows-msvc" |
| 123 | + ContinueOnError="false" /> |
| 124 | + |
| 125 | + <!-- Compile C++ files --> |
| 126 | + <Exec Condition="'%(StrideNativeCFile.Extension)' == '.cpp'" |
| 127 | + Command=""$(StrideNativeClangCommand)" -gcodeview -fno-ms-extensions -nobuiltininc -nostdinc++ $(StrideNativeClangCPP) $(StrideNativeClang) -DNEED_DLL_EXPORT -o "$(OutputObjectPath)\win-arm64\%(StrideNativeCFile.Filename).obj" -c "%(StrideNativeCFile.FullPath)" -fms-extensions -DWINDOWS_DESKTOP -target aarch64-pc-windows-msvc" |
| 128 | + ContinueOnError="false" /> |
| 129 | + |
| 130 | + <!-- Create marker file --> |
| 131 | + <Touch AlwaysCreate="true" Files="$(OutputObjectPath)\win-arm64\compiled" /> |
| 132 | + </Target> |
| 133 | + |
| 134 | + <!-- |
| 135 | + Windows Clang+LLD Linking Target (ARM64) |
| 136 | + |
| 137 | + Links compiled .obj files for ARM64 Windows using LLVM LLD with MSVC ABI |
| 138 | + --> |
| 139 | + <Target Name="_StrideLinkNativeWindows_ARM64_Lld" |
| 140 | + Inputs="$(OutputObjectPath)\win-arm64\compiled" |
| 141 | + Outputs="$(StrideNativeOutputPath)\runtimes\win-arm64\native\$(StrideNativeOutputName).dll" |
| 142 | + Condition="'$(StrideNativeBuildModeClang)' == 'true' AND '$(StrideNativeWindowsArm64Enabled)' == 'true'"> |
| 143 | + |
| 144 | + <MakeDir Directories="$(StrideNativeOutputPath)\runtimes\win-arm64\native"/> |
| 145 | + |
| 146 | + <!-- Debug: Show what libraries are being linked --> |
| 147 | + <Message Text="[Stride] Linking libraries: libNativePath.lib $(StrideNativePathLibsWindows)" Importance="high" /> |
| 148 | + <Message Text="[Stride] Object files: @(StrideNativeCFile->'$(OutputObjectPath)\win-arm64\%(Filename).obj')" Importance="high" /> |
| 149 | + |
| 150 | + <!-- Link DLL using Clang driver with LLD (MinGW target to avoid CRT conflicts) --> |
| 151 | + <Exec Command=""$(StrideNativeClangCommand)" -shared -fuse-ld=lld -target aarch64-pc-windows-msvc -o "$(StrideNativeOutputPath)\runtimes\win-arm64\native\$(StrideNativeOutputName).dll" -Wl,-subsystem:windows -Wl,-nxcompat -L"$(MSBuildThisFileDirectory)..\..\deps\NativePath\dotnet\win-arm64" @(StrideNativeCFile->'"$(OutputObjectPath)\win-arm64\%(Filename).obj"', ' ') "$(MSBuildThisFileDirectory)..\..\deps\NativePath\dotnet\win-arm64\libNativePath.lib" "$(StrideNativePathLibsWindowsArm64)" -lkernel32 -luser32 -lole32 -loleaut32 -luuid -ladvapi32 -lshell32" |
| 152 | + ContinueOnError="false" /> |
| 153 | + |
| 154 | + <Message Text="[Stride] Linked $(StrideNativeOutputName).dll for Windows ARM64" Importance="normal" /> |
| 155 | + </Target> |
| 156 | + |
| 157 | + <!-- |
| 158 | + Master Windows Clang+LLD Compilation Target |
| 159 | + |
| 160 | + Orchestrates compilation and linking for all Windows architectures |
| 161 | + This is the main entry point for the new Windows build approach |
| 162 | + --> |
| 163 | + <Target Name="CompileNativeClang_Windows_Lld" |
| 164 | + Inputs="@(StrideNativeCFile);@(StrideNativeHFile)" |
| 165 | + Outputs="@(StrideNativeOutput)" |
| 166 | + Condition="('$(TargetFramework)' == '$(StrideFramework)') And $([MSBuild]::IsOSPlatform('Windows')) And $(DesignTimeBuild) != true And $(BuildingProject) != false And '$(StrideNativeBuildModeClang)' == 'true'" |
| 167 | + BeforeTargets="CoreCompile" |
| 168 | + DependsOnTargets="_StrideRegisterNativeOutputs"> |
| 169 | + |
| 170 | + <!-- Compile for all architectures --> |
| 171 | + <CallTarget Targets="_StrideCompileNativeWindows_X86_Lld" /> |
| 172 | + <CallTarget Targets="_StrideCompileNativeWindows_X64_Lld" /> |
| 173 | + <CallTarget Targets="_StrideCompileNativeWindows_ARM64_Lld" /> |
| 174 | + |
| 175 | + <!-- Link for all architectures --> |
| 176 | + <CallTarget Targets="_StrideLinkNativeWindows_X86_Lld" /> |
| 177 | + <CallTarget Targets="_StrideLinkNativeWindows_X64_Lld" /> |
| 178 | + <CallTarget Targets="_StrideLinkNativeWindows_ARM64_Lld" /> |
| 179 | + |
| 180 | + <!-- Workaround: forcing C# rebuild so that timestamps are up to date --> |
| 181 | + <Delete Files="@(IntermediateAssembly)"/> |
| 182 | + |
| 183 | + <Message Text="[Stride] Windows native build completed using Clang+LLD" Importance="high" /> |
| 184 | + </Target> |
| 185 | + |
| 186 | +</Project> |
0 commit comments