microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.11k stars 695 forks source link

Crosscompilation: Build aarch64 windows target on x64 windows #7000

Closed shaoboyan closed 2 weeks ago

shaoboyan commented 2 weeks ago

Running cmake config command:

cmake -B out/Debug -C ./cmake/caches/PredefinedParams.cmake -DCMAKE_BUILD_TYPE=Debug -DHLSL_OPTIONAL_PROJS_IN_DEFAULT=OFF -DHLSL_ENABLE_ANALYZE=OFF -DHLSL_OFFICIAL_BUILD=OFF -DHLSL_ENABLE_FIXED_VER=OFF -DHLSL_BUILD_DXILCONV=OFF -DHLSL_INCLUDE_TESTS=OFF -DENABLE_SPIRV_CODEGEN=OFF -DSPIRV_BUILD_TESTS=OFF -DLLVM_BUILD_RUNTIME=ON -DLLVM_BUILD_EXAMPLES=OFF -DLLVM_BUILD_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_DOCS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_OPTIMIZED_TABLEGEN=OFF -DLLVM_APPEND_VC_REV=OFF -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_EH=ON -DCLANG_CL=OFF -A ARM64

After configuration done, run build command

cmake --build out/Debug --config=Debug  

But get errors (For example):

  Building Attrs.inc...
  This version of D:\workspace\DirectXShaderCompiler\out\Debug\Debug\bin\clang-tblgen.exe is not compatible with the ve
  rsion of Windows you're running. Check your computer's system information and then contact the software publisher.
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): e
rror MSB8066: Custom build for 'D:\workspace\DirectXShaderCompiler\out\Debug\CMakeFiles\a2d74403e46282f9b8a9ca0ce3c5c1d
c\Attrs.inc.tmp.rule;D:\workspace\DirectXShaderCompiler\out\Debug\CMakeFiles\a2d74403e46282f9b8a9ca0ce3c5c1dc\Attrs.inc
.rule;D:\workspace\DirectXShaderCompiler\out\Debug\CMakeFiles\31901e38765945593449b2f44b6837b3\ClangAttrClasses.rule;D:
\workspace\DirectXShaderCompiler\tools\clang\include\clang\AST\CMakeLists.txt' exited with code 216. [D:\workspace\Dire
ctXShaderCompiler\out\Debug\tools\clang\include\clang\AST\ClangAttrClasses.vcxproj]

Adding -DCMAKE_CROSSCOMPILING=ON doesn't help.

It seems the built clang-tblgen.exe is arm based instead of x64 based. Is there any flag/switch to support cross-compiling?

NOTE: Following LLVM doc here https://llvm.org/docs/HowToCrossCompileLLVM.html and setting -DLLVM_TARGETS_TO_BUILD=ARM and -DLLVM_HOST_TRIPLE=aarch64-pc-win32 got errors in configuration step

  Unexpected failure executing llvm-build: Usage: llvm-build [options]

  llvm-build: error: invalid target to enable: 'ARM' (not in project)
shaoboyan commented 2 weeks ago

cc @fs-eire @guschmue @snnn

llvm-beanz commented 2 weeks ago

Cross compiling LLVM is a bit complicated, and DXC is such an old version of LLVM that the modern LLVM instructions don't quite work for it.

The main thing that you need to do is build a local x64 build of DXC and you'll need to configure your arm64 build directory to use the x64 build's tablegen tools. You can do that with the CMake options:

-DLLVM_TABLEGEN=<path to x64 build>\bin\llvm-tblgen.exe
-DCLANG_TABLEGEN=<path to x64 build>\bin\clang-tblgen.exe

If you continue to have problems please re-open this issue.