Skip to content

Commit ac3225d

Browse files
authored
Fix Makefile.Windows (#211)
Adapted from #197 by gvanem. I squashed the commits from that PR, and added my own on top. We need to remove the link.exe provided by MSYS and Git to make sure they don't interfere with MSVC's link.exe. Also, add a #define for strncasecmp, which is not available on Windows.
1 parent 8927058 commit ac3225d

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

.github/workflows/test.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ jobs:
4343
- uses: actions/checkout@v2
4444
with:
4545
persist-credentials: false
46+
- name: Setup PATH for CL.EXE
47+
uses: ilammy/msvc-dev-cmd@v1
48+
# Remove link.exe from non-MSVC packages that interferes with MSVC link
49+
- run: rm "C:\Program Files\Git\usr\bin\link.exe"
50+
- run: rm "C:\msys64\usr\bin\link.exe"
4651
- run: make -f Makefile.Windows
4752

4853
ensure-header-updated:

Makefile.Windows

+40-25
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,65 @@
11
#
2-
# Create 'crustls.lib' and 'src/crustls.h' for Windows using
3-
# 'cl' or 'clang-cl'.
2+
# A GNU Makefile that creates:
3+
# target/release/rustls_ffi.lib -- using 'cargo build'
4+
# target/client.exe
5+
# target/server.exe
6+
#
7+
# for Windows using 'cl' or 'clang-cl'.
48
#
59
export CL=
610

7-
CRUSTLS_LIB = target/release/crustls.lib
11+
VPATH = tests
12+
13+
RUSTLS_LIB = target/release/rustls_ffi.lib
14+
15+
USE_CLANG_CL ?= 0
816

9-
USE_CLANG_CL ?= 1
17+
green_msg = @echo -e "\e[1;32m$(strip $(1))\e[0m"
1018

11-
CFLAGS = -nologo -MD -Zi -W3 -O2 -I. -Dssize_t=int -D_CRT_SECURE_NO_WARNINGS
12-
LDFLAGS = -nologo -incremental:no
13-
CARGOFLAGS = --color never --release
19+
CFLAGS = -nologo -MD -Zi -W3 -O2 \
20+
-I./src \
21+
-D_WIN32_WINNT=0x601 \
22+
-Dssize_t=int \
23+
-D_CRT_SECURE_NO_WARNINGS \
24+
-D_CRT_NONSTDC_NO_WARNINGS
25+
26+
LDFLAGS = -nologo -incremental:no -debug
1427

1528
ifeq ($(USE_CLANG_CL),1)
1629
CC = clang-cl
17-
CFLAGS += -ferror-limit=5
30+
CFLAGS += -ferror-limit=5 -Wno-pointer-sign
1831
else
1932
CC = cl
2033
endif
2134

22-
all: crustls.h $(CRUSTLS_LIB) # crustls-demo.exe
35+
all: $(RUSTLS_LIB) target/client.exe target/server.exe
2336

2437
test: all
25-
crustls-demo.exe httpbin.org /headers
26-
27-
crustls.h: src/lib.rs
28-
cbindgen --lang C --output $@
29-
@echo
38+
$(call green_msg, getting 'https://httpbin.org/headers' ...)
39+
target/client.exe httpbin.org 443 /headers
40+
$(call green_msg, Running 'cargo test')
41+
cargo test
3042

31-
#
32-
# Currently impossible on Windows since it used epoll API.
33-
#
34-
crustls-demo.exe: main.obj $(CRUSTLS_LIB)
35-
link $(LDFLAGS) -out:$@ $^
36-
@echo
37-
38-
$(CRUSTLS_LIB): src/lib.rs Cargo.toml
39-
cargo build $(CARGOFLAGS)
43+
$(RUSTLS_LIB): src/lib.rs Cargo.toml
44+
$(call green_msg, Building '$@')
45+
cargo build --release
4046
@echo
4147

42-
main.obj: src/main.c crustls.h
48+
%.obj: tests/%.c
4349
$(CC) -Fo$@ -c $< $(CFLAGS)
4450
@echo
4551

52+
target/%.exe: common.obj %.obj $(RUSTLS_LIB)
53+
$(call link_EXE, $@, $^ advapi32.lib userenv.lib ws2_32.lib)
54+
4655
clean:
47-
rm -f *.obj target/.rustc_info.json $(CRUSTLS_LIB) crustls.h vc1*.pdb
56+
rm -f *.obj target/.rustc_info.json $(RUSTLS_LIB) vc1*.pdb
4857
rm -fR target/*
4958
rmdir target
5059

60+
define link_EXE
61+
$(call green_msg, Linking $(1))
62+
link $(LDFLAGS) -out:$(strip $(1)) $(2)
63+
@echo
64+
endef
65+

tests/common.c

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <ws2tcpip.h> /* gai_strerror() */
66
#include <io.h> /* write() */
77
#include <fcntl.h> /* O_BINARY */
8+
#define strncasecmp _strnicmp
89
#else
910
#include <sys/socket.h>
1011
#include <sys/uio.h>

0 commit comments

Comments
 (0)