about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-05-11 14:03:45 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-05-19 10:52:57 -0700
commitb56d47cc80a7df471c0e2f96fa62a3e3983972ec (patch)
tree250de54bb1cabbefd20d59e40b571f3a5dbf031d
parent7cf0b1798bddad33876258d6715b363896252e40 (diff)
downloadrust-b56d47cc80a7df471c0e2f96fa62a3e3983972ec.tar.gz
rust-b56d47cc80a7df471c0e2f96fa62a3e3983972ec.zip
mk: Enable building LLVM targeting MSVC
This commit modifies the makefiles to enable building LLVM with cmake and Visual
Studio to generate an LLVM that targets MSVC. Rust's configure script requires
cmake to be installed when targeting MSVC and will configure LLVM with cmake
instead of the normal `./configure` script LLVM provides. The build will then
run cmake to execute the build instead of the normal `make`.

Currently `make clean-llvm` isn't supported on MSVC as I can't figure out how to
run a "clean" target for the Visual Studio files.
-rwxr-xr-xconfigure34
-rw-r--r--mk/clean.mk13
-rw-r--r--mk/llvm.mk26
-rw-r--r--mk/main.mk4
4 files changed, 63 insertions, 14 deletions
diff --git a/configure b/configure
index b57a2f0fbef..29bddf687b2 100755
--- a/configure
+++ b/configure
@@ -1348,7 +1348,39 @@ do
         done
     fi
 
-    if [ ${do_reconfigure} -ne 0 ]
+    use_cmake=0
+    case "$t" in
+        (*-msvc)
+        use_cmake=1
+        ;;
+    esac
+
+    if [ ${do_reconfigure} -ne 0 ] && [ ${use_cmake} -ne 0 ]
+    then
+        msg "configuring LLVM for $t with cmake"
+
+        CMAKE_ARGS="-DLLVM_INCLUDE_TESTS=OFF"
+        if [ ! -z "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then
+            CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug"
+        else
+            CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release"
+        fi
+        if [ -z "$CFG_ENABLE_LLVM_ASSERTIONS" ]
+        then
+            CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=OFF"
+        else
+            CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=ON"
+        fi
+
+        msg "configuring LLVM with:"
+        msg "$CMAKE_ARGS"
+        (cd $LLVM_BUILD_DIR && "$CFG_CMAKE" $CFG_LLVM_SRC_DIR \
+                                            -G "Visual Studio 12 2013 Win64" \
+                                            $CMAKE_ARGS)
+        need_ok "LLVM cmake configure failed"
+    fi
+
+    if [ ${do_reconfigure} -ne 0 ] && [ ${use_cmake} -eq 0 ]
     then
         # LLVM's configure doesn't recognize the new Windows triples yet
         gnu_t=$(to_gnu_triple $t)
diff --git a/mk/clean.mk b/mk/clean.mk
index 5b90d41ceec..c04ef89ebc5 100644
--- a/mk/clean.mk
+++ b/mk/clean.mk
@@ -118,16 +118,3 @@ $(foreach host, $(CFG_HOST), \
  $(eval $(foreach target, $(CFG_TARGET), \
   $(eval $(foreach stage, 0 1 2 3, \
    $(eval $(call CLEAN_TARGET_STAGE_N,$(stage),$(target),$(host))))))))
-
-define DEF_CLEAN_LLVM_HOST
-ifeq ($(CFG_LLVM_ROOT),)
-clean-llvm$(1):
-	$$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) clean
-else
-clean-llvm$(1): ;
-
-endif
-endef
-
-$(foreach host, $(CFG_HOST), \
- $(eval $(call DEF_CLEAN_LLVM_HOST,$(host))))
diff --git a/mk/llvm.mk b/mk/llvm.mk
index cce1cab3968..356366bd5c6 100644
--- a/mk/llvm.mk
+++ b/mk/llvm.mk
@@ -19,6 +19,12 @@ LLVM_DEPS_INC=$(call rwildcard,$(CFG_LLVM_SRC_DIR)include,*cpp *hpp)
 LLVM_DEPS=$(LLVM_DEPS_SRC) $(LLVM_DEPS_INC)
 endif
 
+ifdef CFG_DISABLE_OPTIMIZE_LLVM
+LLVM_BUILD_CONFIG_MODE := Debug
+else
+LLVM_BUILD_CONFIG_MODE := Release
+endif
+
 define DEF_LLVM_RULES
 
 # If CFG_LLVM_ROOT is defined then we don't build LLVM ourselves
@@ -26,10 +32,30 @@ ifeq ($(CFG_LLVM_ROOT),)
 
 LLVM_STAMP_$(1) = $$(CFG_LLVM_BUILD_DIR_$(1))/llvm-auto-clean-stamp
 
+ifeq ($$(findstring msvc,$(1)),msvc)
+
+$$(LLVM_CONFIG_$(1)): $$(LLVM_DEPS) $$(LLVM_STAMP_$(1))
+	@$$(call E, cmake: llvm)
+	$$(Q)$$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
+		--config $$(LLVM_BUILD_CONFIG_MODE)
+	$$(Q)touch $$(LLVM_CONFIG_$(1))
+
+clean-llvm$(1):
+
+else
+
 $$(LLVM_CONFIG_$(1)): $$(LLVM_DEPS) $$(LLVM_STAMP_$(1))
 	@$$(call E, make: llvm)
 	$$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) $$(CFG_LLVM_BUILD_ENV_$(1)) ONLY_TOOLS="$$(LLVM_TOOLS)"
 	$$(Q)touch $$(LLVM_CONFIG_$(1))
+
+clean-llvm$(1):
+	$$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) clean
+
+endif
+
+else
+clean-llvm$(1):
 endif
 
 # This is used to independently force an LLVM clean rebuild
diff --git a/mk/main.mk b/mk/main.mk
index a3e34bfeedb..a70200e4d8a 100644
--- a/mk/main.mk
+++ b/mk/main.mk
@@ -299,9 +299,13 @@ LLVM_LIBDIR_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libdir)
 LLVM_LIBDIR_RUSTFLAGS_$(1)=-L "$$(LLVM_LIBDIR_$(1))"
 LLVM_LIBS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --libs $$(LLVM_COMPONENTS))
 LLVM_LDFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --ldflags)
+ifeq ($$(findstring freebsd,$(1)),freebsd)
 # On FreeBSD, it may search wrong headers (that are for pre-installed LLVM),
 # so we replace -I with -iquote to ensure that it searches bundled LLVM first.
 LLVM_CXXFLAGS_$(1)=$$(subst -I, -iquote , $$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags))
+else
+LLVM_CXXFLAGS_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --cxxflags)
+endif
 LLVM_HOST_TRIPLE_$(1)=$$(shell "$$(LLVM_CONFIG_$(1))" --host-target)
 
 LLVM_AS_$(1)=$$(CFG_LLVM_INST_DIR_$(1))/bin/llvm-as$$(X_$(1))