Skip to content

Commit 0675dff

Browse files
committed
rmake: Get all tests passing on MSVC
1 parent 3887ca2 commit 0675dff

File tree

34 files changed

+155
-78
lines changed

34 files changed

+155
-78
lines changed

mk/tests.mk

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,10 @@ $$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
10461046
$$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
10471047
@touch $$@
10481048

1049+
$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
1050+
export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(3)))
1051+
$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
1052+
export LIB := $$(CFG_MSVC_LIB_PATH_$$(HOST_$(3)))
10491053
$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
10501054
$(S)src/test/run-make/%/Makefile \
10511055
$$(CSREQ$(1)_T_$(2)_H_$(3))
@@ -1056,15 +1060,16 @@ $(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
10561060
$$(MAKE) \
10571061
$$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
10581062
$(3)/test/run-make/$$* \
1059-
$$(CC_$(3)) \
1063+
'$$(CC_$(3))' \
10601064
"$$(CFG_GCCISH_CFLAGS_$(3))" \
10611065
$$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
10621066
"$$(TESTNAME)" \
10631067
$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3)) \
10641068
"$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3))" \
10651069
"$$(LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3))" \
10661070
$(1) \
1067-
$$(S)
1071+
$$(S) \
1072+
$(3)
10681073
@touch -r [email protected]_time $$@ && rm [email protected]_time
10691074
else
10701075
# FIXME #11094 - The above rule doesn't work right for multiple targets

src/etc/maketest.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import sys
1414

15+
target_triple = sys.argv[14]
1516

1617
def normalize_path(v):
1718
"""msys1/msys2 automatically converts `/abs/path1:/abs/path2` into
@@ -22,8 +23,11 @@ def normalize_path(v):
2223
windows paths so it is really error-prone. revert it for peace."""
2324
v = v.replace('\\', '/')
2425
# c:/path -> /c/path
25-
if ':/' in v:
26-
v = '/' + v.replace(':/', '/')
26+
# "c:/path" -> "/c/path"
27+
start = v.find(':/')
28+
while start != -1:
29+
v = v[:start - 1] + '/' + v[start - 1:start] + v[start + 1:]
30+
start = v.find(':/')
2731
return v
2832

2933

@@ -50,6 +54,10 @@ def convert_path_spec(name, value):
5054
putenv('RUST_BUILD_STAGE', sys.argv[12])
5155
putenv('S', os.path.abspath(sys.argv[13]))
5256
putenv('PYTHON', sys.executable)
57+
os.putenv('TARGET', target_triple)
58+
59+
if 'msvc' in target_triple:
60+
os.putenv('IS_MSVC', '1')
5361

5462
if filt not in sys.argv[1]:
5563
sys.exit(0)

src/test/run-make/archive-duplicate-names/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
all:
44
mkdir $(TMPDIR)/a
55
mkdir $(TMPDIR)/b
6-
$(CC) -c -o $(TMPDIR)/a/foo.o foo.c
7-
$(CC) -c -o $(TMPDIR)/b/foo.o bar.c
6+
$(call COMPILE_OBJ,$(TMPDIR)/a/foo.o,foo.c)
7+
$(call COMPILE_OBJ,$(TMPDIR)/b/foo.o,bar.c)
88
ar crus $(TMPDIR)/libfoo.a $(TMPDIR)/a/foo.o $(TMPDIR)/b/foo.o
99
$(RUSTC) foo.rs
1010
$(RUSTC) bar.rs
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
// ignore-license
2+
#ifdef _WIN32
3+
__declspec(dllexport)
4+
#endif
25
int foo() { return 0; }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
// ignore-license
2+
3+
#ifdef _WIN32
4+
__declspec(dllexport)
5+
#endif
26
int foo() { return 0; }
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
-include ../tools.mk
22

3-
HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
4-
5-
all:
6-
$(RUSTC) foo.rs
7-
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -Wl,-rpath,$(TMPDIR) $(EXTRACFLAGS)
3+
all: $(TMPDIR)/$(call BIN,bar)
84
$(call RUN,bar)
95
$(call REMOVE_DYLIBS,foo)
106
$(call FAIL,bar)
7+
8+
ifdef IS_MSVC
9+
$(TMPDIR)/$(call BIN,bar): $(call DYLIB,foo)
10+
$(CC) bar.c $(TMPDIR)/foo.lib $(call OUT_EXE,bar)
11+
else
12+
$(TMPDIR)/$(call BIN,bar): $(call DYLIB,foo)
13+
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) -L $(TMPDIR)
14+
endif
15+
16+
$(call DYLIB,foo): foo.rs
17+
$(RUSTC) foo.rs

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

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

