Skip to content

Commit ae36d4f

Browse files
committed
mk: Add support for i686-pc-windows-msvc
This commit modifies the configure script and our makefiles to support building 32-bit MSVC targets. The MSVC toolchain is now parameterized over whether it can produce a 32-bit or 64-bit binary. The configure script was updated to export more variables at configure time, and the makefiles were rejiggered to selectively reexport the relevant environment variables for the applicable targets they're going to run for.
1 parent 2ba46f8 commit ae36d4f

File tree

6 files changed

+138
-35
lines changed

6 files changed

+138
-35
lines changed

configure

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ do
11141114
fi
11151115
;;
11161116

1117-
x86_64-*-msvc)
1117+
*-msvc)
11181118
# Currently the build system is not configured to build jemalloc
11191119
# with MSVC, so we omit this optional dependency.
11201120
step_msg "targeting MSVC, disabling jemalloc"
@@ -1154,22 +1154,45 @@ do
11541154
CFG_MSVC_ROOT=$(echo "$install" | grep InstallDir | sed 's/.*REG_SZ[ ]*//')
11551155
CFG_MSVC_ROOT=$(dirname "$CFG_MSVC_ROOT")
11561156
CFG_MSVC_ROOT=$(dirname "$CFG_MSVC_ROOT")
1157-
CFG_MSVC_CL="${CFG_MSVC_ROOT}/VC/bin/amd64/cl.exe"
1158-
CFG_MSVC_LIB="${CFG_MSVC_ROOT}/VC/bin/amd64/lib.exe"
1159-
CFG_MSVC_LINK="${CFG_MSVC_ROOT}/VC/bin/amd64/link.exe"
1157+
putvar CFG_MSVC_ROOT
1158+
1159+
case $i in
1160+
x86_64-*)
1161+
bits=x86_64
1162+
msvc_part=amd64
1163+
;;
1164+
i686-*)
1165+
bits=i386
1166+
msvc_part=
1167+
;;
1168+
*)
1169+
err "can only target x86 targets for MSVC"
1170+
;;
1171+
esac
1172+
bindir="${CFG_MSVC_ROOT}/VC/bin"
1173+
if [ ! -z "$msvc_part" ]; then
1174+
bindir="$bindir/$msvc_part"
1175+
fi
1176+
eval CFG_MSVC_BINDIR_$bits="\"$bindir\""
1177+
eval CFG_MSVC_CL_$bits="\"$bindir/cl.exe\""
1178+
eval CFG_MSVC_LIB_$bits="\"$bindir/lib.exe\""
1179+
eval CFG_MSVC_LINK_$bits="\"$bindir/link.exe\""
11601180

11611181
vcvarsall="${CFG_MSVC_ROOT}/VC/vcvarsall.bat"
1162-
CFG_MSVC_INCLUDE_PATH=$(cmd /c "\"$vcvarsall\" amd64 && cmd /c echo %INCLUDE%")
1182+
include_path=$(cmd /c "\"$vcvarsall\" $msvc_part && cmd /c echo %INCLUDE%")
11631183
need_ok "failed to learn about MSVC's INCLUDE"
1164-
CFG_MSVC_LIB_PATH=$(cmd /c "\"$vcvarsall\" amd64 && cmd /c echo %LIB%")
1184+
lib_path=$(cmd /c "\"$vcvarsall\" $msvc_part && cmd /c echo %LIB%")
11651185
need_ok "failed to learn about MSVC's LIB"
11661186

1167-
putvar CFG_MSVC_ROOT
1168-
putvar CFG_MSVC_CL
1169-
putvar CFG_MSVC_LIB
1170-
putvar CFG_MSVC_LINK
1171-
putvar CFG_MSVC_INCLUDE_PATH
1172-
putvar CFG_MSVC_LIB_PATH
1187+
eval CFG_MSVC_INCLUDE_PATH_${bits}="\"$include_path\""
1188+
eval CFG_MSVC_LIB_PATH_${bits}="\"$lib_path\""
1189+
1190+
putvar CFG_MSVC_BINDIR_${bits}
1191+
putvar CFG_MSVC_CL_${bits}
1192+
putvar CFG_MSVC_LIB_${bits}
1193+
putvar CFG_MSVC_LINK_${bits}
1194+
putvar CFG_MSVC_INCLUDE_PATH_${bits}
1195+
putvar CFG_MSVC_LIB_PATH_${bits}
11731196
;;
11741197

