Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added windows patch for mime.core to rockspec #433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

goldenstein64
Copy link
Contributor

@goldenstein64 goldenstein64 commented May 30, 2024

Closes #429.

I made sure to modify the scm rockspec this time :)

I'm assuming this needs confirmation from another Windows user and testing on *nix platforms like before.

@Tieske
Copy link
Member

Tieske commented May 31, 2024

besides this change, can you also test with the commented-out line enabled again?

@goldenstein64
Copy link
Contributor Author

goldenstein64 commented May 31, 2024

@Tieske, it looks like I still get an error.

> luarocks build .\luasocket-scm-3.rockspec
luasocket scm-3 depends on lua >= 5.1 (5.4-1 provided by VM: success)
gcc -O2 -c -o src/luasocket.o -I~/ProgramFiles/Lua/5.4/include src/luasocket.c -DLUASOCKET_DEBUG -DLUASOCKET_INET_PTON -DWINVER=0x0501 -Ic:\windows\system32\include
In file included from src/luasocket.c:20:
src/inet.h:48:13: error: conflicting types for 'inet_ntop'; have 'const char *(int,  const void *, char *, socklen_t)' {aka 'const char *(int,  const void *, char *, int)'}
   48 | const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt);
      |             ^~~~~~~~~
In file included from src/wsocket.h:12,
                 from src/socket.h:18,
                 from src/inet.h:18,
                 from src/luasocket.c:20:
~\programfiles\mingw\x86_64-w64-mingw32\include\ws2tcpip.h:401:35: note: previous declaration of 'inet_ntop' with type 'const CHAR *(INT,  const void *, CHAR *, size_t)' {aka 'const char *(int,  const void *, char *, long long unsigned int)'}
  401 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~
In file included from src/luasocket.c:20:
src/inet.h:49:5: warning: 'inet_pton' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
   49 | int inet_pton(int af, const char *src, void *dst);
      |     ^~~~~~~~~

Error: Build error: Failed compiling object src/luasocket.o

@Tieske
Copy link
Member

Tieske commented Jun 6, 2024

in the generated gcc command you have -DLUASOCKET_INET_PTON, iirc this tells that it is to use a luasocket provided implementation of inet_pton, yet in your case it still seems to also include the system provided one.

Seems you have something in your system setup that still tries to include that.

@goldenstein64
Copy link
Contributor Author

goldenstein64 commented Jun 6, 2024

It looks like lines 397 and 400 of MinGW's ws2tcpip.h are associated with this.

https://sourceforge.net/p/mingw-w64/mingw-w64/ci/v11.0.1/tree/mingw-w64-headers/include/ws2tcpip.h#l400

// line 397
#define InetNtopA inet_ntop 

// line 400
WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID pAddr, LPSTR pStringBuf, size_t StringBufSize);

The #define makes this a definition of inet_ntop.

Commenting out LUASOCKET_INET_PTON from defines prevents a conflict with inet.h.

luasocket/src/inet.h

Lines 47 to 50 in 95b7efa

#ifdef LUASOCKET_INET_PTON
const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt);
int inet_pton(int af, const char *src, void *dst);
#endif

So from this conflict, I tried defining socklen_t as size_t under MinGW in wsocket.h, but socklen_t is also already defined in ws2tcpip.h at line 228.

https://sourceforge.net/p/mingw-w64/mingw-w64/ci/v11.0.1/tree/mingw-w64-headers/include/ws2tcpip.h#l228

  typedef int socklen_t;

In Win32's version of inet_ntop, the fourth arg is of type size_t, and it looks like MinGW is using mostly the same signature. Maybe this is a Windows thing?

https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_ntop

PCSTR WSAAPI inet_ntop(
  [in]  INT        Family,
  [in]  const VOID *pAddr,
  [out] PSTR       pStringBuf,
  [in]  size_t     StringBufSize
);

Searching through LuaSocket shows that there is no implementation of inet_ntop. Should the header just be redefined to use size_t instead? Would it be better to remove the header altogether? Building on Windows is successful in both cases.

Edit: That might conflict with Linux implementations, looking at man7.org's signature.

