Skip to content

Commit 8cbda5d

Browse files
committed
Refactoring: Introduce distinct host and target rpath var setters.
Two line summary: Distinguish HOST_RPATH and TARGET_RPATH; added RPATH_LINK_SEARCH; skip tests broken in stage1; general cleanup. `HOST_RPATH_VAR$(1)_T_$(2)_H_$(3)` and `TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3)` both match the format of the old `RPATH_VAR$(1)_T_$(2)_H_$(3)` (which is still being set the same way that it was before, to one of either HOST/TARGET depending on what stage we are building). Namely, the format is <XXX>_RPATH_VAR = "<LD_LIB_PATH_ENVVAR>=<COLON_SEP_PATH_ENTRIES>" What this commit does: * Pass both of the (newly introduced) HOST and TARGET rpath setup vars to `maketest.py` * Update `maketest.py` to no longer update the LD_LIBRARY_PATH itself Instead, it passes along the HOST and TARGET rpath setup vars in environment variables `HOST_RPATH_ENV` and `TARGET_RPATH_ENV` * Also, pass the current stage number to maketest.py; it in turn passes it (via an env var) to run-make tests. This allows the run-make tests to selectively change behavior (e.g. turn themselves off) to deal with incompatibilities with e.g. stage1. * Cleanup: Distinguish in tools.mk between the command to run (`RUN`) and the file to generate to drive that command (`RUN_BINFILE`). The main thing this enables is that `RUN` can now setup the `TARGET_RPATH_ENV` without having to dirty up the runner code in each of the `run-make` Makefiles. * Cleanup: Factored out commands to delete dylib/rlib into REMOVE_DYLIBS/REMOVE_RLIBS. There were places where we were only calling `rm $(call DYLIB,foo)` even though we really needed to get rid of the whole glob (at least based on alex's findings on #13753 that removing the symlink does not suffice). Therefore rather than peppering the code with the awkward `rm $(TMPDIR)/$(call DYLIB_GLOB,foo)`, I instead introduced a common `REMOVE_DYLIBS` user function that expands into that when called. After I adding an analogous `REMOVE_RLIBS`, I changed all of the existing calls that rm dylibs or rlibs to use these routines instead. Note that the latter is not a true refactoring since I may have changed cases where it was our intent to only remove the sym-link. (But if that is the case, then we need to more deeply investigate alex's findings on #13753 where the system was still dynamically loading up the non-symlinked libraries that it finds on the load path.) * Added RPATH_LINK_SEARCH command and use it on Linux. On some platforms, namely Linux, when you have libboot.so that has its internal rpath set (to e.g. $(ORIGIN)/path/to/HOSTDIR), the linker still complains when you do the link step and it does not know where to find libraries that libboot.so depends upon that live in HOSTDIR (think e.g. librustuv.so). As far as I can tell, the GNU linker will consult the LD_LIBRARY_PATH as part of the linking process to find such libraries. But if you want to be more careful and not override LD_LIBRARY_PATH for the `gcc` invocation, then you need some other way to tell the linker where it can find the libraries that libboot.so needs. The solution to this on Linux is the `-Wl,-rpath-link` command line option. However, this command line option does not exist on Mac OS X, (which appears to be figuring out how to resolve the libboot.dylib dependency by some other means, perhaps by consulting the rpath setting within libboot.dylib). So, in order to abstract over this distinction, I added the RPATH_LINK_SEARCH macro to the run-make infrastructure and added calls to it where necessary to get Linux working. On architectures other than Linux, the macro expands to nothing. * Disable miscellaneous tests atop stage1. * An especially interesting instance of the previous bullet point: Excuse regex from doing rustdoc tests atop stage1. This was a (nearly-) final step to get `make check-stage1` working again. The use of a special-case check for regex here is ugly but is analogous other similar checks for regex such as the one that landed in PR #13844. The way this is written, the user will get a reminder that doc-crate-regex is being skipped whenever their rules attempt to do the crate documentation tests. This is deliberate: I want people running `make check-stage1` to be reminded about which cases are being skipped. (But if such echo noise is considered offensive, it can obviously be removed.) * Got windows working with the above changes. This portion of the commit is a cleanup revision of the (previously mentioned on try builds) re-architecting of how the LD_LIBRARY_PATH setup and extension is handled in order to accommodate Windows' (1.) use of `$PATH` for that purpose and (2.) use of spaces in `$PATH` entries (problematic for make and for interoperation with tools at the shell). * In addition, since the code has been rearchitected to pass the HOST_RPATH_DIR/TARGET_RPATH_DIR rather than a whole sh environment-variable setting command, there is no need to for the convert_path_spec calls in maketest.py, which in fact were put in place to placate Windows but were now causing the Windows builds to fail. Instead we just convert the paths to absolute paths just like all of the other path arguments. Also, note for makefile hackers: apparently you cannot quote operands to `ifeq` in Makefile (or at least, you need to be careful about adding them, e.g. to only one side).
1 parent a8646be commit 8cbda5d

File tree

22 files changed

+158
-55
lines changed

22 files changed

+158
-55
lines changed

mk/main.mk

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,18 +349,45 @@ CFGFLAG$(1)_T_$(2)_H_$(3) = stage$(1)
349349
endef
350350

351351
# Same macro/variables as above, but defined in a separate loop so it can use
352-
# all the varibles above for all archs. The RPATH_VAR setup sometimes needs to
352+
# all the variables above for all archs. The RPATH_VAR setup sometimes needs to
353353
# reach across triples to get things in order.
354+
#
355+
# Defines (with the standard $(1)_T_$(2)_H_$(3) suffix):
356+
# * `LD_LIBRARY_PATH_ENV_NAME`: the name for the key to use in the OS
357+
# environment to access or extend the lookup path for dynamic
358+
# libraries. Note on Windows, that key is `$PATH`, and thus not
359+
# only conflates programs with dynamic libraries, but also often
360+
# contains spaces which confuse make.
361+
# * `LD_LIBRARY_PATH_ENV_HOSTDIR`: the entry to add to lookup path for the host
362+
# * `LD_LIBRARY_PATH_ENV_TARGETDIR`: the entry to add to lookup path for target
363+
#
364+
# Below that, HOST_RPATH_VAR and TARGET_RPATH_VAR are defined in terms of the
365+
# above settings.
366+
#
354367
define SREQ_CMDS
355368

356369
ifeq ($$(OSTYPE_$(3)),apple-darwin)
357-
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
358-
DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
370+
LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := DYLD_LIBRARY_PATH
371+
else
372+
ifeq ($$(CFG_WINDOWSY_$(2)),1)
373+
LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := PATH
359374
else
360-
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
361-
LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(HLIB$(1)_H_$(3))"
375+
LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3) := LD_LIBRARY_PATH
376+
endif
362377
endif
363378