11751198
*)
@@ -1408,8 +1431,19 @@ do
14081431

14091432
msg "configuring LLVM with:"
14101433
msg "$CMAKE_ARGS"
1434+
case "$t" in
1435+
x86_64-*)
1436+
generator="Visual Studio 12 2013 Win64"
1437+
;;
1438+
i686-*)
1439+
generator="Visual Studio 12 2013"
1440+
;;
1441+
*)
1442+
err "can only build LLVM for x86 platforms"
1443+
;;
1444+
esac
14111445
(cd $LLVM_BUILD_DIR && "$CFG_CMAKE" $CFG_LLVM_SRC_DIR \
1412-
-G "Visual Studio 12 2013 Win64" \
1446+
-G "$generator" \
14131447
$CMAKE_ARGS)
14141448
need_ok "LLVM cmake configure failed"
14151449
fi

mk/cfg/i686-pc-windows-msvc.mk

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# i686-pc-windows-msvc configuration
2+
CC_i686-pc-windows-msvc="$(CFG_MSVC_CL_i386)" -nologo
3+
LINK_i686-pc-windows-msvc="$(CFG_MSVC_LINK_i386)" -nologo
4+
CXX_i686-pc-windows-msvc="$(CFG_MSVC_CL_i386)" -nologo
5+
CPP_i686-pc-windows-msvc="$(CFG_MSVC_CL_i386)" -nologo
6+
AR_i686-pc-windows-msvc="$(CFG_MSVC_LIB_i386)" -nologo
7+
CFG_LIB_NAME_i686-pc-windows-msvc=$(1).dll
8+
CFG_STATIC_LIB_NAME_i686-pc-windows-msvc=$(1).lib
9+
CFG_LIB_GLOB_i686-pc-windows-msvc=$(1)-*.{dll,lib}
10+
CFG_LIB_DSYM_GLOB_i686-pc-windows-msvc=$(1)-*.dylib.dSYM
11+
CFG_JEMALLOC_CFLAGS_i686-pc-windows-msvc :=
12+
CFG_GCCISH_CFLAGS_i686-pc-windows-msvc := -MD
13+
CFG_GCCISH_CXXFLAGS_i686-pc-windows-msvc := -MD
14+
CFG_GCCISH_LINK_FLAGS_i686-pc-windows-msvc :=
15+
CFG_GCCISH_DEF_FLAG_i686-pc-windows-msvc :=
16+
CFG_LLC_FLAGS_i686-pc-windows-msvc :=
17+
CFG_INSTALL_NAME_i686-pc-windows-msvc =
18+
CFG_EXE_SUFFIX_i686-pc-windows-msvc := .exe
19+
CFG_WINDOWSY_i686-pc-windows-msvc := 1
20+
CFG_UNIXY_i686-pc-windows-msvc :=
21+
CFG_LDPATH_i686-pc-windows-msvc :=
22+
CFG_RUN_i686-pc-windows-msvc=$(2)
23+
CFG_RUN_TARG_i686-pc-windows-msvc=$(call CFG_RUN_i686-pc-windows-msvc,,$(2))
24+
CFG_GNU_TRIPLE_i686-pc-windows-msvc := i686-pc-win32
25+
26+
# All windows nightiles are currently a GNU triple, so this MSVC triple is not
27+
# bootstrapping from itself. This is relevant during stage0, and other parts of
28+
# the build system take this into account.
29+
BOOTSTRAP_FROM_i686-pc-windows-msvc := i686-pc-windows-gnu