https://man7.org/linux/man-pages/man3/inet_ntop.3.html

#include <arpa/inet.h>

const char *inet_ntop(int af, const void *restrict src, char dst[restrict .size], socklen_t size);

Then again, those implementations don't have LUASOCKET_INET_PTON, only MinGW is affected by this flag. I'm not very knowledgeable about how to implement C flags, but I don't think it would be correct to specialize the behavior of a flag that isn't targeting a specific platform. So I'm leaning towards removing the inet_ntop header.

@Tieske
Copy link
Member

Tieske commented Jun 29, 2024

I cannot for the life of me reproduce this. I have tried MinGW compilers (TDM releases), just installed and tried with Msys2 based MinGW toolchains (universal crt), but to no avail.

What toolchains do you folks use? How did you install them?

@goldenstein64
Copy link
Contributor Author

goldenstein64 commented Jun 30, 2024

You can try running this script to get a reproduction of my environment, I think. This expects you already have 7-zip and LuaRocks 3.11.1 installed and in PATH. Running luarocks init in the directory helps! I tested this script using PowerShell 7.4.3.

curl https://nuwen.net/files/mingw/mingw-19.0.exe -o mingw-19.0.exe # get the nuwen distro
7z x mingw-19.0.exe -omingw-19-0                                    # extract with 7-zip
luarocks config variables.CC "$(pwd)/mingw-19-0/MinGW/bin/gcc.exe"  # set compiler and linker
luarocks config variables.LD "$(pwd)/mingw-19-0/MinGW/bin/gcc.exe"
luarocks make ./luasocket-scm-3.rockspec                            # make the SCM

For something more manual:

  1. Download mingw-19.0.exe from https://nuwen.net/mingw.html
  2. Run the executable and install it to a folder in the current directory
  3. Configure LuaRocks to use this copy of MinGW using luarocks config variables.<LD and CC> <path to gcc>
  4. Build LuaSocket with luarocks make

With LUASOCKET_INET_PTON commented out and this PR applied, you should get the output from #433 (comment)

@Tieske
Copy link
Member

Tieske commented Jun 30, 2024

How did you install LuaRocks in that case?

@goldenstein64
Copy link
Contributor Author

goldenstein64 commented Jun 30, 2024

I think I just downloaded the standalone 64-bit binary and put it in my PATH. From https://github.com/luarocks/luarocks/wiki/Download (Windows all-in-one executable (64-bit))

@alerque alerque requested a review from Tieske July 1, 2024 08:39
@Ketho
Copy link

Ketho commented Jul 21, 2024

I can confirm the patch with modules["mime.core"].libdirs = {} solved the problem.

This is before and after applying it. (using winlibs GCC)

luarocks install .\luasocket-scm-3.rockspec