379+
LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3) := \
380+
$$(CURDIR)/$$(HLIB$(1)_H_$(3))
381+
LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3) := \
382+
$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))
383+
384+
HOST_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
385+
$$(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))
386+
TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
387+
$$(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))
388+
389+
RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(HOST_RPATH_VAR$(1)_T_$(2)_H_$(3))
390+
364391
# Pass --cfg stage0 only for the build->host part of stage0;
365392
# if you're building a cross config, the host->* parts are
366393
# effectively stage1, since it uses the just-built stage0.
@@ -376,13 +403,7 @@ ifeq ($(1),0)
376403
ifneq ($(strip $(CFG_BUILD)),$(strip $(3)))
377404
CFGFLAG$(1)_T_$(2)_H_$(3) = stage1
378405

379-
ifeq ($$(OSTYPE_$(3)),apple-darwin)
380-
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
381-
DYLD_LIBRARY_PATH="$$$$DYLD_LIBRARY_PATH:$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))"
382-
else
383-
RPATH_VAR$(1)_T_$(2)_H_$(3) := \
384-
LD_LIBRARY_PATH="$$$$LD_LIBRARY_PATH:$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))"
385-
endif
406+
RPATH_VAR$(1)_T_$(2)_H_$(3) := $$(TARGET_RPATH_VAR$(1)_T_$(2)_H_$(3))
386407
endif
387408
endif
388409

