Skip to content

Commit b09e8f5

Browse files
committed
Build compiler-rt/builtins with MSVC
1 parent 6e61c6f commit b09e8f5

File tree

2 files changed

+51
-34
lines changed

2 files changed

+51
-34
lines changed

configure

+27-19
Original file line numberDiff line numberDiff line change
@@ -1498,25 +1498,9 @@ do
14981498
done
14991499
fi
15001500

1501-
if [ ${do_reconfigure} -ne 0 ] && [ ${is_msvc} -ne 0 ]
1501+
# We need the generator later on for compiler-rt even if LLVM's not built
1502+
if [ ${is_msvc} -ne 0 ]
15021503
then
1503-
msg "configuring LLVM for $t with cmake"
1504-
1505-
CMAKE_ARGS="-DLLVM_INCLUDE_TESTS=OFF"
1506-
if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then
1507-
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug"
1508-
else
1509-
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release"
1510-
fi
1511-
if [ -z "$CFG_ENABLE_LLVM_ASSERTIONS" ]
1512-
then
1513-
CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=OFF"
1514-
else
1515-
CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=ON"
1516-
fi
1517-
1518-
msg "configuring LLVM with:"
1519-
msg "$CMAKE_ARGS"
15201504
case "$CFG_MSVC_ROOT" in
15211505
*14.0*)
15221506
generator="Visual Studio 14 2015"
@@ -1538,8 +1522,32 @@ do
15381522
err "can only build LLVM for x86 platforms"
15391523
;;
15401524
esac
1525+
CFG_CMAKE_GENERATOR=$generator
1526+
putvar CFG_CMAKE_GENERATOR
1527+
fi
1528+
1529+
if [ ${do_reconfigure} -ne 0 ] && [ ${is_msvc} -ne 0 ]
1530+
then
1531+
msg "configuring LLVM for $t with cmake"
1532+
1533+
CMAKE_ARGS="-DLLVM_INCLUDE_TESTS=OFF"
1534+
if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then
1535+
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug"
1536+
else
1537+
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release"
1538+
fi
1539+
if [ -z "$CFG_ENABLE_LLVM_ASSERTIONS" ]
1540+
then
1541+
CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=OFF"
1542+
else
1543+
CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=ON"
1544+
fi
1545+
1546+
msg "configuring LLVM with:"
1547+
msg "$CMAKE_ARGS"
1548+
15411549
(cd $LLVM_BUILD_DIR && "$CFG_CMAKE" $CFG_LLVM_SRC_DIR \
1542-
-G "$generator" \
1550+
-G "$CFG_CMAKE_GENERATOR" \
15431551
$CMAKE_ARGS)
15441552
need_ok "LLVM cmake configure failed"
15451553
fi

mk/rt.mk

+24-15
Original file line numberDiff line numberDiff line change
@@ -216,22 +216,31 @@ COMPRT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
216216
COMPRT_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(COMPRT_NAME_$(1))
217217
COMPRT_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/compiler-rt
218218

219-
# Note that on MSVC-targeting builds we hardwire CC/AR to gcc/ar even though
220-
# we're targeting MSVC. This is because although compiler-rt has a CMake build
221-
# config I can't actually figure out how to use it, so I'm not sure how to use
222-
# cl.exe to build the objects. Additionally, the compiler-rt library when built
223-
# with gcc has the same ABI as cl.exe, so they're largely compatible
224-
COMPRT_CC_$(1) := $$(CC_$(1))
225-
COMPRT_AR_$(1) := $$(AR_$(1))
226-
COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1))
227219
ifeq ($$(findstring msvc,$(1)),msvc)
228-
COMPRT_CC_$(1) := gcc
229-
COMPRT_AR_$(1) := ar
230-
ifeq ($$(findstring i686,$(1)),i686)
231-
COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m32
220+
$$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS) $$(LLVM_CONFIG_$(1))
221+
@$$(call E, cmake: compiler-rt)
222+
$$(Q)cd "$$(COMPRT_BUILD_DIR_$(1))"; $$(CFG_CMAKE) "$(S)src/compiler-rt" \
223+
-DCMAKE_BUILD_TYPE=$$(LLVM_BUILD_CONFIG_MODE) \
224+
-DLLVM_CONFIG_PATH=$$(LLVM_CONFIG_$(1)) \
225+
-G"$$(CFG_CMAKE_GENERATOR)"
226+
$$(Q)$$(CFG_CMAKE) --build "$$(COMPRT_BUILD_DIR_$(1))" \
227+
--target lib/builtins/builtins \
228+
--config $$(LLVM_BUILD_CONFIG_MODE) \
229+
-- //v:m //nologo
230+
$$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/lib/windows/$$(LLVM_BUILD_CONFIG_MODE)/clang_rt.builtins-$$(HOST_$(1)).lib $$@
232231
else
233-
COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m64
234-
endif
232+
COMPRT_CC_$(1) := $$(CC_$(1))
233+
COMPRT_AR_$(1) := $$(AR_$(1))
234+
# We chomp -Werror here because GCC warns about the type signature of
235+
# builtins not matching its own and the build fails. It's a bit hacky,
236+
# but what can we do, we're building libclang-rt using GCC ......
237+
COMPRT_CFLAGS_$(1) := $$(subst -Werror,,$$(CFG_GCCISH_CFLAGS_$(1))) -std=c99
238+
239+
# FreeBSD Clang's packaging is problematic; it doesn't copy unwind.h to
240+
# the standard include directory. This should really be in our changes to
241+
# compiler-rt, but we override the CFLAGS here so there isn't much choice
242+
ifeq ($$(findstring freebsd,$(1)),freebsd)
243+
COMPRT_CFLAGS_$(1) += -I/usr/include/c++/v1
235244
endif
236245

237246
$$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
@@ -246,7 +255,7 @@ $$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
246255
TargetTriple=$(1) \
247256
triple-builtins
248257
$$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/triple/builtins/libcompiler_rt.a $$@
249-
258+
endif
250259
################################################################################
251260
# libbacktrace
252261
#

0 commit comments

Comments
 (0)