Skip to content

Commit 64412a4

Browse files
committed
mk: Fix building compiler-rt on MSVC
It looks like compiler-rt has a cmake build sytem inside its source, but I have been unable to figure out how to use it and actually build the right library. For now this commit hard-wires MSVC-targeting builds of libcompiler-rt to continue using `make` as the primary bulid system, but some frobbing of the flags are necessary to ensure that the right compiler is used.
1 parent ee64bab commit 64412a4

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

mk/rt.mk

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,32 @@ COMPRT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
226226
COMPRT_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(COMPRT_NAME_$(1))
227227
COMPRT_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/compiler-rt
228228

229+
# Note that on MSVC-targeting builds we hardwire CC/AR to gcc/ar even though
230+
# we're targeting MSVC. This is because although compiler-rt has a CMake build
231+
# config I can't actually figure out how to use it, so I'm not sure how to use
232+
# cl.exe to build the objects. Additionally, the compiler-rt library when built
233+
# with gcc has the same ABI as cl.exe, so they're largely compatible
234+
COMPRT_CC_$(1) := $$(CC_$(1))
235+
COMPRT_AR_$(1) := $$(AR_$(1))
236+
COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1))
237+
ifeq ($$(findstring msvc,$(1)),msvc)
238+
COMPRT_CC_$(1) := gcc
239+
COMPRT_AR_$(1) := ar
240+
COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m64
241+
endif
242+
229243
$$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
230244
@$$(call E, make: compiler-rt)
231245
$$(Q)$$(MAKE) -C "$(S)src/compiler-rt" \
232246
ProjSrcRoot="$(S)src/compiler-rt" \
233247
ProjObjRoot="$$(abspath $$(COMPRT_BUILD_DIR_$(1)))" \
234-
CC="$$(CC_$(1))" \
235-
AR="$$(AR_$(1))" \
236-
RANLIB="$$(AR_$(1)) s" \
237-
CFLAGS="$$(CFG_GCCISH_CFLAGS_$(1))" \
248+
CC='$$(COMPRT_CC_$(1))' \
249+
AR='$$(COMPRT_AR_$(1))' \
250+
RANLIB='$$(COMPRT_AR_$(1)) s' \
251+
CFLAGS="$$(COMPRT_CFLAGS_$(1))" \
238252
TargetTriple=$(1) \
239253
triple-builtins
240-
$$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/triple/builtins/libcompiler_rt.a $$(COMPRT_LIB_$(1))
254+
$$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/triple/builtins/libcompiler_rt.a $$@
241255

242256
################################################################################
243257
# libbacktrace

0 commit comments

Comments
 (0)