mk/cfg/x86_64-pc-windows-msvc.mk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# x86_64-pc-windows-msvc configuration
2-
CC_x86_64-pc-windows-msvc="$(CFG_MSVC_CL)" -nologo
3-
LINK_x86_64-pc-windows-msvc="$(CFG_MSVC_LINK)" -nologo
4-
CXX_x86_64-pc-windows-msvc="$(CFG_MSVC_CL)" -nologo
5-
CPP_x86_64-pc-windows-msvc="$(CFG_MSVC_CL)" -nologo
6-
AR_x86_64-pc-windows-msvc="$(CFG_MSVC_LIB)" -nologo
2+
CC_x86_64-pc-windows-msvc="$(CFG_MSVC_CL_x86_64)" -nologo
3+
LINK_x86_64-pc-windows-msvc="$(CFG_MSVC_LINK_x86_64)" -nologo
4+
CXX_x86_64-pc-windows-msvc="$(CFG_MSVC_CL_x86_64)" -nologo
5+
CPP_x86_64-pc-windows-msvc="$(CFG_MSVC_CL_x86_64)" -nologo
6+
AR_x86_64-pc-windows-msvc="$(CFG_MSVC_LIB_x86_64)" -nologo
77
CFG_LIB_NAME_x86_64-pc-windows-msvc=$(1).dll
88
CFG_STATIC_LIB_NAME_x86_64-pc-windows-msvc=$(1).lib
99
CFG_LIB_GLOB_x86_64-pc-windows-msvc=$(1)-*.{dll,lib}

mk/platform.mk

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,23 +239,6 @@ endef
239239
$(foreach target,$(CFG_TARGET), \
240240
$(eval $(call CFG_MAKE_TOOLCHAIN,$(target))))
241241

242-
# These two environment variables are scraped by the `./configure` script and
243-
# are necessary for `cl.exe` to find standard headers (the INCLUDE variable) and
244-
# for `link.exe` to find standard libraries (the LIB variable).
245-
ifdef CFG_MSVC_INCLUDE_PATH
246-
export INCLUDE := $(CFG_MSVC_INCLUDE_PATH)
247-
endif
248-
ifdef CFG_MSVC_LIB_PATH
249-
export LIB := $(CFG_MSVC_LIB_PATH)
250-
endif
251-
252-
# Unfortunately `link.exe` is also a program in `/usr/bin` on MinGW installs,
253-
# but it's not the one that we want. As a result we make sure that our detected
254-
# `link.exe` shows up in PATH first.
255-
ifdef CFG_MSVC_LINK
256-
export PATH := $(CFG_MSVC_ROOT)/VC/bin/amd64:$(PATH)
257-
endif
258-
259242
# There are more comments about this available in the target specification for
260243
# Windows MSVC in the compiler, but the gist of it is that we use `llvm-ar.exe`
261244
# instead of `lib.exe` for assembling archives, so we need to inject this custom
@@ -307,3 +290,4 @@ endef
307290

308291
$(foreach target,$(CFG_TARGET), \
309292
$(eval $(call ADD_RUSTC_LLVM_DEF_TO_MSVC,$(target))))
293+

mk/rt.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ NATIVE_DEPS_rust_builtin_$(1) := rust_builtin.c \
5555
rust_android_dummy.c
5656
NATIVE_DEPS_rustrt_native_$(1) := arch/$$(HOST_$(1))/record_sp.S
5757
ifeq ($$(findstring msvc,$(1)),msvc)
58+
ifeq ($$(findstring i686,$(1)),i686)
59+
NATIVE_DEPS_rustrt_native_$(1) += rust_try_msvc_32.ll
60+
else
5861
NATIVE_DEPS_rustrt_native_$(1) += rust_try_msvc_64.ll
62+
endif
5963
else
6064
NATIVE_DEPS_rustrt_native_$(1) += rust_try.ll
6165
endif
@@ -93,6 +97,17 @@ $$(RT_OUTPUT_DIR_$(1))/%.o: $(S)src/rt/%.S $$(MKFILE_DEPS) \
9397
@mkdir -p $$(@D)
9498
@$$(call E, compile: $$@)
9599
$$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
100+
101+
# On MSVC targets the compiler's default include path (e.g. where to find system
102+
# headers) is specified by the INCLUDE environment variable. This may not be set
103+
# so the ./configure script scraped the relevant values and this is the location
104+
# that we put them into cl.exe's environment.
105+
ifeq ($$(findstring msvc,$(1)),msvc)
106+
$$(RT_OUTPUT_DIR_$(1))/%.o: \
107+
export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(1)))
108+
$(1)/rustllvm/%.o: \
109+
export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(1)))
110+
endif
96111
endef
97112

98113
$(foreach target,$(CFG_TARGET),$(eval $(call NATIVE_LIBRARIES,$(target))))
@@ -240,8 +255,12 @@ COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1))
240255
ifeq ($$(findstring msvc,$(1)),msvc)
241256
COMPRT_CC_$(1) := gcc
242257
COMPRT_AR_$(1) := ar
258+
ifeq ($$(findstring i686,$(1)),i686)
259+
COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m32
260+
else
243261
COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m64
244262
endif
263+
endif
245264

246265
$$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
247266
@$$(call E, make: compiler-rt)

mk/target.mk

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,40 @@ $(foreach target,$(CFG_TARGET), \
220220
$(foreach crate,$(CRATES), \
221221
$(foreach tool,$(NATIVE_TOOL_DEPS_$(crate)_T_$(target)), \
222222
$(eval $(call MOVE_TOOLS_TO_SNAPSHOT_HOST_DIR,0,$(target),$(BOOTSTRAP_FROM_$(target)),$(crate),$(tool))))))
223+
224+
# For MSVC targets we need to set up some environment variables for the linker
225+
# to work correctly when building Rust crates. These two variables are:
226+
#
227+
# - LIB tells the linker the default search path for finding system libraries,
228+
# for example kernel32.dll
229+
# - PATH needs to be modified to ensure that MSVC's link.exe is first in the
230+
# path instead of MinGW's /usr/bin/link.exe (entirely unrelated)
231+
#
232+
# The values for these variables are detected by the configure script.
233+
define SETUP_LIB_MSVC_ENV_VARS
234+
ifeq ($$(findstring msvc,$(2)),msvc)
235+
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
236+
export LIB := $$(CFG_MSVC_LIB_PATH_$$(HOST_$(2)))
237+
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
238+
export PATH := $$(CFG_MSVC_BINDIR_$$(HOST_$(2))):$$(PATH)
239+
endif
240+
endef
241+
define SETUP_TOOL_MSVC_ENV_VARS
242+
ifeq ($$(findstring msvc,$(2)),msvc)
243+
$$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
244+
export LIB := $$(CFG_MSVC_LIB_PATH_$$(HOST_$(2)))
245+
$$(TBIN$(1)_T_$(2)_H_$(3))/$(4)$$(X_$(2)): \
246+
export PATH := $$(CFG_MSVC_BINDIR_$$(HOST_$(2))):$$(PATH)
247+
endif
248+
endef
249+
250+
$(foreach host,$(CFG_HOST), \
251+
$(foreach target,$(CFG_TARGET), \
252+
$(foreach stage,$(STAGES), \
253+
$(foreach crate,$(CRATES), \
254+
$(eval $(call SETUP_LIB_MSVC_ENV_VARS,$(stage),$(target),$(host),$(crate)))))))
255+
$(foreach host,$(CFG_HOST), \
256+
$(foreach target,$(CFG_TARGET), \
257+
$(foreach stage,$(STAGES), \
258+
$(foreach tool,$(TOOLS), \
259+
$(eval $(call SETUP_TOOL_MSVC_ENV_VARS,$(stage),$(target),$(host),$(tool)))))))

0 commit comments

Comments
 (0)