File tree Expand file tree Collapse file tree 4 files changed +29
-3
lines changed Expand file tree Collapse file tree 4 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ fn main() {
7
7
fs:: remove_dir_all ( & out) . unwrap ( ) ;
8
8
fs:: create_dir ( & out) . unwrap ( ) ;
9
9
10
+ let target = std:: env:: var ( "TARGET" ) . unwrap ( ) ;
11
+
12
+ if target. ends_with ( "msvc" ) {
13
+ env:: set_var ( "CL" , "-Zl" ) ; // drop linker directives
14
+ }
15
+
10
16
cc:: Build :: new ( )
11
17
. file ( "src/foo.c" )
12
18
. flag_if_supported ( "-Wall" )
@@ -21,7 +27,6 @@ fn main() {
21
27
. include ( "src/include" )
22
28
. compile ( "bar" ) ;
23
29
24
- let target = std:: env:: var ( "TARGET" ) . unwrap ( ) ;
25
30
let file = target. split ( "-" ) . next ( ) . unwrap ( ) ;
26
31
let file = format ! (
27
32
"src/{}.{}" ,
@@ -55,6 +60,14 @@ fn main() {
55
60
56
61
if target. contains ( "windows" ) {
57
62
cc:: Build :: new ( ) . file ( "src/windows.c" ) . compile ( "windows" ) ;
63
+ if target. ends_with ( "msvc" ) && which:: which ( "clang" ) . is_ok ( ) {
64
+ cc:: Build :: new ( )
65
+ . compiler ( "clang" )
66
+ . define ( "_CRT_NONSTDC_NO_WARNINGS" , None )
67
+ . file ( "src/msvcrt.c" )
68
+ . compile ( "nonstdcrt" ) ;
69
+ println ! ( "cargo:rustc-cfg=feature=\" msvcrt\" " ) ;
70
+ }
58
71
}
59
72
60
73
// Test that the `windows_registry` module will set PATH by looking for
Original file line number Diff line number Diff line change @@ -2,13 +2,12 @@ all: $(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.exe
2
2
3
3
$(OUT_DIR)/msvc.lib: $(OUT_DIR)/msvc.o
4
4
lib -nologo -out:$(OUT_DIR)/msvc.lib $(OUT_DIR)/msvc.o
5
- rc -h
6
5
7
6
$(OUT_DIR)/msvc.o: src/msvc.c
8
7
$(CC) -nologo -c -Fo:$@ src/msvc.c -MD
9
8
10
9
$(OUT_DIR)/msvc.exe: $(OUT_DIR)/msvc2.o
11
- $(CC) -nologo -Fo:$@ $(OUT_DIR)/msvc2.o
10
+ $(CC) -nologo -Fo:$@ $(OUT_DIR)/msvc2.o /link msvcrt.lib
12
11
13
12
$(OUT_DIR)/msvc2.o: src/msvc.c
14
13
$(CC) -nologo -c -Fo:$@ src/msvc.c -DMAIN -MD
Original file line number Diff line number Diff line change
1
+ #include <stdlib.h>
2
+ #include <string.h>
3
+ void msvcrt () { free (strdup ("" )); }
Original file line number Diff line number Diff line change @@ -50,6 +50,17 @@ fn msvc_here() {
50
50
}
51
51
}
52
52
53
+ #[ test]
54
+ #[ cfg( feature = "msvcrt" ) ]
55
+ fn msvcrt_here ( ) {
56
+ extern "C" {
57
+ fn msvcrt ( ) ;
58
+ }
59
+ unsafe {
60
+ msvcrt ( ) ;
61
+ }
62
+ }
63
+
53
64
#[ test]
54
65
fn opt_linkage ( ) {
55
66
unsafe {
You can’t perform that action at this time.
0 commit comments