[PATCH] D41314: [cmake] Use symlinks for Windows-hosted toolchains built on Unix

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 15 16:52:27 PST 2017


smeenai created this revision.
smeenai added reviewers: beanz, compnerd, zturner.
Herald added a subscriber: mgorny.

When cross-compiling for Windows on Unix, the built toolchain will need
to be transferred to Windows to actually run. My opinion is that the
Unix build should use symlinks, and the transfer to Windows should take
care of making those symlinks usable. E.g., I envision tarballs to be a
common form of transfer from Unix to Windows, in which case the tarball
can be created using --dereference to follow the symlinks.

The motivation here is that, when cross-compiling for Windows on Unix,
the installation will *already* create symlinks. The reason is that the
installation script will be invoked without knowing the host system, so
the `if(UNIX)` check in the installation symlink creation script will
reflect the build system rather than the host system. We could either
make the build and install trees both contain copies or both contain
symlinks, and using symlinks is a significant space saving without (in
my opinion) having any detrimental effect on the usage of the cross-
compiled toolchain on Windows.

A secondary motivation is that Windows 10 version 1703 and later finally
lift the administrator rights requirement for creating symbolic links
(if the system is in Developer Mode), which makes symlinks a lot more
practical even on Windows. Of course Unix and Windows symlinks aren't
interoperable, but symlinks for Windows toolchains is a reasonable
future direction to be going in anyway.


https://reviews.llvm.org/D41314

Files:
  cmake/modules/AddLLVM.cmake
  cmake/modules/LLVMInstallSymlink.cmake


Index: cmake/modules/LLVMInstallSymlink.cmake
===================================================================
--- cmake/modules/LLVMInstallSymlink.cmake
+++ cmake/modules/LLVMInstallSymlink.cmake
@@ -3,7 +3,7 @@
 # See PR8397.
 
 function(install_symlink name target outdir)
-  if(UNIX)
+  if(CMAKE_HOST_UNIX)
     set(LINK_OR_COPY create_symlink)
     set(DESTDIR $ENV{DESTDIR})
   else()
Index: cmake/modules/AddLLVM.cmake
===================================================================
--- cmake/modules/AddLLVM.cmake
+++ cmake/modules/AddLLVM.cmake
@@ -1473,7 +1473,7 @@
   if(NOT ARG_OUTPUT_DIR)
     # If you're not overriding the OUTPUT_DIR, we can make the link relative in
     # the same directory.
-    if(UNIX)
+    if(CMAKE_HOST_UNIX)
       set(dest_binary "$<TARGET_FILE_NAME:${target}>")
     endif()
     if(CMAKE_CONFIGURATION_TYPES)
@@ -1499,7 +1499,7 @@
     endif()
   endif()
 
-  if(UNIX)
+  if(CMAKE_HOST_UNIX)
     set(LLVM_LINK_OR_COPY create_symlink)
   else()
     set(LLVM_LINK_OR_COPY copy)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41314.127208.patch
Type: text/x-patch
Size: 1029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171216/c38a9c42/attachment.bin>


More information about the llvm-commits mailing list