[PATCH] Support cross compiling with MinGW-w64 on Debian GNU/Linux

Maxim Dounin mdounin at mdounin.ru
Wed Oct 8 14:24:41 UTC 2014


Hello!

On Sat, Oct 04, 2014 at 07:51:56PM +0900, Kouhei Sutou wrote:

> Hi,
> 
> I'm trying cross compiling nginx for Windows on Debian
> GNU/Linux. The current nginx doesn't support it.
> I created a patch to do it. With the attached patch, I can
> cross compile nginx for Windows on Debian GNU/Linux.
> Please review the attached patch.

In short: changes to ngx_wsasend_chain.c and ngx_iocp_module.c 
look fine, changes to ngx_win32_config.h look wrong.  See below 
for more comments.

[...]

> diff --git a/src/event/modules/ngx_iocp_module.c b/src/event/modules/ngx_iocp_module.c
> --- a/src/event/modules/ngx_iocp_module.c
> +++ b/src/event/modules/ngx_iocp_module.c
> @@ -242,17 +242,17 @@ ngx_int_t ngx_iocp_process_events(ngx_cy
>      ngx_event_ovlp_t  *ovlp;
>  
>      if (timer == NGX_TIMER_INFINITE) {
>          timer = INFINITE;
>      }
>  
>      ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "iocp timer: %M", timer);
>  
> -    rc = GetQueuedCompletionStatus(iocp, &bytes, (LPDWORD) &key,
> +    rc = GetQueuedCompletionStatus(iocp, &bytes, (PULONG_PTR) &key,
>                                     (LPOVERLAPPED *) &ovlp, (u_long) timer);
>  
>      if (rc == 0) {
>          err = ngx_errno;
>      } else {
>          err = 0;
>      }
>  

Looks fine, though I think it should be a separate patch.

Please see http://nginx.org/en/docs/contributing_changes.html for 
hints how to make sure you'll name will be preserved in commit 
history.

> diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h
> --- a/src/os/win32/ngx_win32_config.h
> +++ b/src/os/win32/ngx_win32_config.h
> @@ -33,18 +33,17 @@
>  
>  #include <winsock2.h>
>  #include <ws2tcpip.h>  /* ipv6 */
>  #include <mswsock.h>
>  #include <shellapi.h>
>  #include <stddef.h>    /* offsetof() */
>  
>  #ifdef __GNUC__
> -/* GCC MinGW's stdio.h includes sys/types.h */
> -#define _OFF_T_
> +#define _FILE_OFFSET_BITS 64
>  #endif
>  
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <stdarg.h>
>  #include <ctype.h>
>  #include <locale.h>
>  
> @@ -131,25 +130,31 @@ typedef int                 int32_t;
>  typedef unsigned short int  uint16_t;
>  #define ngx_libc_cdecl
>  
>  #endif
>  
>  typedef __int64             int64_t;
>  typedef unsigned __int64    uint64_t;
>  
> -#ifndef __WATCOMC__
> +#ifdef __WATCOMC__
> +/* do nothing */
> +#elif defined(__GNUC__)
> +#include <stdint.h>
> +#else
>  typedef int                 intptr_t;
>  typedef u_int               uintptr_t;
>  #endif

I think that ngx_win32_config.h part needs a bit more work.  In 
particular, "#include <stdint.h>" should be placed with other 
includes if it's needed.

> +#ifndef __GNUC__
>  /* Windows defines off_t as long, which is 32-bit */
> -typedef __int64             off_t;
> -#define _OFF_T_DEFINED
> +typedef __int64             off64_t;
> +#define _OFF64_T_DEFINED
> +#endif

Defining off64_t looks very wrong for me.  There is nothing in 
nginx which use it, and it shouldn't be defined.

Additionally, this breaks at least compilation with MSVC.

[...]

> --- a/src/os/win32/ngx_wsasend_chain.c
> +++ b/src/os/win32/ngx_wsasend_chain.c
> @@ -29,17 +29,17 @@ ngx_wsasend_chain(ngx_connection_t *c, n
>      wev = c->write;
>  
>      if (!wev->ready) {
>          return in;
>      }
>  
>      /* the maximum limit size is the maximum u_long value - the page size */
>  
> -    if (limit == 0 || limit > NGX_MAX_UINT32_VALUE - ngx_pagesize) {
> +    if (limit == 0 || limit > (off_t) (NGX_MAX_UINT32_VALUE - ngx_pagesize)) {
>          limit = NGX_MAX_UINT32_VALUE - ngx_pagesize;
>      }
>  
>      send = 0;
>  
>      /*
>       * WSABUFs must be 4-byte aligned otherwise
>       * WSASend() will return undocumented WSAEINVAL error.
> @@ -151,17 +151,17 @@ ngx_overlapped_wsasend_chain(ngx_connect
>                     "wev->complete: %d", wev->complete);
>  
>      if (!wev->complete) {
>  
>          /* post the overlapped WSASend() */
>  
>          /* the maximum limit size is the maximum u_long value - the page size */
>  
> -        if (limit == 0 || limit > NGX_MAX_UINT32_VALUE - ngx_pagesize) {
> +        if (limit == 0 || limit > (off_t) (NGX_MAX_UINT32_VALUE - ngx_pagesize)) {
>              limit = NGX_MAX_UINT32_VALUE - ngx_pagesize;
>          }
>  
>          /*
>           * WSABUFs must be 4-byte aligned otherwise
>           * WSASend() will return undocumented WSAEINVAL error.
>           */
>  

Looks fine, though should be a separate patch.  See above.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list