3-
EXTRAFLAGS := $(EXTRACFLAGS)
4-
53
# FIXME: ignore freebsd
64
ifneq ($(shell uname),FreeBSD)
75
all:
86
$(RUSTC) foo.rs
9-
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRAFLAGS) $(EXTRACXXFLAGS)
7+
cp $(TMPDIR)/libfoo.a $(call NATIVE_STATICLIB,foo2)
8+
$(CC) bar.c $(call NATIVE_STATICLIB,foo2) $(call OUT_EXE,bar) \
9+
$(EXTRACFLAGS) $(EXTRACXXFLAGS)
1010
$(call RUN,bar)
1111
rm $(call STATICLIB,foo*)
1212
$(call RUN,bar)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
-include ../tools.mk
22

3-
all: $(call STATICLIB,cfoo)
3+
all: $(call NATIVE_STATICLIB,cfoo)
44
$(RUSTC) foo.rs -C prefer-dynamic
55
$(RUSTC) bar.rs
6-
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
6+
rm $(call NATIVE_STATICLIB,cfoo)
77
$(call RUN,bar)
88
$(call REMOVE_DYLIBS,foo)
99
$(call FAIL,bar)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-include ../tools.mk
22

3-
all: $(call STATICLIB,cfoo)
3+
all: $(call NATIVE_STATICLIB,cfoo)
44
$(RUSTC) foo.rs
55
$(RUSTC) bar.rs
66
$(call REMOVE_RLIBS,foo)
7-
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
7+
rm $(call NATIVE_STATICLIB,cfoo)
88
$(call RUN,bar)

src/test/run-make/crate-name-priority/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ all:
77
rm $(TMPDIR)/$(call BIN,bar)
88
$(RUSTC) foo1.rs
99
rm $(TMPDIR)/$(call BIN,foo)
10-
$(RUSTC) foo1.rs -o $(TMPDIR)/bar1
10+
$(RUSTC) foo1.rs -o $(TMPDIR)/$(call BIN,bar1)
1111
rm $(TMPDIR)/$(call BIN,bar1)
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
-include ../tools.mk
22

3-
all:
4-
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
5-
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
6-
$(RUSTC) testcrate.rs -L $(TMPDIR)
7-
$(RUSTC) test.rs -L $(TMPDIR)
3+
all: $(call NATIVE_STATICLIB,test)
4+
$(RUSTC) testcrate.rs
5+
$(RUSTC) test.rs
86
$(call RUN,test) || exit 1
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
-include ../tools.mk
22

3-
all:
4-
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
5-
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
6-
$(RUSTC) test.rs -L $(TMPDIR)
3+
all: $(call NATIVE_STATICLIB,test)
4+
$(RUSTC) test.rs
75
$(call RUN,test) || exit 1
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
-include ../tools.mk
22

3-
all:
4-
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
5-
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
6-
$(RUSTC) test.rs -L $(TMPDIR)
3+
all: $(call NATIVE_STATICLIB,test)
4+
$(RUSTC) test.rs
75
$(call RUN,test) || exit 1

src/test/run-make/extern-fn-with-packed-struct/test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
// ignore-license
22
// Pragma needed cause of gcc bug on windows: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991
3+
4+
#ifdef _MSC_VER
5+
#pragma pack(push,1)
6+
struct Foo {
7+
char a;
8+
short b;
9+
char c;
10+
};
11+
#else
312
#pragma pack(1)
413
struct __attribute__((packed)) Foo {
514
char a;
615
short b;
716
char c;
817
};
18+
#endif
919

1020
struct Foo foo(struct Foo foo) {
1121
return foo;
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
-include ../tools.mk
22

3-
all:
4-
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
5-
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
6-
$(RUSTC) testcrate.rs -L $(TMPDIR)
7-
$(RUSTC) test.rs -L $(TMPDIR)
3+
all: $(call NATIVE_STATICLIB,test)
4+
$(RUSTC) testcrate.rs
5+
$(RUSTC) test.rs
86
$(call RUN,test) || exit 1

src/test/run-make/interdependent-c-libraries/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# correct to complete the linkage. If passed as "-lfoo -lbar", then the 'foo'
99
# library will be stripped out, and the linkage will fail.
1010

11-
all: $(call STATICLIB,foo) $(call STATICLIB,bar)
11+
all: $(call NATIVE_STATICLIB,foo) $(call NATIVE_STATICLIB,bar)
1212
$(RUSTC) foo.rs
1313
$(RUSTC) bar.rs
1414
$(RUSTC) main.rs -Z print-link-args
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-include ../tools.mk
22

3-
all: $(call STATICLIB,foo)
3+
all: $(call NATIVE_STATICLIB,foo)
44
$(RUSTC) foo.rs
55
$(RUSTC) bar.rs
66
$(call RUN,bar)

src/test/run-make/issue-14500/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ endif
1313
all:
1414
$(RUSTC) foo.rs --crate-type=rlib
1515
$(RUSTC) bar.rs --crate-type=staticlib -C lto -L. -o $(TMPDIR)/libbar.a
16-
$(CC) foo.c -lbar -o $(call RUN_BINFILE,foo) $(EXTRACFLAGS)
16+
$(CC) foo.c $(TMPDIR)/libbar.a $(EXTRACFLAGS) $(call OUT_EXE,foo)
1717
$(call RUN,foo)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-include ../tools.mk
22

3-
all: $(TMPDIR)/libfoo.a
3+
all: $(call NATIVE_STATICLIB,foo)
44
$(RUSTC) foo.rs -C extra-filename=-383hf8 -C prefer-dynamic
55
$(RUSTC) bar.rs
66
$(call RUN,bar)

src/test/run-make/issue-15460/foo.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
// ignore-license
2+
3+
#ifdef _WIN32
4+
__declspec(dllexport)
5+
#endif
26
void foo() {}

src/test/run-make/issue-15460/foo.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(linked_from)]
1112
#![crate_type = "dylib"]
1213

