endef
# Same macro/variables as above, but defined in a separate loop so it can use
-# all the varibles above for all archs. The RPATH_VAR setup sometimes needs to
+# all the variables above for all archs. The RPATH_VAR setup sometimes needs to
# reach across triples to get things in order.
+#
+# Defines (with the standard $(1)_T_$(2)_H_$(3) suffix):
+# * `LD_LIBRARY_PATH_ENV_NAME`: the name for the key to use in the OS
+# environment to access or extend the lookup path for dynamic
+# libraries. Note on Windows, that key is `$PATH`, and thus not
+# only conflates programs with dynamic libraries, but also often
+# contains spaces which confuse make.
+# * `LD_LIBRARY_PATH_ENV_HOSTDIR`: the entry to add to lookup path for the host
+# * `LD_LIBRARY_PATH_ENV_TARGETDIR`: the entry to add to lookup path for target
+#
+# Below that, HOST_RPATH_VAR and TARGET_RPATH_VAR are defined in terms of the
+# above settings.
+#
define SREQ_CMDS
ifeq ($$(OSTYPE_$(3)),apple-darwin)
- RPATH_VAR$(1)_T_$(2)_H_$(3) := \
- DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
+ LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := DYLD_LIBRARY_PATH
+else
+ifeq ($$(CFG_WINDOWSY_$(2)),1)
+ LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := PATH
else
- RPATH_VAR$(1)_T_$(2)_H_$(3) := \
- LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
+ LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := LD_LIBRARY_PATH
+endif
endif
+LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3) := \
+ $$(CURDIR)/$$(HLIB$(1)_H_$(3))
+LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3) := \
+ $$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))
+
+HOST_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
+ $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))=$$$$$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)):$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))
+TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
+ $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))=$$$$$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)):$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))
+
+RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(HOST_RPATH_VAR$(1)_T_$(2)_H_$(3))
+
# Pass --cfg stage0 only for the build->host part of stage0;
# if you're building a cross config, the host->* parts are
# effectively stage1, since it uses the just-built stage0.
ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
-ifeq ($$(OSTYPE_$(3)),apple-darwin)
- RPATH_VAR$(1)_T_$(2)_H_$(3) := \
- DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))"
-else
- RPATH_VAR$(1)_T_$(2)_H_$(3) := \
- LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))"
-endif
+RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3))
endif
endif
CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
endif
+# (Issues #13732, #13983, #14000) The doc for the regex crate includes
+# uses of the `regex!` macro from the regex_macros crate. There is
+# normally a dependence injected that makes the target's regex depend
+# upon the host's regex_macros (see #13845), but that dependency
+# injection is currently skipped for stage1 as a special case.
+#
+# Therefore, as a further special case, this conditional skips
+# attempting to run the doc tests for the regex crate atop stage1,
+# (since there is no regex_macros crate for the stage1 rustc to load).
+#
+# (Another approach for solving this would be to inject the desired
+# dependence for stage1 as well, by setting things up to generate a
+# regex_macros crate that was compatible with the stage1 rustc and
+# thus re-enable our ability to run this test.)
+ifeq (stage$(1)-crate-$(4),stage1-crate-regex)
+check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec:
+ @$$(call E, skipping doc-crate-$(4) as it uses macros and cannot run at stage$(1))
+else
check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
+endif
ifeq ($(2),$$(CFG_BUILD))
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
"$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
"$$(TESTNAME)" \
- "$$(RPATH_VAR$(1)_T_$(2)_H_$(3))"
+ $$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
+ "$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
+ "$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
+ $(1)
@touch $$@
else
# FIXME #11094 - The above rule doesn't work right for multiple targets
value = normalize_path(value)
os.putenv(name, value)
+def convert_path_spec(name, value):
+ if os.name == 'nt' and name != 'PATH':
+ value = ":".join(normalize_path(v) for v in value.split(";"))
+ return value
make = sys.argv[2]
putenv('RUSTC', os.path.abspath(sys.argv[3]))
putenv('CC', sys.argv[5])
putenv('RUSTDOC', os.path.abspath(sys.argv[6]))
filt = sys.argv[7]
-ldpath = sys.argv[8]
-if ldpath != '':
- name = ldpath.split('=')[0]
- value = ldpath.split('=')[1]
- if os.name == 'nt' and name != 'PATH':
- value = ":".join(normalize_path(v) for v in value.split(";"))
- os.putenv(name, value)
+putenv('LD_LIB_PATH_ENVVAR', sys.argv[8]);
+putenv('HOST_RPATH_DIR', os.path.abspath(sys.argv[9]));
+putenv('TARGET_RPATH_DIR', os.path.abspath(sys.argv[10]));
+putenv('RUST_BUILD_STAGE', sys.argv[11])
if not filt in sys.argv[1]:
sys.exit(0)
-include ../tools.mk
+HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
+# This overrides the LD_LIBRARY_PATH for RUN
+TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
+
all:
$(RUSTC) lib.rs
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
- $(CC) main.c -o $(call RUN,main) -lboot
+ $(CC) main.c -o $(call RUN_BINFILE,main) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -lboot
$(call RUN,main)
- rm $(call DYLIB,boot)
+ $(call REMOVE_DYLIBS,boot)
$(call FAIL,main)
-include ../tools.mk
+HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
+# This overrides the LD_LIBRARY_PATH for RUN
+TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
+
all:
$(RUSTC) lib.rs
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
- $(CC) main.c -o $(call RUN,main) -lboot
+ $(CC) main.c -o $(call RUN_BINFILE,main) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -lboot
$(call RUN,main)
- rm $(call DYLIB,boot)
+ $(call REMOVE_DYLIBS,boot)
$(call FAIL,main)
$(RUSTC) foo.rs
$(RUSTC) bar.rs
$(call RUN,bar)
- rm $(TMPDIR)/$(call DYLIB_GLOB,cfoo)
+ $(call REMOVE_DYLIBS,cfoo)
$(call FAIL,bar)
endif
-include ../tools.mk
+# This overrides the LD_LIBRARY_PATH for RUN
+TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
+
# This hits an assertion in the linker on older versions of osx apparently
ifeq ($(shell uname),Darwin)
all:
all: $(call DYLIB,cfoo)
$(RUSTC) foo.rs
$(RUSTC) bar.rs
- LD_LIBRARY_PATH=$(TMPDIR) $(call RUN,bar)
- rm $(TMPDIR)/$(call DYLIB_GLOB,cfoo)
+ $(call RUN,bar)
+ $(call REMOVE_DYLIBS,cfoo)
$(call FAIL,bar)
endif
-include ../tools.mk
+HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
+
all:
$(RUSTC) foo.rs
ln -s $(call DYLIB,foo-*) $(call DYLIB,foo)
- $(CC) bar.c -lfoo -o $(call RUN,bar) -Wl,-rpath,$(TMPDIR)
+ $(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -Wl,-rpath,$(TMPDIR)
$(call RUN,bar)
- rm $(call DYLIB,foo)
+ $(call REMOVE_DYLIBS,foo)
$(call FAIL,bar)
all:
$(RUSTC) foo.rs
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
- $(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++
+ $(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRAFLAGS) -lstdc++
$(call RUN,bar)
rm $(call STATICLIB,foo*)
$(call RUN,bar)
$(RUSTC) bar.rs
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
$(call RUN,bar)
- rm $(TMPDIR)/$(call DYLIB_GLOB,foo)
+ $(call REMOVE_DYLIBS,foo)
$(call FAIL,bar)
all: $(call STATICLIB,cfoo)
$(RUSTC) foo.rs
$(RUSTC) bar.rs
- rm $(TMPDIR)/$(call RLIB_GLOB,foo)
+ $(call REMOVE_RLIBS,foo)
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
$(call RUN,bar)
$(RUSTC) m3.rs
$(RUSTC) m4.rs
$(call RUN,m4)
- rm $(TMPDIR)/$(call DYLIB_GLOB,m1)
- rm $(TMPDIR)/$(call DYLIB_GLOB,m2)
- rm $(TMPDIR)/$(call DYLIB_GLOB,m3)
+ $(call REMOVE_DYLIBS,m1)
+ $(call REMOVE_DYLIBS,m2)
+ $(call REMOVE_DYLIBS,m3)
$(call FAIL,m4)
-include ../tools.mk
+# This overrides the LD_LIBRARY_PATH for RUN
+TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
+
all:
$(RUSTC) dylib.rs -o $(TMPDIR)/libdylib.so
$(RUSTC) main.rs
all:
$(RUSTC) foo.rs -Z lto
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
- $(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++
+ $(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRAFLAGS) -lstdc++
$(call RUN,bar)
-include ../tools.mk
-all:
+# This test attempts to use syntax extensions, which are known to be
+# incompatible with stage1 at the moment.
+
+ifeq ($(RUST_BUILD_STAGE),1)
+DOTEST=
+else
+DOTEST=dotest
+endif
+
+all: $(DOTEST)
+
+dotest:
+ env
$(RUSTC) lib.rs
$(RUSTC) main.rs -Z lto
$(call RUN,main)
all:
$(RUSTC) --crate-type=rlib crateA.rs
$(RUSTC) --crate-type=rlib crateB.rs
- rm $(TMPDIR)/$(call RLIB_GLOB,crateA)
+ $(call REMOVE_RLIBS,crateA)
# Ensure crateC fails to compile since dependency crateA is missing
$(RUSTC) crateC.rs 2>&1 | \
grep "error: can't find crate for \`crateA\` which \`crateB\` depends on"
$(RUSTC) dylib.rs
$(RUSTC) rlib.rs --crate-type=dylib
$(RUSTC) dylib.rs
- rm $(call DYLIB,rlib-*)
+ $(call REMOVE_DYLIBS,rlib)
$(RUSTC) prog.rs && exit 1 || exit 0
# fail if an rlib was built
all:
$(RUSTC) test.rs
- rm $(TMPDIR)/$(call RLIB_GLOB,test)
- rm $(TMPDIR)/$(call DYLIB_GLOB,test)
+ $(call REMOVE_RLIBS,test)
+ $(call REMOVE_DYLIBS,test)
$(RUSTC) --crate-type dylib test.rs
- rm $(TMPDIR)/$(call RLIB_GLOB,test) && exit 1 || exit 0
+ $(call REMOVE_RLIBS,test) && exit 1 || exit 0
all:
$(RUSTC) foo.rs --crate-type=rlib,dylib,staticlib
- rm $(TMPDIR)/$(call RLIB_GLOB,bar)
- rm $(TMPDIR)/$(call DYLIB_GLOB,bar)
+ $(call REMOVE_RLIBS,bar)
+ $(call REMOVE_DYLIBS,bar)
rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
$(RUSTC) foo.rs --crate-type=bin
rm $(TMPDIR)/$(call BIN,bar)
cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc
rm $(TMPDIR)/bar.bc
rm $(TMPDIR)/foo.bc
- rm $(TMPDIR)/$(call RLIB_GLOB,bar)
+ $(call REMOVE_RLIBS,bar)
$(RUSTC) foo.rs -C prefer-dynamic
$(call RUN,foo)
rm $(TMPDIR)/*bar*
- $(call FAILS,foo)
+ $(call FAIL,foo)
RUSTC := $(RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR)
CC := $(CC) -L $(TMPDIR)
-RUN = $(TMPDIR)/$(1)
-FAILS = $(TMPDIR)/$(1) && exit 1 || exit 0
+# These deliberately use `=` and not `:=` so that client makefiles can
+# augment HOST_RPATH_DIR / TARGET_RPATH_DIR.
+HOST_RPATH_ENV = \
+ $(LD_LIB_PATH_ENVVAR)=$$$(LD_LIB_PATH_ENVVAR):$(HOST_RPATH_DIR)
+TARGET_RPATH_ENV = \
+ $(LD_LIB_PATH_ENVVAR)=$$$(LD_LIB_PATH_ENVVAR):$(TARGET_RPATH_DIR)
+
+# This is the name of the binary we will generate and run; use this
+# e.g. for `$(CC) -o $(RUN_BINFILE)`.
+RUN_BINFILE = $(TMPDIR)/$(1)
+
+# RUN and FAIL are basic way we will invoke the generated binary. On
+# non-windows platforms, they set the LD_LIBRARY_PATH environment
+# variable before running the binary.
RLIB_GLOB = lib$(1)*.rlib
STATICLIB = $(TMPDIR)/lib$(1).a
endif
ifeq ($(UNAME),Darwin)
+RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
+FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
DYLIB_GLOB = lib$(1)*.dylib
DYLIB = $(TMPDIR)/lib$(1).dylib
+RPATH_LINK_SEARCH =
else
ifdef IS_WINDOWS
+RUN = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE)
+FAIL = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE) && exit 1 || exit 0
DYLIB_GLOB = $(1)*.dll
DYLIB = $(TMPDIR)/$(1).dll
BIN = $(1).exe
-export PATH := $(PATH):$(LD_LIBRARY_PATH)
+RPATH_LINK_SEARCH =
+RUSTC := PATH="$(PATH):$(LD_LIBRARY_PATH)" $(RUSTC)
else
+RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
+FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
DYLIB_GLOB = lib$(1)*.so
DYLIB = $(TMPDIR)/lib$(1).so
+RPATH_LINK_SEARCH = -Wl,-rpath-link=$(1)
endif
endif
+REMOVE_DYLIBS = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1))
+REMOVE_RLIBS = rm $(TMPDIR)/$(call RLIB_GLOB,$(1))
+
%.a: %.o
ar crus $@ $<
%.dylib: %.o
-include ../tools.mk
+# This test attempts to run rustc itself from the compiled binary; but
+# that means that you need to set the LD_LIBRARY_PATH for rustc itself
+# while running multiple_files, and that won't work for stage1.
+
# FIXME ignore windows
ifndef IS_WINDOWS
+ifeq ($(RUST_BUILD_STAGE),1)
+DOTEST=
+else
+DOTEST=dotest
+endif
+endif
+
+all: $(DOTEST)
-all:
+dotest:
# check that we don't ICE on unicode input, issue #11178
$(RUSTC) multiple_files.rs
$(call RUN,multiple_files) "$(RUSTC)" "$(TMPDIR)"
# correct length. issue #8706
$(RUSTC) span_length.rs
$(call RUN,span_length) "$(RUSTC)" "$(TMPDIR)"
-
-else
-all:
-
-endif