diff options
author | Jacob Hoffman-Andrews <github@hoffman-andrews.com> | 2021-11-11 17:29:50 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-11 17:29:50 -0800 |
commit | ac3225d0d0e6ca1ce24c5eaecf4bc0aecbc47f14 (patch) | |
tree | 9da0f15eabb877c05890d8b8c0eddd0501c8cf8c | |
parent | 892705816ccdab1a90621f38e6b96f94776e1cfe (diff) |
Fix Makefile.Windows (#211)v0.8.1
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.
-rw-r--r-- | .github/workflows/test.yaml | 5 | ||||
-rw-r--r-- | Makefile.Windows | 65 | ||||
-rw-r--r-- | tests/common.c | 1 |
3 files changed, 46 insertions, 25 deletions
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2aa5f78..b24faa7 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 1fd5f7e..b50cba1 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 52568e9..75b8d9d 100644 --- a/tests/common.c +++ b/tests/common.c @@ -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> |