mk/tests.mk

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,8 +793,27 @@ else
793793
CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4) = $$(RSINPUTS_$(4))
794794
endif
795795

796+
# (Issues #13732, #13983, #14000) The doc for the regex crate includes
797+
# uses of the `regex!` macro from the regex_macros crate. There is
798+
# normally a dependence injected that makes the target's regex depend
799+
# upon the host's regex_macros (see #13845), but that dependency
800+
# injection is currently skipped for stage1 as a special case.
801+
#
802+
# Therefore, as a further special case, this conditional skips
803+
# attempting to run the doc tests for the regex crate atop stage1,
804+
# (since there is no regex_macros crate for the stage1 rustc to load).
805+
#
806+
# (Another approach for solving this would be to inject the desired
807+
# dependence for stage1 as well, by setting things up to generate a
808+
# regex_macros crate that was compatible with the stage1 rustc and
809+
# thus re-enable our ability to run this test.)
810+
ifeq (stage$(1)-crate-$(4),stage1-crate-regex)
811+
check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec:
812+
@$$(call E, skipping doc-crate-$(4) as it uses macros and cannot run at stage$(1))
813+
else
796814
check-stage$(1)-T-$(2)-H-$(3)-doc-crate-$(4)-exec: \
797815
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4))
816+
endif
798817

799818
ifeq ($(2),$$(CFG_BUILD))
800819
$$(call TEST_OK_FILE,$(1),$(2),$(3),doc-crate-$(4)): $$(CRATEDOCTESTDEP_$(1)_$(2)_$(3)_$(4))
@@ -951,7 +970,10 @@ $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
951970
"$$(CC_$(3)) $$(CFG_GCCISH_CFLAGS_$(3))" \
952971
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
953972
"$$(TESTNAME)" \
954-
"$$(RPATH_VAR$(1)_T_$(2)_H_$(3))"
973+
$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
974+
"$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
975+
"$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
976+
$(1)
955977
@touch $$@
956978
else
957979
# FIXME #11094 - The above rule doesn't work right for multiple targets

src/etc/maketest.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,21 @@ def putenv(name, value):
3030
value = normalize_path(value)
3131
os.putenv(name, value)
3232

33+
def convert_path_spec(name, value):
34+
if os.name == 'nt' and name != 'PATH':
35+
value = ":".join(normalize_path(v) for v in value.split(";"))
36+
return value
3337

3438
make = sys.argv[2]
3539
putenv('RUSTC', os.path.abspath(sys.argv[3]))
3640
putenv('TMPDIR', os.path.abspath(sys.argv[4]))
3741
putenv('CC', sys.argv[5])
3842
putenv('RUSTDOC', os.path.abspath(sys.argv[6]))
3943
filt = sys.argv[7]
40-
ldpath = sys.argv[8]
41-
if ldpath != '':
42-
name = ldpath.split('=')[0]
43-
value = ldpath.split('=')[1]
44-
if os.name == 'nt' and name != 'PATH':
45-
value = ":".join(normalize_path(v) for v in value.split(";"))
46-
os.putenv(name, value)
44+
putenv('LD_LIB_PATH_ENVVAR', sys.argv[8]);
45+
putenv('HOST_RPATH_DIR', os.path.abspath(sys.argv[9]));
46+
putenv('TARGET_RPATH_DIR', os.path.abspath(sys.argv[10]));
47+
putenv('RUST_BUILD_STAGE', sys.argv[11])
4748

4849
if not filt in sys.argv[1]:
4950
sys.exit(0)
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
-include ../tools.mk
22

3+
HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
4+
# This overrides the LD_LIBRARY_PATH for RUN
5+
TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
6+
37
all:
48
$(RUSTC) lib.rs
59
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
6-
$(CC) main.c -o $(call RUN,main) -lboot
10+
$(CC) main.c -o $(call RUN_BINFILE,main) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -lboot
711
$(call RUN,main)
8-
rm $(call DYLIB,boot)
12+
$(call REMOVE_DYLIBS,boot)
913
$(call FAIL,main)
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
-include ../tools.mk
22

3+
HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
4+
# This overrides the LD_LIBRARY_PATH for RUN
5+
TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
6+
37
all:
48
$(RUSTC) lib.rs
59
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
6-
$(CC) main.c -o $(call RUN,main) -lboot
10+
$(CC) main.c -o $(call RUN_BINFILE,main) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -lboot
711
$(call RUN,main)
8-
rm $(call DYLIB,boot)
12+
$(call REMOVE_DYLIBS,boot)
913
$(call FAIL,main)

src/test/run-make/c-dynamic-dylib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ all: $(call DYLIB,cfoo)
99
$(RUSTC) foo.rs
1010
$(RUSTC) bar.rs
1111
$(call RUN,bar)
12-
rm $(TMPDIR)/$(call DYLIB_GLOB,cfoo)
12+
$(call REMOVE_DYLIBS,cfoo)
1313
$(call FAIL,bar)
1414
endif
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
-include ../tools.mk
22

3+
# This overrides the LD_LIBRARY_PATH for RUN
4+
TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
5+
36
# This hits an assertion in the linker on older versions of osx apparently
47
ifeq ($(shell uname),Darwin)
58
all:
@@ -8,7 +11,7 @@ else
811
all: $(call DYLIB,cfoo)
912
$(RUSTC) foo.rs
1013
$(RUSTC) bar.rs
11-
LD_LIBRARY_PATH=$(TMPDIR) $(call RUN,bar)
12-
rm $(TMPDIR)/$(call DYLIB_GLOB,cfoo)
14+
$(call RUN,bar)
15+
$(call REMOVE_DYLIBS,cfoo)
1316
$(call FAIL,bar)
1417
endif
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
-include ../tools.mk
22

3+
HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
4+
35
all:
46
$(RUSTC) foo.rs
57
ln -s $(call DYLIB,foo-*) $(call DYLIB,foo)
6-
$(CC) bar.c -lfoo -o $(call RUN,bar) -Wl,-rpath,$(TMPDIR)
8+
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -Wl,-rpath,$(TMPDIR)
79
$(call RUN,bar)
8-
rm $(call DYLIB,foo)
10+
$(call REMOVE_DYLIBS,foo)
911
$(call FAIL,bar)

src/test/run-make/c-link-to-rust-staticlib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ifneq ($(shell uname),FreeBSD)
1111
all:
1212
$(RUSTC) foo.rs
1313
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
14-
$(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++
14+
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRAFLAGS) -lstdc++
1515
$(call RUN,bar)
1616
rm $(call STATICLIB,foo*)
1717
$(call RUN,bar)

src/test/run-make/c-static-dylib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ all: $(call STATICLIB,cfoo)
55
$(RUSTC) bar.rs
66
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
77
$(call RUN,bar)
8-
rm $(TMPDIR)/$(call DYLIB_GLOB,foo)
8+
$(call REMOVE_DYLIBS,foo)
99
$(call FAIL,bar)

src/test/run-make/c-static-rlib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
all: $(call STATICLIB,cfoo)
44
$(RUSTC) foo.rs
55
$(RUSTC) bar.rs
6-
rm $(TMPDIR)/$(call RLIB_GLOB,foo)
6+
$(call REMOVE_RLIBS,foo)
77
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
88
$(call RUN,bar)

