Author: Haowei Wu Date: 2023-01-23T14:09:31-08:00 New Revision: 20bb7658f53b0b8db165ff4d404ede3f9b34862d
URL: https://github.com/llvm/llvm-project/commit/20bb7658f53b0b8db165ff4d404ede3f9b34862d DIFF: https://github.com/llvm/llvm-project/commit/20bb7658f53b0b8db165ff4d404ede3f9b34862d.diff LOG: [Fuchsia] Build windows runtimes using cross compilation on Linux This patch provides initial support of building Clang runtimes for Windows when using Fuchsia Clang toolchains under Linux. Differential Revision: https://reviews.llvm.org/D141738 Added: Modified: clang/cmake/caches/Fuchsia-stage2.cmake llvm/cmake/modules/LLVMExternalProjectUtils.cmake Removed: ################################################################################ diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake index 9694a0f59856..73fa55668957 100644 --- a/clang/cmake/caches/Fuchsia-stage2.cmake +++ b/clang/cmake/caches/Fuchsia-stage2.cmake @@ -69,12 +69,44 @@ if(APPLE) set(RUNTIMES_CMAKE_ARGS "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13;-DCMAKE_OSX_ARCHITECTURES=arm64|x86_64" CACHE STRING "") endif() -if(WIN32) +if(WIN32 OR LLVM_WINSYSROOT) + if((NOT WIN32) AND (NOT LLVM_VFSOVERLAY)) + message(FATAL_ERROR "LLVM_VFSOVERLAY should be defined.") + endif() set(target "x86_64-pc-windows-msvc") + if (LLVM_WINSYSROOT) + set(WINDOWS_COMPILER_FLAGS + -Xclang + -ivfsoverlay + -Xclang + ${LLVM_VFSOVERLAY} + # TODO: /winsysroot should be set by HandleLLVMOptions.cmake automatically + # but it current has a bug that prevents it from working under cross + # compilation. Set this flag manually for now. + /winsysroot + ${LLVM_WINSYSROOT}) + string(REPLACE ";" " " WINDOWS_COMPILER_FLAGS "${WINDOWS_COMPILER_FLAGS}") + set(WINDOWS_LINK_FLAGS + /vfsoverlay:${LLVM_VFSOVERLAY} + # TODO: On Windows, linker is invoked by cmake instead of the clang-cl driver, + # so we have to manually set the libpath. We use clang-cl driver if we can + # and remove these libpath flags. + -libpath:"${LLVM_WINSYSROOT}/VC/Tools/MSVC/14.34.31933/lib/x64" + -libpath:"${LLVM_WINSYSROOT}/VC/Tools/MSVC/14.34.31933/atlmfc/lib/x64" + -libpath:"${LLVM_WINSYSROOT}/Windows Kits/10/Lib/10.0.19041.0/ucrt/x64" + -libpath:"${LLVM_WINSYSROOT}/Windows Kits/10/Lib/10.0.19041.0/um/x64") + string(REPLACE ";" " " WINDOWS_LINK_FLAGS "${WINDOWS_LINK_FLAGS}") + endif() + list(APPEND BUILTIN_TARGETS "${target}") set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "") set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") + set(BUILTINS_${target}_CMAKE_C_FLAGS ${WINDOWS_COMPILER_FLAGS} CACHE STRING "") + set(BUILTINS_${target}_CMAKE_CXX_FLAGS ${WINDOWS_COMPILER_FLAGS} CACHE STRING "") + set(BUILTINS_${target}_CMAKE_EXE_LINKER_FLAGS ${WINDOWS_LINK_FLAGS} CACHE STRING "") + set(BUILTINS_${target}_CMAKE_SHARED_LINKER_FLAGS ${WINDOWS_LINK_FLAGS} CACHE STRING "") + set(BUILTINS_${target}_CMAKE_MODULE_LINKER_FLAGS ${WINDOWS_LINK_FLAGS} CACHE STRING "") list(APPEND RUNTIME_TARGETS "${target}") set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "") @@ -84,6 +116,11 @@ if(WIN32) set(RUNTIMES_${target}_LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "") set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "") set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE STRING "") + set(RUNTIMES_${target}_CMAKE_C_FLAGS ${WINDOWS_COMPILER_FLAGS} CACHE STRING "") + set(RUNTIMES_${target}_CMAKE_CXX_FLAGS ${WINDOWS_COMPILER_FLAGS} CACHE STRING "") + set(RUNTIMES_${target}_CMAKE_EXE_LINKER_FLAGS ${WINDOWS_LINK_FLAGS} CACHE STRING "") + set(RUNTIMES_${target}_CMAKE_SHARED_LINKER_FLAGS ${WINDOWS_LINK_FLAGS} CACHE STRING "") + set(RUNTIMES_${target}_CMAKE_MODULE_LINKER_FLAGS ${WINDOWS_LINK_FLAGS} CACHE STRING "") endif() foreach(target aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unknown-linux-gnu;x86_64-unknown-linux-gnu) diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake index bf61d6dbc497..ff6cb11f7d1b 100644 --- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake +++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake @@ -93,7 +93,7 @@ function(llvm_ExternalProject_Add name source_dir) if(_cmake_system_name STREQUAL Darwin) list(APPEND ARG_TOOLCHAIN_TOOLS llvm-libtool-darwin llvm-lipo) elseif(is_msvc_target) - list(APPEND ARG_TOOLCHAIN_TOOLS llvm-lib) + list(APPEND ARG_TOOLCHAIN_TOOLS llvm-lib llvm-rc llvm-mt) else() # TODO: These tools don't fully support Mach-O format yet. list(APPEND ARG_TOOLCHAIN_TOOLS llvm-objcopy llvm-strip llvm-readelf) @@ -213,6 +213,12 @@ function(llvm_ExternalProject_Add name source_dir) if(llvm-readelf IN_LIST TOOLCHAIN_TOOLS) list(APPEND compiler_args -DCMAKE_READELF=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-readelf${CMAKE_EXECUTABLE_SUFFIX}) endif() + if(llvm-mt IN_LIST TOOLCHAIN_TOOLS AND is_msvc_target) + list(APPEND compiler_args -DCMAKE_MT=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-mt${CMAKE_EXECUTABLE_SUFFIX}) + endif() + if(llvm-rc IN_LIST TOOLCHAIN_TOOLS AND is_msvc_target) + list(APPEND compiler_args -DCMAKE_RC_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-rc${CMAKE_EXECUTABLE_SUFFIX}) + endif() list(APPEND ARG_DEPENDS ${TOOLCHAIN_TOOLS}) endif() _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits