Skip to content

Commit b8c5921

Browse files
committed
mk: Fix MSVC bootstrapping itself
Now that MSVC support has landed in the most recent nightlies we can now have MSVC bootstrap itself without going through a GNU compiler first. Unfortunately, however, the bootstrap currently fails due to the compiler not being able to find the llvm-ar.exe tool during the stage0 libcore compile. The compiler cannot find this tool because it's looking inside a directory that does not exist: $SYSROOT/rustlib/x86_64-pc-windows-gnu/bin The `gnu` on this triple is because the bootstrap compiler's host architecture is GNU. The build system, however, only arranges for the llvm-ar.exe tool to be available in this location: $SYSROOT/rustlib/x86_64-pc-windows-msvc/bin To resolve this discrepancy, the build system has been modified to understand triples that are bootstrapped from another triple, and in this case copy the native tools to the right location.
1 parent efcc1d1 commit b8c5921

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ CUSTOM_DEPS_rustc_llvm_T_x86_64-pc-windows-msvc += \
8080
x86_64-pc-windows-msvc/rt/rustc_llvm.def: $(S)src/etc/mklldef.py \
8181
$(S)src/librustc_llvm/lib.rs
8282
$(CFG_PYTHON) $^ $@ rustc_llvm-$(CFG_FILENAME_EXTRA)
83+
84+
# All windows nightiles are currently a GNU triple, so this MSVC triple is not
85+
# bootstrapping from itself. This is relevant during stage0, and other parts of
86+
# the build system take this into account.
87+
BOOTSTRAP_FROM_x86_64-pc-windows-msvc := x86_64-pc-windows-gnu

mk/target.mk

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,42 @@ $(foreach host,$(CFG_HOST), \
181181
$(foreach stage,$(STAGES), \
182182
$(foreach tool,$(TOOLS), \
183183
$(eval $(call TARGET_TOOL,$(stage),$(target),$(host),$(tool)))))))
184+
185+
# We have some triples which are bootstrapped from other triples, and this means
186+
# that we need to fixup some of the native tools that a triple depends on.
187+
#
188+
# For example, MSVC requires the llvm-ar.exe executable to manage archives, but
189+
# it bootstraps from the GNU Windows triple. This means that the compiler will
190+
# add this directory to PATH when executing new processes:
191+
#
192+
# $SYSROOT/rustlib/x86_64-pc-windows-gnu/bin
193+
#
194+
# Unfortunately, however, the GNU triple is not known about in stage0, so the
195+
# tools are actually located in:
196+
#
197+
# $SYSROOT/rustlib/x86_64-pc-windows-msvc/bin
198+
#
199+
# To remedy this problem, the rules below copy all native tool dependencies into
200+
# the bootstrap triple's location in stage 0 so the bootstrap compiler can find
201+
# the right sets of tools. Later stages (1+) will have the right host triple for
202+
# the compiler, so there's no need to worry there.
203+
#
204+
# $(1) - stage
205+
# $(2) - triple that's being used as host/target
206+
# $(3) - triple snapshot is built for
207+
# $(4) - crate
208+
# $(5) - tool
209+
define MOVE_TOOLS_TO_SNAPSHOT_HOST_DIR
210+
ifneq (,$(3))
211+
$$(TLIB$(1)_T_$(2)_H_$(2))/stamp.$(4): $$(HLIB$(1)_H_$(2))/rustlib/$(3)/bin/$(5)
212+
213+
$$(HLIB$(1)_H_$(2))/rustlib/$(3)/bin/$(5): $$(TBIN$(1)_T_$(2)_H_$(2))/$(5)
214+
mkdir -p $$(@D)
215+
cp $$< $$@
216+
endif
217+
endef
218+
219+
$(foreach target,$(CFG_TARGET), \
220+
$(foreach crate,$(CRATES), \
221+
$(foreach tool,$(NATIVE_TOOL_DEPS_$(crate)_T_$(target)), \
222+
$(eval $(call MOVE_TOOLS_TO_SNAPSHOT_HOST_DIR,0,$(target),$(BOOTSTRAP_FROM_$(target)),$(crate),$(tool))))))

0 commit comments

Comments
 (0)