haowei created this revision.
haowei added a reviewer: phosek.
Herald added a subscriber: abrachet.
Herald added a project: All.
haowei requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Work in progress.

Initial work on building Windows compiler runtimes under Linux.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141738

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake
  llvm/cmake/modules/LLVMExternalProjectUtils.cmake
  llvm/runtimes/CMakeLists.txt

Index: llvm/runtimes/CMakeLists.txt
===================================================================
--- llvm/runtimes/CMakeLists.txt
+++ llvm/runtimes/CMakeLists.txt
@@ -3,9 +3,12 @@
 # similar although simpler functionality. We should figure out how to merge
 # the two files.
 
+message(NOTICE "Fuchisa Clang compiler-rt hello world")
+message(NOTICE "CMAKE_CURRENT_SOURCE_DIR is ${CMAKE_CURRENT_SOURCE_DIR}")
 set(COMMON_CMAKE_ARGS "-DHAVE_LLVM_LIT=ON")
 foreach(proj ${LLVM_ENABLE_RUNTIMES})
   set(proj_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../${proj}")
+  message(NOTICE "${proj}'s proj_dir is ${proj_dir}")
   if(IS_DIRECTORY ${proj_dir} AND EXISTS ${proj_dir}/CMakeLists.txt)
     list(APPEND runtimes ${proj_dir})
   else()
@@ -94,7 +97,9 @@
   check_apple_target(${target} builtin)
 
   get_cmake_property(variableNames VARIABLES)
+  #message(NOTICE "builtin variableNames ${variableNames}")
   foreach(variableName ${variableNames})
+    #message(NOTICE "builtin variableName ${variableName}")
     string(FIND "${variableName}" "BUILTINS_${target}" out)
     if("${out}" EQUAL 0)
       string(REPLACE "BUILTINS_${target}_" "" new_name ${variableName})
@@ -103,6 +108,12 @@
     endif()
   endforeach()
 
+  message(NOTICE "builtin target for ${target}")
+  #message(NOTICE "cmake args ${CMAKE_ARGS}")
+  message(NOTICE "cmake common args ${COMMON_CMAKE_ARGS}")
+  message(NOTICE "extra args:")
+  message(NOTICE ${${target}_extra_args})
+
   llvm_ExternalProject_Add(builtins-${target}
                            ${compiler_rt_path}/lib/builtins
                            DEPENDS ${ARG_DEPENDS}
@@ -139,6 +150,7 @@
       add_custom_target(install-builtins-stripped)
     endif()
 
+    message(NOTICE "Fuchisa Clang builtins: ${LLVM_BUILTIN_TARGETS}")
     foreach(target ${LLVM_BUILTIN_TARGETS})
       builtin_register_target(${compiler_rt_path} ${target}
         DEPENDS clang-resource-headers)
@@ -344,10 +356,16 @@
     list(APPEND ${name}_extra_args -DLLVM_ENABLE_RUNTIMES=${LLVM_ENABLE_RUNTIMES_PASSTHROUGH})
   endif()
 
-  if(NOT RUNTIMES_${name}_LLVM_USE_LINKER AND NOT RUNTIMES_${target}_LLVM_USE_LINKER)
+  if(NOT RUNTIMES_${name}_LLVM_USE_LINKER AND NOT RUNTIMES_${target}_LLVM_USE_LINKER AND NOT ${target} STREQUAL "x86_64-pc-windows-msvc")
     list(APPEND ${name}_extra_args -DLLVM_USE_LINKER=${LLVM_USE_LINKER})
   endif()
 
+  message(NOTICE "runtime target for ${target}")
+  #message(NOTICE "cmake args ${CMAKE_ARGS}")
+  message(NOTICE "cmake common args ${COMMON_CMAKE_ARGS}")
+  message(NOTICE "extra args:")
+  message(NOTICE ${${name}_extra_args})
+
   llvm_ExternalProject_Add(runtimes-${name}
                            ${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes
                            DEPENDS ${${name}_deps}
@@ -419,6 +437,7 @@
       endif()
     endif()
 
+    message(NOTICE "Fuchisa Clang runtimes: ${LLVM_RUNTIME_TARGETS}")
     foreach(name ${LLVM_RUNTIME_TARGETS})
       if(builtins_dep)
         if (LLVM_BUILTIN_TARGETS)
Index: llvm/cmake/modules/LLVMExternalProjectUtils.cmake
===================================================================
--- llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -168,7 +168,10 @@
       if(is_msvc_target)
         set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}
                           -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}
-                          -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
+                          -DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang-cl${CMAKE_EXECUTABLE_SUFFIX}
+                          -DCMAKE_RC_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-rc
+                          -DCMAKE_MT=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-mt
+                          )
       else()
         set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang${CMAKE_EXECUTABLE_SUFFIX}
                           -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++${CMAKE_EXECUTABLE_SUFFIX}
Index: clang/cmake/caches/Fuchsia-stage2.cmake
===================================================================
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -69,13 +69,49 @@
   set(RUNTIMES_CMAKE_ARGS "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13;-DCMAKE_OSX_ARCHITECTURES=arm64|x86_64" CACHE STRING "")
 endif()
 
-if(WIN32)
+
+if(WIN32 OR (LINUX AND WINDOWS_SDK_DIR))
+#if(WINDOWS_SDK_DIR)
+  #message(FATAL_ERROR "${WINDOWS_SDK_DIR} is set")
   set(target "x86_64-pc-windows-msvc")
 
   list(APPEND BUILTIN_TARGETS "${target}")
   set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
 
+  if(LINUX AND WINDOWS_SDK_DIR)
+    if(NOT FUCHSIA_TOOLCHAIN_DIR)
+      message(FATAL_ERROR "FUCHSIA_TOOLCHAIN_DIR should be defined")
+    endif()
+    set(BUILTINS_${target}_WINDOWS_SDK_DIR ${WINDOWS_SDK_DIR})
+    # set(BUILTINS_${target}_CMAKE_C_COMPILER "${FUCHSIA_TOOLCHAIN_DIR}/bin/clang-cl")
+    # set(BUILTINS_${target}_CMAKE_CXX_COMPILER "${FUCHSIA_TOOLCHAIN_DIR}/bin/clang-cl")
+    # set(BUILTINS_${target}_CMAKE_ASM_COMPILER "${FUCHSIA_TOOLCHAIN_DIR}/bin/clang-cl")
+    # set(BUILTINS_${target}_CMAKE_LINKER_COMPILER "${FUCHSIA_TOOLCHAIN_DIR}/bin/llvm-link")
+    # set(BUILTINS_${target}_CMAKE_AR "${FUCHSIA_TOOLCHAIN_DIR}/bin/llvm-lib")
+    # set(BUILTINS_${target}_CMAKE_NM "${FUCHSIA_TOOLCHAIN_DIR}/bin/llvm-nm")
+    # set(BUILTINS_${target}_CMAKE_RC "${FUCHSIA_TOOLCHAIN_DIR}/bin/llvm-rc")
+    # set(BUILTINS_${target}_CMAKE_MT "${FUCHSIA_TOOLCHAIN_DIR}/bin/llvm-mt")
+    set(CLANG_WINDOWS_CROSS_FLAGS
+        -Xclang
+        -ivfsoverlay
+        -Xclang
+        "${WINDOWS_SDK_DIR}/llvm-vfsoverlay.yaml"
+        /winsysroot
+        ${WINDOWS_SDK_DIR})
+    set(LINK_WINDOWS_OVERLAY_FLAGS
+        /vfsoverlay:"${WINDOWS_SDK_DIR}/llvm-vfsoverlay.yaml"
+        -libpath:"${WINDOWS_SDK_DIR}/VC/Tools/MSVC/14.34.31933/lib/x64"
+        -libpath:"${WINDOWS_SDK_DIR}/VC/Tools/MSVC/14.34.31933/atlmfc/lib/x64"
+        -libpath:"${WINDOWS_SDK_DIR}/Windows Kits/10/Lib/10.0.19041.0/ucrt/x64"
+        -libpath:"${WINDOWS_SDK_DIR}/Windows Kits/10/Lib/10.0.19041.0/um/x64")
+    set(BUILTINS_${target}_CMAKE_C_FLAGS ${CLANG_WINDOWS_CROSS_FLAGS} CACHE STRING "")
+    set(BUILTINS_${target}_CMAKE_CXX_FLAGS ${CLANG_WINDOWS_CROSS_FLAGS} CACHE STRING "")
+    set(BUILTINS_${target}_CMAKE_EXE_LINKER_FLAGS ${LINK_WINDOWS_OVERLAY_FLAGS} CACHE STRING "")
+    set(BUILTINS_${target}_CMAKE_SHARED_LINKER_FLAGS ${LINK_WINDOWS_OVERLAY_FLAGS} CACHE STRING "")
+    set(BUILTINS_${target}_CMAKE_MODULE_LINKER_FLAGS ${LINK_WINDOWS_OVERLAY_FLAGS} CACHE STRING "")
+  endif()
+
   list(APPEND RUNTIME_TARGETS "${target}")
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
@@ -84,6 +120,39 @@
   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 "")
