Skip to content

Commit

Permalink
Fix Makefile.Windows (#211)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsha authored Nov 12, 2021
1 parent 8927058 commit ac3225d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
- uses: actions/checkout@v2
with:
persist-credentials: false
- name: Setup PATH for CL.EXE
uses: ilammy/msvc-dev-cmd@v1
# Remove link.exe from non-MSVC packages that interferes with MSVC link
- run: rm "C:\Program Files\Git\usr\bin\link.exe"
- run: rm "C:\msys64\usr\bin\link.exe"
- run: make -f Makefile.Windows

ensure-header-updated:
Expand Down
65 changes: 40 additions & 25 deletions Makefile.Windows
Original file line number Diff line number Diff line change
@@ -1,50 +1,65 @@
#
# Create 'crustls.lib' and 'src/crustls.h' for Windows using
# 'cl' or 'clang-cl'.
# A GNU Makefile that creates:
# target/release/rustls_ffi.lib -- using 'cargo build'
# target/client.exe
# target/server.exe
#
# for Windows using 'cl' or 'clang-cl'.
#
export CL=

CRUSTLS_LIB = target/release/crustls.lib
VPATH = tests

RUSTLS_LIB = target/release/rustls_ffi.lib

USE_CLANG_CL ?= 0

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

CFLAGS = -nologo -MD -Zi -W3 -O2 -I. -Dssize_t=int -D_CRT_SECURE_NO_WARNINGS
LDFLAGS = -nologo -incremental:no
CARGOFLAGS = --color never --release
CFLAGS = -nologo -MD -Zi -W3 -O2 \
-I./src \
-D_WIN32_WINNT=0x601 \
-Dssize_t=int \
-D_CRT_SECURE_NO_WARNINGS \
-D_CRT_NONSTDC_NO_WARNINGS

LDFLAGS = -nologo -incremental:no -debug

ifeq ($(USE_CLANG_CL),1)
CC = clang-cl
CFLAGS += -ferror-limit=5
CFLAGS += -ferror-limit=5 -Wno-pointer-sign
else
CC = cl
endif

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

test: all
crustls-demo.exe httpbin.org /headers

crustls.h: src/lib.rs
cbindgen --lang C --output $@
@echo
$(call green_msg, getting 'https://httpbin.org/headers' ...)

This comment has been minimized.

Copy link
@gvanem

gvanem Nov 12, 2021

Contributor

There could be a export NO_CHECK_CERTIFICATE=1 ; \ here.

target/client.exe httpbin.org 443 /headers
$(call green_msg, Running 'cargo test')
cargo test

#
# Currently impossible on Windows since it used epoll API.
#
crustls-demo.exe: main.obj $(CRUSTLS_LIB)
link $(LDFLAGS) -out:$@ $^
@echo

$(CRUSTLS_LIB): src/lib.rs Cargo.toml
cargo build $(CARGOFLAGS)
$(RUSTLS_LIB): src/lib.rs Cargo.toml
$(call green_msg, Building '$@')
cargo build --release
@echo

main.obj: src/main.c crustls.h
%.obj: tests/%.c
$(CC) -Fo$@ -c $< $(CFLAGS)
@echo

target/%.exe: common.obj %.obj $(RUSTLS_LIB)
$(call link_EXE, $@, $^ advapi32.lib userenv.lib ws2_32.lib)

clean:
rm -f *.obj target/.rustc_info.json $(CRUSTLS_LIB) crustls.h vc1*.pdb
rm -f *.obj target/.rustc_info.json $(RUSTLS_LIB) vc1*.pdb
rm -fR target/*
rmdir target

define link_EXE
$(call green_msg, Linking $(1))
link $(LDFLAGS) -out:$(strip $(1)) $(2)
@echo
endef

1 change: 1 addition & 0 deletions tests/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ws2tcpip.h> /* gai_strerror() */
#include <io.h> /* write() */
#include <fcntl.h> /* O_BINARY */
#define strncasecmp _strnicmp
#else
#include <sys/socket.h>
#include <sys/uio.h>
Expand Down

0 comments on commit ac3225d

Please sign in to comment.