src/test/run-make/dylib-chain/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ all:
66
$(RUSTC) m3.rs
77
$(RUSTC) m4.rs
88
$(call RUN,m4)
9-
rm $(TMPDIR)/$(call DYLIB_GLOB,m1)
10-
rm $(TMPDIR)/$(call DYLIB_GLOB,m2)
11-
rm $(TMPDIR)/$(call DYLIB_GLOB,m3)
9+
$(call REMOVE_DYLIBS,m1)
10+
$(call REMOVE_DYLIBS,m2)
11+
$(call REMOVE_DYLIBS,m3)
1212
$(call FAIL,m4)

src/test/run-make/extern-fn-reachable/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
-include ../tools.mk
22

3+
# This overrides the LD_LIBRARY_PATH for RUN
4+
TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
5+
36
all:
47
$(RUSTC) dylib.rs -o $(TMPDIR)/libdylib.so
58
$(RUSTC) main.rs

src/test/run-make/lto-smoke-c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ CC := $(CC:-g=)
1919
all:
2020
$(RUSTC) foo.rs -Z lto
2121
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
22-
$(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++
22+
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRAFLAGS) -lstdc++
2323
$(call RUN,bar)
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
-include ../tools.mk
22

3-
all:
3+
# This test attempts to use syntax extensions, which are known to be
4+
# incompatible with stage1 at the moment.
5+
6+
ifeq ($(RUST_BUILD_STAGE),1)
7+
DOTEST=
8+
else
9+
DOTEST=dotest
10+
endif
11+
12+
all: $(DOTEST)
13+
14+
dotest:
15+
env
416
$(RUSTC) lib.rs
517
$(RUSTC) main.rs -Z lto
618
$(call RUN,main)

src/test/run-make/missing-crate-dependency/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
all:
44
$(RUSTC) --crate-type=rlib crateA.rs
55
$(RUSTC) --crate-type=rlib crateB.rs
6-
rm $(TMPDIR)/$(call RLIB_GLOB,crateA)
6+
$(call REMOVE_RLIBS,crateA)
77
# Ensure crateC fails to compile since dependency crateA is missing
88
$(RUSTC) crateC.rs 2>&1 | \
99
grep "error: can't find crate for \`crateA\` which \`crateB\` depends on"

src/test/run-make/mixing-libs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ all:
55
$(RUSTC) dylib.rs
66
$(RUSTC) rlib.rs --crate-type=dylib
77
$(RUSTC) dylib.rs
8-
rm $(call DYLIB,rlib-*)
8+
$(call REMOVE_DYLIBS,rlib)
99
$(RUSTC) prog.rs && exit 1 || exit 0

src/test/run-make/obey-crate-type-flag/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# fail if an rlib was built
88
all:
99
$(RUSTC) test.rs
10-
rm $(TMPDIR)/$(call RLIB_GLOB,test)
11-
rm $(TMPDIR)/$(call DYLIB_GLOB,test)
10+
$(call REMOVE_RLIBS,test)
11+
$(call REMOVE_DYLIBS,test)
1212
$(RUSTC) --crate-type dylib test.rs
13-
rm $(TMPDIR)/$(call RLIB_GLOB,test) && exit 1 || exit 0
13+
$(call REMOVE_RLIBS,test) && exit 1 || exit 0

src/test/run-make/output-type-permutations/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
all:
44
$(RUSTC) foo.rs --crate-type=rlib,dylib,staticlib
5-
rm $(TMPDIR)/$(call RLIB_GLOB,bar)
6-
rm $(TMPDIR)/$(call DYLIB_GLOB,bar)
5+
$(call REMOVE_RLIBS,bar)
6+
$(call REMOVE_DYLIBS,bar)
77
rm $(TMPDIR)/$(call STATICLIB_GLOB,bar)
88
$(RUSTC) foo.rs --crate-type=bin
99
rm $(TMPDIR)/$(call BIN,bar)
@@ -41,4 +41,4 @@ all:
4141
cmp $(TMPDIR)/foo.bc $(TMPDIR)/bar.bc
4242
rm $(TMPDIR)/bar.bc
4343
rm $(TMPDIR)/foo.bc
44-
rm $(TMPDIR)/$(call RLIB_GLOB,bar)
44+
$(call REMOVE_RLIBS,bar)

