about summary refs log tree commit diff
diff options
context:
space:
mode:
authorangelsl <hidingfromhidden@gmail.com>2015-10-24 00:31:12 +0800
committerangelsl <hidingfromhidden@gmail.com>2015-11-04 11:43:41 +0800
commit9fe4e962e1fe7a4c1d603d1549800d105ca5941f (patch)
tree772983369c2c487302e96d74c286cc18df18cef8
parent54d85b4f2fb0756c67fe92734403bef2d169a08f (diff)
downloadrust-9fe4e962e1fe7a4c1d603d1549800d105ca5941f.tar.gz
rust-9fe4e962e1fe7a4c1d603d1549800d105ca5941f.zip
Build compiler-rt/builtins with MSVC
-rwxr-xr-xconfigure46
-rw-r--r--mk/rt.mk39
-rw-r--r--src/test/run-make/compiler-rt-works-on-mingw/Makefile17
-rw-r--r--src/test/run-make/compiler-rt-works-on-mingw/foo.cpp5
-rw-r--r--src/test/run-make/compiler-rt-works-on-mingw/foo.rs16
5 files changed, 89 insertions, 34 deletions
diff --git a/configure b/configure
index 60d366100f8..8caf6abed78 100755
--- a/configure
+++ b/configure
@@ -1498,25 +1498,9 @@ do
         done
     fi
 
-    if [ ${do_reconfigure} -ne 0 ] && [ ${is_msvc} -ne 0 ]
+    # We need the generator later on for compiler-rt even if LLVM's not built
+    if [ ${is_msvc} -ne 0 ]
     then
-        msg "configuring LLVM for $t with cmake"
-
-        CMAKE_ARGS="-DLLVM_INCLUDE_TESTS=OFF"
-        if [ -n "$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"
         case "$CFG_MSVC_ROOT" in
             *14.0*)
                 generator="Visual Studio 14 2015"
@@ -1538,8 +1522,32 @@ do
                 err "can only build LLVM for x86 platforms"
                 ;;
         esac
+        CFG_CMAKE_GENERATOR=$generator
+        putvar CFG_CMAKE_GENERATOR
+    fi
+
+    if [ ${do_reconfigure} -ne 0 ] && [ ${is_msvc} -ne 0 ]
+    then
+        msg "configuring LLVM for $t with cmake"
+
+        CMAKE_ARGS="-DLLVM_INCLUDE_TESTS=OFF"
+        if [ -n "$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 "$generator" \
+                                            -G "$CFG_CMAKE_GENERATOR" \
                                             $CMAKE_ARGS)
         need_ok "LLVM cmake configure failed"
     fi
diff --git a/mk/rt.mk b/mk/rt.mk
index 1f60aaed473..d8b5aeccdcd 100644
--- a/mk/rt.mk
+++ b/mk/rt.mk
@@ -216,22 +216,31 @@ COMPRT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
 COMPRT_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(COMPRT_NAME_$(1))
 COMPRT_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/compiler-rt
 
-# Note that on MSVC-targeting builds we hardwire CC/AR to gcc/ar even though
-# we're targeting MSVC. This is because although compiler-rt has a CMake build
-# config I can't actually figure out how to use it, so I'm not sure how to use
-# cl.exe to build the objects. Additionally, the compiler-rt library when built
-# with gcc has the same ABI as cl.exe, so they're largely compatible
-COMPRT_CC_$(1) := $$(CC_$(1))
-COMPRT_AR_$(1) := $$(AR_$(1))
-COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1))
 ifeq ($$(findstring msvc,$(1)),msvc)
-COMPRT_CC_$(1) := gcc
-COMPRT_AR_$(1) := ar
-ifeq ($$(findstring i686,$(1)),i686)
-COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m32
+$$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS) $$(LLVM_CONFIG_$(1))
+	@$$(call E, cmake: compiler-rt)
+	$$(Q)cd "$$(COMPRT_BUILD_DIR_$(1))"; $$(CFG_CMAKE) "$(S)src/compiler-rt" \
+		-DCMAKE_BUILD_TYPE=$$(LLVM_BUILD_CONFIG_MODE) \
+		-DLLVM_CONFIG_PATH=$$(LLVM_CONFIG_$(1)) \
+		-G"$$(CFG_CMAKE_GENERATOR)"
+	$$(Q)$$(CFG_CMAKE) --build "$$(COMPRT_BUILD_DIR_$(1))" \
+		--target lib/builtins/builtins \
+		--config $$(LLVM_BUILD_CONFIG_MODE) \
+		-- //v:m //nologo
+	$$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/lib/windows/$$(LLVM_BUILD_CONFIG_MODE)/clang_rt.builtins-$$(HOST_$(1)).lib $$@
 else
-COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m64
-endif
+COMPRT_CC_$(1) := $$(CC_$(1))
+COMPRT_AR_$(1) := $$(AR_$(1))
+# We chomp -Werror here because GCC warns about the type signature of
+# builtins not matching its own and the build fails. It's a bit hacky,
+# but what can we do, we're building libclang-rt using GCC ......
+COMPRT_CFLAGS_$(1) := $$(subst -Werror,,$$(CFG_GCCISH_CFLAGS_$(1))) -std=c99
+
+# FreeBSD Clang's packaging is problematic; it doesn't copy unwind.h to
+# the standard include directory. This should really be in our changes to
+# compiler-rt, but we override the CFLAGS here so there isn't much choice
+ifeq ($$(findstring freebsd,$(1)),freebsd)
+	COMPRT_CFLAGS_$(1) += -I/usr/include/c++/v1
 endif
 
 $$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
@@ -246,7 +255,7 @@ $$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
 		TargetTriple=$(1) \
 		triple-builtins
 	$$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/triple/builtins/libcompiler_rt.a $$@
-
+endif
 ################################################################################
 # libbacktrace
 #
diff --git a/src/test/run-make/compiler-rt-works-on-mingw/Makefile b/src/test/run-make/compiler-rt-works-on-mingw/Makefile
new file mode 100644
index 00000000000..4ec54f73e67
--- /dev/null
+++ b/src/test/run-make/compiler-rt-works-on-mingw/Makefile
@@ -0,0 +1,17 @@
+-include ../tools.mk
+
+ifneq (,$(findstring MINGW,$(UNAME)))
+ifndef IS_MSVC
+all:
+	g++ foo.cpp -c -o $(TMPDIR)/foo.o
+	ar crus $(TMPDIR)/libfoo.a $(TMPDIR)/foo.o
+	$(RUSTC) foo.rs -lfoo -lstdc++
+	$(call RUN,foo)
+else
+all:
+
+endif
+else
+all:
+
+endif
diff --git a/src/test/run-make/compiler-rt-works-on-mingw/foo.cpp b/src/test/run-make/compiler-rt-works-on-mingw/foo.cpp
new file mode 100644
index 00000000000..aac3ba42201
--- /dev/null
+++ b/src/test/run-make/compiler-rt-works-on-mingw/foo.cpp
@@ -0,0 +1,5 @@
+// ignore-license
+extern "C" void foo() {
+    int *a = new int(3);
+    delete a;
+}
diff --git a/src/test/run-make/compiler-rt-works-on-mingw/foo.rs b/src/test/run-make/compiler-rt-works-on-mingw/foo.rs
new file mode 100644
index 00000000000..293f9d58294
--- /dev/null
+++ b/src/test/run-make/compiler-rt-works-on-mingw/foo.rs
@@ -0,0 +1,16 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+extern { fn foo(); }
+
+pub fn main() {
+    unsafe { foo(); }
+    assert_eq!(7f32.powi(3), 343f32);
+}