x86_64-w64-mingw32-gcc -O2 -c -o src/compat.o -IE:/ReadyDev/lua-5.4.2_Win64_bin/include src/compat.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -Ic:\windows\system32\include
x86_64-w64-mingw32-gcc  -shared -o C:\Users\ketho\AppData\Local\Temp\luarocks_build-LuaSocket-3.1.0-1-996640\mime\core.dll src/mime.o src/compat.o -Lc:\windows\system32 E:\ReadyDev\lua-5.4.2_Win64_bin\lua54.dll -lm
E:/ReadyDev/winlibs-x86_64-posix-seh-gcc-14.1.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/ReadyDev/winlibs-x86_64-posix-seh-gcc-14.1.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x13): undefined reference to `_initialize_onexit_table'
E:/ReadyDev/winlibs-x86_64-posix-seh-gcc-14.1.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/ReadyDev/winlibs-x86_64-posix-seh-gcc-14.1.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x255): undefined reference to `_execute_onexit_table'
E:/ReadyDev/winlibs-x86_64-posix-seh-gcc-14.1.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/ReadyDev/winlibs-x86_64-posix-seh-gcc-14.1.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x485): undefined reference to `_register_onexit_function'
E:/ReadyDev/winlibs-x86_64-posix-seh-gcc-14.1.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/ReadyDev/winlibs-x86_64-posix-seh-gcc-14.1.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text+0x29): undefined reference to `__acrt_iob_func'
E:/ReadyDev/winlibs-x86_64-posix-seh-gcc-14.1.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/ReadyDev/winlibs-x86_64-posix-seh-gcc-14.1.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text+0x54): undefined reference to `__acrt_iob_func'
collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module mime\core.dll
x86_64-w64-mingw32-gcc -O2 -c -o src/compat.o -IE:/ReadyDev/lua-5.4.2_Win64_bin/include src/compat.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -Ic:\windows\system32\include
x86_64-w64-mingw32-gcc -O2 -c -o src/wsocket.o -IE:/ReadyDev/lua-5.4.2_Win64_bin/include src/wsocket.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -Ic:\windows\system32\include
x86_64-w64-mingw32-gcc  -shared -o C:\Users\ketho\AppData\Local\Temp\luarocks_build-LuaSocket-scm-3-7234727\socket\core.dll src/luasocket.o src/timeout.o src/buffer.o src/io.o src/auxiliar.o src/options.o src/inet.o src/except.o src/select.o src/tcp.o src/udp.o src/compat.o src/wsocket.o -lws2_32 E:\ReadyDev\lua-5.4.2_Win64_bin\lua54.dll -lm
luasocket scm-3 is now installed in C:\Users\ketho\AppData\Roaming\luarocks (license: MIT)

I had also just downloaded the standalone 64-bit binary and put it in my path.

@HuaNanHYC
Copy link

HuaNanHYC commented Jul 31, 2024

I still have the problem after adding :modules["mime.core"].libdirs = {},

PS D:\Lua\luasocket-master\luasocket-master> luarocks make

luasocket scm-3 depends on lua >= 5.1 (5.4-1 provided by VM: success)
x86_64-w64-mingw32-gcc -O2 -c -o src/mime.o -ID:\Lua\lua-5.4.2/include src/mime.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -Ic:\windows\system32\include
x86_64-w64-mingw32-gcc -O2 -c -o src/compat.o -ID:\Lua\lua-5.4.2/include src/compat.c -DLUASOCKET_DEBUG -DWINVER=0x0501 -Ic:\windows\system32\include
x86_64-w64-mingw32-gcc  -shared -o C:\Users\CHYHEC~1\AppData\Local\Temp\luarocks_build-LuaSocket-scm-3-2976160\mime\core.dll src/mime.o src/compat.o -Lc:\windows\system32 D:\Lua\lua-5.4.2\lua54.dll -lm
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x148): undefined reference to `_execute_onexit_table'
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x8): undefined reference to `_initialize_onexit_table'
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/dllcrt2.o:crtdll.c:(.text+0x34b): undefined reference to `_register_onexit_function'
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text+0x28): undefined reference to `__acrt_iob_func'
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text+0x51): undefined reference to `__acrt_iob_func'
collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module mime\core.dll

@HuaNanHYC
Copy link

sorry, i think i had made a mistake , i put the code in rockspec/luasocket-3.1.0-1.rockspec , just now i put them in luasocket-scm-3.rockspec , and it works
help a lot , thank you so much

x86_64-w64-mingw32-gcc  -shared -o C:\Users\CHYHEC~1\AppData\Local\Temp\luarocks_build-LuaSocket-scm-3-5612939\socket\core.dll src/luasocket.o src/timeout.o src/buffer.o src/io.o src/auxiliar.o src/options.o src/inet.o src/except.o src/select.o src/tcp.o src/udp.o src/compat.o src/wsocket.o -lws2_32 D:\Lua\lua-5.4.2\lua54.dll -lm
No existing manifest. Attempting to rebuild...
luasocket scm-3 is now installed in C:\Users\chyhechen\AppData\Roaming\luarocks (license: MIT)

@goldenstein64
Copy link
Contributor Author

goldenstein64 commented Sep 2, 2024

I made a very bad typo in this reproduction comment #433 (comment):

With LUASOCKET_INET_PTON enabled and this PR applied, you should get the output from #433 (comment)

This reproduction works with LUASOCKET_INET_PTON disabled and commented out, not enabled! Sorry about that!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

"Build error: Failed compiling module mime\core.dll" on Windows
4 participants