src/test/run-make/prefer-dylib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ all:
55
$(RUSTC) foo.rs -C prefer-dynamic
66
$(call RUN,foo)
77
rm $(TMPDIR)/*bar*
8-
$(call FAILS,foo)
8+
$(call FAIL,foo)

src/test/run-make/tools.mk

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ export DYLD_LIBRARY_PATH:=$(TMPDIR):$(DYLD_LIBRARY_PATH)
44
RUSTC := $(RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR)
55
CC := $(CC) -L $(TMPDIR)
66

7-
RUN = $(TMPDIR)/$(1)
8-
FAILS = $(TMPDIR)/$(1) && exit 1 || exit 0
7+
# These deliberately use `=` and not `:=` so that client makefiles can
8+
# augment HOST_RPATH_DIR / TARGET_RPATH_DIR.
9+
HOST_RPATH_ENV = \
10+
$(LD_LIB_PATH_ENVVAR)=$$$(LD_LIB_PATH_ENVVAR):$(HOST_RPATH_DIR)
11+
TARGET_RPATH_ENV = \
12+
$(LD_LIB_PATH_ENVVAR)=$$$(LD_LIB_PATH_ENVVAR):$(TARGET_RPATH_DIR)
13+
14+
# This is the name of the binary we will generate and run; use this
15+
# e.g. for `$(CC) -o $(RUN_BINFILE)`.
16+
RUN_BINFILE = $(TMPDIR)/$(1)
17+
18+
# RUN and FAIL are basic way we will invoke the generated binary. On
19+
# non-windows platforms, they set the LD_LIBRARY_PATH environment
20+
# variable before running the binary.
921

1022
RLIB_GLOB = lib$(1)*.rlib
1123
STATICLIB = $(TMPDIR)/lib$(1).a
@@ -18,20 +30,32 @@ IS_WINDOWS=1
1830
endif
1931

2032
ifeq ($(UNAME),Darwin)
33+
RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
34+
FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
2135
DYLIB_GLOB = lib$(1)*.dylib
2236
DYLIB = $(TMPDIR)/lib$(1).dylib
37+
RPATH_LINK_SEARCH =
2338
else
2439
ifdef IS_WINDOWS
40+
RUN = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE)
41+
FAIL = PATH="$(PATH):$(TARGET_RPATH_DIR)" $(RUN_BINFILE) && exit 1 || exit 0
2542
DYLIB_GLOB = $(1)*.dll
2643
DYLIB = $(TMPDIR)/$(1).dll
2744
BIN = $(1).exe
28-
export PATH := $(PATH):$(LD_LIBRARY_PATH)
45+
RPATH_LINK_SEARCH =
46+
RUSTC := PATH="$(PATH):$(LD_LIBRARY_PATH)" $(RUSTC)
2947
else
48+
RUN = $(TARGET_RPATH_ENV) $(RUN_BINFILE)
49+
FAIL = $(TARGET_RPATH_ENV) $(RUN_BINFILE) && exit 1 || exit 0
3050
DYLIB_GLOB = lib$(1)*.so
3151
DYLIB = $(TMPDIR)/lib$(1).so
52+
RPATH_LINK_SEARCH = -Wl,-rpath-link=$(1)
3253
endif
3354
endif
3455

56+
REMOVE_DYLIBS = rm $(TMPDIR)/$(call DYLIB_GLOB,$(1))
57+
REMOVE_RLIBS = rm $(TMPDIR)/$(call RLIB_GLOB,$(1))
58+
3559
%.a: %.o
3660
ar crus $@ $<
3761
%.dylib: %.o

0 commit comments

Comments
 (0)