Skip to content

Commit 745a3ce

Browse files
committed
auto merge of #13462 : alexcrichton/rust/fix-cross-rpath, r=brson
After removing absolute rpaths, cross compile builds (notably the nightly builders) broke. This is because the RPATH was pointing at an empty directory because only the rustc binary is copied over, not all of the target libraries. This modifies the cross compile logic to fixup the rpath of the stage0 cross-compiled rustc to point to where it came from.
2 parents 96aeb7e + c60d9ad commit 745a3ce

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

mk/main.mk

+32-4
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,44 @@ EXTRAFLAGS_STAGE$(1) = $$(RUSTFLAGS_STAGE$(1))
349349

350350
CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
351351

352+
endef
353+
354+
# Same macro/variables as above, but defined in a separate loop so it can use
355+
# all the varibles above for all archs. The RPATH_VAR setup sometimes needs to
356+
# reach across triples to get things in order.
357+
define SREQ_CMDS
358+
359+
ifeq ($$(OSTYPE_$(3)),apple-darwin)
360+
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
361+
DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
362+
else
363+
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
364+
LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
365+
endif
366+
352367
# Pass --cfg stage0 only for the build->host part of stage0;
353368
# if you're building a cross config, the host->* parts are
354369
# effectively stage1, since it uses the just-built stage0.
370+
#
371+
# This logic is similar to how the LD_LIBRARY_PATH variable must
372+
# change be slightly different when doing cross compilations.
373+
# The build doesn't copy over all target libraries into
374+
# a new directory, so we need to point the library path at
375+
# the build directory where all the target libraries came
376+
# from (the stage0 build host). Otherwise the relative rpaths
377+
# inside of the rustc binary won't get resolved correctly.
355378
ifeq ($(1),0)
356379
ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
357380
CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
358-
endif
359-
endif
360381

361382
ifeq ($$(OSTYPE_$(3)),apple-darwin)
362383
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
363-
DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
384+
DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))"
364385
else
365386
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
366-
LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
387+
LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))"
388+
endif
389+
endif
367390
endif
368391

369392
STAGE$(1)_T_$(2)_H_$(3) := \
@@ -390,6 +413,11 @@ $(foreach build,$(CFG_HOST), \
390413
$(eval $(foreach stage,$(STAGES), \
391414
$(eval $(call SREQ,$(stage),$(target),$(build))))))))
392415

416+
$(foreach build,$(CFG_HOST), \
417+
$(eval $(foreach target,$(CFG_TARGET), \
418+
$(eval $(foreach stage,$(STAGES), \
419+
$(eval $(call SREQ_CMDS,$(stage),$(target),$(build))))))))
420+
393421
######################################################################
394422
# rustc-H-targets
395423
#

0 commit comments

Comments
 (0)