From ac3225d0d0e6ca1ce24c5eaecf4bc0aecbc47f14 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Thu, 11 Nov 2021 17:29:50 -0800 Subject: [PATCH] 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. --- .github/workflows/test.yaml | 5 +++ Makefile.Windows | 65 +++++++++++++++++++++++-------------- tests/common.c | 1 + 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2aa5f785..b24faa76 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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: diff --git a/Makefile.Windows b/Makefile.Windows index 1fd5f7e8..b50cba16 100644 --- a/Makefile.Windows +++ b/Makefile.Windows @@ -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' ...) + 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 + diff --git a/tests/common.c b/tests/common.c index 52568e9b..75b8d9d2 100644 --- a/tests/common.c +++ b/tests/common.c @@ -5,6 +5,7 @@ #include /* gai_strerror() */ #include /* write() */ #include /* O_BINARY */ +#define strncasecmp _strnicmp #else #include #include