+
+  if(LINUX AND WINDOWS_SDK_DIR)
+    if(NOT FUCHSIA_TOOLCHAIN_DIR)
+      message(FATAL_ERROR "FUCHSIA_TOOLCHAIN_DIR should be defined")
+    endif()
+    # set(RUNTIMES_${target}_WINDOWS_SDK_DIR ${WINDOWS_SDK_DIR})
+    # set(RUNTIMES_${target}_CMAKE_C_COMPILER "${FUCHSIA_TOOLCHAIN_DIR}/bin/clang-cl")
+    # set(RUNTIMES_${target}_CMAKE_CXX_COMPILER "${FUCHSIA_TOOLCHAIN_DIR}/bin/clang-cl")
+    # set(RUNTIMES_${target}_CMAKE_ASM_COMPILER "${FUCHSIA_TOOLCHAIN_DIR}/bin/clang-cl")
+    # set(RUNTIMES_${target}_CMAKE_LINKER_COMPILER "${FUCHSIA_TOOLCHAIN_DIR}/bin/llvm-link")
+    # set(RUNTIMES_${target}_CMAKE_AR "${FUCHSIA_TOOLCHAIN_DIR}/bin/llvm-lib")
+    # set(RUNTIMES_${target}_CMAKE_NM "${FUCHSIA_TOOLCHAIN_DIR}/bin/llvm-nm")
+    # set(RUNTIMES_${target}_CMAKE_RC "${FUCHSIA_TOOLCHAIN_DIR}/bin/llvm-rc")
+    # set(RUNTIMES_${target}_CMAKE_MT "${FUCHSIA_TOOLCHAIN_DIR}/bin/llvm-mt")
+    set(CLANG_WINDOWS_CROSS_FLAGS
+        -Xclang
+        -ivfsoverlay
+        -Xclang
+        "${WINDOWS_SDK_DIR}/llvm-vfsoverlay.yaml"
+        /winsysroot
+        ${WINDOWS_SDK_DIR})
+    set(LINK_WINDOWS_OVERLAY_FLAGS
+        /vfsoverlay:"${WINDOWS_SDK_DIR}/llvm-vfsoverlay.yaml"
+        -libpath:"${WINDOWS_SDK_DIR}/VC/Tools/MSVC/14.34.31933/lib/x64"
+        -libpath:"${WINDOWS_SDK_DIR}/VC/Tools/MSVC/14.34.31933/atlmfc/lib/x64"
+        -libpath:"${WINDOWS_SDK_DIR}/Windows Kits/10/Lib/10.0.19041.0/ucrt/x64"
+        -libpath:"${WINDOWS_SDK_DIR}/Windows Kits/10/Lib/10.0.19041.0/um/x64")
+    set(RUNTIMES_${target}_CMAKE_C_FLAGS "-Xclang -ivfsoverlay -Xclang ${WINDOWS_SDK_DIR}/llvm-vfsoverlay.yaml /winsysroot ${WINDOWS_SDK_DIR}" CACHE STRING "")
+    set(RUNTIMES_${target}_CMAKE_CXX_FLAGS "-Xclang -ivfsoverlay -Xclang ${WINDOWS_SDK_DIR}/llvm-vfsoverlay.yaml /winsysroot ${WINDOWS_SDK_DIR}" CACHE STRING "")
+    set(RUNTIMES_${target}_CMAKE_EXE_LINKER_FLAGS "/vfsoverlay:${WINDOWS_SDK_DIR}/llvm-vfsoverlay.yaml" CACHE STRING "")
+    set(RUNTIMES_${target}_CMAKE_SHARED_LINKER_FLAGS "/vfsoverlay:${WINDOWS_SDK_DIR}/llvm-vfsoverlay.yaml" CACHE STRING "")
+    set(RUNTIMES_${target}_CMAKE_MODULE_LINKER_FLAGS "/vfsoverlay:${WINDOWS_SDK_DIR}/llvm-vfsoverlay.yaml" CACHE STRING "")
+  endif()
 endif()
 
 foreach(target aarch64-unknown-linux-gnu;armv7-unknown-linux-gnueabihf;i386-unknown-linux-gnu;x86_64-unknown-linux-gnu)
@@ -245,9 +314,18 @@
   set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS "aarch64-unknown-fuchsia" CACHE STRING "")
 endif()
 
+
+# if(LINUX)
+#   if (WINDOWS_SDK_DIR)
+#   endif()
+# endif()
+
 set(LLVM_BUILTIN_TARGETS "${BUILTIN_TARGETS}" CACHE STRING "")
 set(LLVM_RUNTIME_TARGETS "${RUNTIME_TARGETS}" CACHE STRING "")
 
+message(NOTICE "Fuchisa Clang builtins: ${LLVM_BUILTIN_TARGETS}")
+message(NOTICE "Fuchisa Clang runtimes: ${LLVM_RUNTIME_TARGETS}")
+
 # Setup toolchain.
 set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
 set(LLVM_TOOLCHAIN_TOOLS
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to