1314
#[link(name = "foo", kind = "static")]
15+
#[linked_from = "foo"]
1416
extern {
1517
pub fn foo();
1618
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
-include ../tools.mk
22

3-
all:
4-
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
5-
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
6-
$(RUSTC) test.rs -L $(TMPDIR)
3+
all: $(call NATIVE_STATICLIB,test)
4+
$(RUSTC) test.rs
75
$(call RUN,test) || exit 1

src/test/run-make/issue-26092/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
all:
44
$(RUSTC) -o "" blank.rs 2>&1 | \
5-
grep 'No such file or directory'
5+
grep -i 'No such file or directory'

src/test/run-make/link-path-order/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
CORRECT_DIR=$(TMPDIR)/correct
77
WRONG_DIR=$(TMPDIR)/wrong
88

9-
all: $(TMPDIR)/libcorrect.a $(TMPDIR)/libwrong.a
9+
F := $(call NATIVE_STATICLIB_FILE,foo)
10+
11+
all: $(call NATIVE_STATICLIB,correct) $(call NATIVE_STATICLIB,wrong)
1012
mkdir -p $(CORRECT_DIR) $(WRONG_DIR)
11-
mv $(TMPDIR)/libcorrect.a $(CORRECT_DIR)/libfoo.a
12-
mv $(TMPDIR)/libwrong.a $(WRONG_DIR)/libfoo.a
13+
mv $(call NATIVE_STATICLIB,correct) $(CORRECT_DIR)/$(F)
14+
mv $(call NATIVE_STATICLIB,wrong) $(WRONG_DIR)/$(F)
1315
$(RUSTC) main.rs -o $(TMPDIR)/should_succeed -L $(CORRECT_DIR) -L $(WRONG_DIR)
1416
$(call RUN,should_succeed)
1517
$(RUSTC) main.rs -o $(TMPDIR)/should_fail -L $(WRONG_DIR) -L $(CORRECT_DIR)
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
-include ../tools.mk
22

3-
all:
4-
$(CC) foo.c -c -o $(TMPDIR)/foo.o
5-
$(AR) rcs $(TMPDIR)/libfoo.a $(TMPDIR)/foo.o
6-
$(RUSTC) bar.rs -lfoo -L $(TMPDIR)
3+
all: $(call NATIVE_STATICLIB,foo)
4+
$(RUSTC) bar.rs
75
$(call RUN,bar) || exit 1

src/test/run-make/linkage-attr-on-static/bar.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#[linkage = "external"]
1515
static BAZ: i32 = 21;
1616

17+
#[link(name = "foo", kind = "static")]
1718
extern {
1819
fn what() -> i32;
1920
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ CC := $(CC:-g=)
55

66
all:
77
$(RUSTC) foo.rs -C lto
8-
$(CC) bar.c -lfoo -o $(call RUN_BINFILE,bar) $(EXTRACFLAGS) $(EXTRACXXFLAGS)
8+
$(CC) bar.c $(TMPDIR)/libfoo.a \
9+
$(call OUT_EXE,bar) \
10+
$(EXTRACFLAGS) $(EXTRACXXFLAGS)
911
$(call RUN,bar)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
-include ../tools.mk
22

3+
ifdef IS_MSVC
4+
# FIXME(#27979)
5+
all:
6+
else
37
all:
48
$(RUSTC) foo.rs
59
$(RUSTC) bar.rs
610
$(RUSTC) main.rs
711
$(call RUN,main)
12+
endif

src/test/run-make/no-duplicate-libs/bar.c

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/test/run-make/no-duplicate-libs/foo.c

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)