sparklemotion / nokogiri

Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby.
https://nokogiri.org/
MIT License
6.16k stars 903 forks source link

MSVC support #2015

Closed jmarrec closed 3 years ago

jmarrec commented 4 years ago

TODO

Describe the bug

I found the similar https://github.com/sparklemotion/nokogiri/issues/255 which is from 2010 and seemed to imply MSVC support was achieved, yet it isn't.

I realize this is rather a corner case, but it's one I am in: I have to use MSVC to compile this gem as we have a C++ application that has to be built on MSVC and one thing it does is to create a CLI based on ruby and embedded some gems.

To Reproduce

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
SET rubypath=C:\src\os-ruby\Ruby-prefix\src\Ruby-install\bin
SET PATH=%rubypath%;%PATH%
ruby -v # check if mswin
=> ruby 2.5.5p157 (2019-03-15) [x64-mswin64_140]

I created a conanfile.txt like this

[build_requires]
zlib/1.2.11
libxml2/2.9.9
libxslt/1.1.33@bincrafters/stable

[generators]
virtualbuildenv
visual_studio

Install dependencies and activate the build env

conan install .
activate_build.bat

Realized it wouldn't still find the exslt lib due to the naming of the libs, so just cp them to a new name

cd ~/.conan/data/libxslt/1.1.33/bincrafters/stable/package/9296f4d14bac4f97f90bc8dd0e7a31945380f014/lib
cp libxslt_a.lib libxslt.lib
cp libexslt_a.lib libexslt.lib

Ok, try compilation again:

bundle exec rake compile -- --use-system-libraries --with-zlib-dir=C:\Users\julien\.conan\data\zlib\1.2.11\_\_\package\3fb49604f9c2f729b85ba3115852006824e72cab --with-exslt-include=C:\Users\julien\.conan\data\libxslt\1.1.33\bincrafters\stable\package\9296f4d14bac4f97f90bc8dd0e7a31945380f014\include\libexslt --with-exslt-lib=C:\Users\julien\.conan\data\libxslt\1.1.33\bincrafters\stable\package\9296f4d14bac4f97f90bc8dd0e7a31945380f014\lib\

Output:

cd tmp/x64-mswin64_140/nokogiri/2.5.5
nmake

Microsoft (R) Program Maintenance Utility Version 14.25.28611.0
Copyright (C) Microsoft Corporation.  All rights reserved.

compiling ../../../../ext/nokogiri/html_document.c
html_document.c
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(103): warning C4005: 'AF_IPX': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(457): note: see previous definition of 'AF_IPX'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(140): warning C4005: 'AF_MAX': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(476): note: see previous definition of 'AF_MAX'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(185): warning C4005: 'SO_DONTLINGER': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(399): note: see previous definition of 'SO_DONTLINGER'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(235): error C2011: 'sockaddr': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(482): note: see declaration of 'sockaddr'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(437): error C2059: syntax error: 'constant'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(572): warning C4005: 'IN_CLASSA': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(284): note: see previous definition of 'IN_CLASSA'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(578): warning C4005: 'IN_CLASSB': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(290): note: see previous definition of 'IN_CLASSB'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(584): warning C4005: 'IN_CLASSC': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(296): note: see previous definition of 'IN_CLASSC'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(595): warning C4005: 'INADDR_ANY': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(301): note: see previous definition of 'INADDR_ANY'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(597): warning C4005: 'INADDR_BROADCAST': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(303): note: see previous definition of 'INADDR_BROADCAST'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2def.h(633): error C2011: 'sockaddr_in': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(309): note: see declaration of 'sockaddr_in'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(136): error C2011: 'fd_set': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(65): note: see declaration of 'fd_set'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(156): warning C4005: 'FD_CLR': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(94): note: see previous definition of 'FD_CLR'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(171): warning C4005: 'FD_SET': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(99): note: see previous definition of 'FD_SET'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(180): error C2011: 'timeval': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(108): note: see declaration of 'timeval'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(236): error C2011: 'hostent': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(164): note: see declaration of 'hostent'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(249): error C2011: 'netent': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(177): note: see declaration of 'netent'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(256): error C2011: 'servent': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(184): note: see declaration of 'servent'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(268): error C2011: 'protoent': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(196): note: see declaration of 'protoent'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(364): error C2011: 'WSAData': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(319): note: see declaration of 'WSAData'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(462): error C2011: 'sockproto': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(491): note: see declaration of 'sockproto'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(504): error C2011: 'linger': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(528): note: see declaration of 'linger'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(517): warning C4005: 'SOMAXCONN': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(541): note: see previous definition of 'SOMAXCONN'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(552): warning C4005: 'FD_READ': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(559): note: see previous definition of 'FD_READ'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(555): warning C4005: 'FD_WRITE': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(560): note: see previous definition of 'FD_WRITE'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(558): warning C4005: 'FD_OOB': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(561): note: see previous definition of 'FD_OOB'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(561): warning C4005: 'FD_ACCEPT': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(562): note: see previous definition of 'FD_ACCEPT'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(564): warning C4005: 'FD_CONNECT': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(563): note: see previous definition of 'FD_CONNECT'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(567): warning C4005: 'FD_CLOSE': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(564): note: see previous definition of 'FD_CLOSE'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1625): error C2375: 'accept': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(739): note: see declaration of 'accept'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1647): error C2375: 'bind': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(744): note: see declaration of 'bind'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1668): error C2375: 'closesocket': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(749): note: see declaration of 'closesocket'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1685): error C2375: 'connect': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(751): note: see declaration of 'connect'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1706): error C2375: 'ioctlsocket': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(756): note: see declaration of 'ioctlsocket'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1729): error C2375: 'getpeername': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(761): note: see declaration of 'getpeername'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1750): error C2375: 'getsockname': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(766): note: see declaration of 'getsockname'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1771): error C2375: 'getsockopt': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(771): note: see declaration of 'getsockopt'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1796): error C2375: 'htonl': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(778): note: see declaration of 'htonl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1813): error C2375: 'htons': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(780): note: see declaration of 'htons'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1831): error C2375: 'inet_addr': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(782): note: see declaration of 'inet_addr'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1849): error C2375: 'inet_ntoa': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(784): note: see declaration of 'inet_ntoa'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1949): error C2375: 'listen': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(786): note: see declaration of 'listen'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1968): error C2375: 'ntohl': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(790): note: see declaration of 'ntohl'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(1985): error C2375: 'ntohs': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(792): note: see declaration of 'ntohs'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2002): error C2375: 'recv': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(794): note: see declaration of 'recv'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2025): error C2375: 'recvfrom': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(800): note: see declaration of 'recvfrom'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2052): error C2375: 'select': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(808): note: see declaration of 'select'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2077): error C2375: 'send': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(815): note: see declaration of 'send'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2100): error C2375: 'sendto': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(821): note: see declaration of 'sendto'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2127): error C2375: 'setsockopt': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(829): note: see declaration of 'setsockopt'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2152): error C2375: 'shutdown': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(836): note: see declaration of 'shutdown'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2172): error C2375: 'socket': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(840): note: see declaration of 'socket'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2197): error C2375: 'gethostbyaddr': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(847): note: see declaration of 'gethostbyaddr'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2219): error C2375: 'gethostbyname': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(852): note: see declaration of 'gethostbyname'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2236): error C2375: 'gethostname': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(854): note: see declaration of 'gethostname'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2276): error C2375: 'getservbyport': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(858): note: see declaration of 'getservbyport'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2295): error C2375: 'getservbyname': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(862): note: see declaration of 'getservbyname'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2314): error C2375: 'getprotobynumber': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(866): note: see declaration of 'getprotobynumber'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2331): error C2375: 'getprotobyname': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(868): note: see declaration of 'getprotobyname'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2351): error C2375: 'WSAStartup': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(872): note: see declaration of 'WSAStartup'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2371): error C2375: 'WSACleanup': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(876): note: see declaration of 'WSACleanup'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2388): error C2375: 'WSASetLastError': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(878): note: see declaration of 'WSASetLastError'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2405): error C2375: 'WSAGetLastError': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(880): note: see declaration of 'WSAGetLastError'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2426): error C2375: 'WSAIsBlocking': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(882): note: see declaration of 'WSAIsBlocking'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2444): error C2375: 'WSAUnhookBlockingHook': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(884): note: see declaration of 'WSAUnhookBlockingHook'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2462): error C2375: 'WSASetBlockingHook': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(886): note: see declaration of 'WSASetBlockingHook'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2480): error C2375: 'WSACancelBlockingCall': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(888): note: see declaration of 'WSACancelBlockingCall'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2498): error C2375: 'WSAAsyncGetServByName': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(890): note: see declaration of 'WSAAsyncGetServByName'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2526): error C2375: 'WSAAsyncGetServByPort': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(898): note: see declaration of 'WSAAsyncGetServByPort'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2554): error C2375: 'WSAAsyncGetProtoByName': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(906): note: see declaration of 'WSAAsyncGetProtoByName'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2580): error C2375: 'WSAAsyncGetProtoByNumber': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(913): note: see declaration of 'WSAAsyncGetProtoByNumber'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2606): error C2375: 'WSAAsyncGetHostByName': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(920): note: see declaration of 'WSAAsyncGetHostByName'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2632): error C2375: 'WSAAsyncGetHostByAddr': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(927): note: see declaration of 'WSAAsyncGetHostByAddr'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2662): error C2375: 'WSACancelAsyncRequest': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(936): note: see declaration of 'WSACancelAsyncRequest'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock2.h(2680): error C2375: 'WSAAsyncSelect': redefinition; different linkage
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(938): note: see declaration of 'WSAAsyncSelect'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(135): warning C4005: 'IP_TOS': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(349): note: see previous definition of 'IP_TOS'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(136): warning C4005: 'IP_TTL': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(348): note: see previous definition of 'IP_TTL'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(137): warning C4005: 'IP_MULTICAST_IF': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(343): note: see previous definition of 'IP_MULTICAST_IF'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(138): warning C4005: 'IP_MULTICAST_TTL': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(344): note: see previous definition of 'IP_MULTICAST_TTL'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(139): warning C4005: 'IP_MULTICAST_LOOP': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(345): note: see previous definition of 'IP_MULTICAST_LOOP'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(140): warning C4005: 'IP_ADD_MEMBERSHIP': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(346): note: see previous definition of 'IP_ADD_MEMBERSHIP'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(141): warning C4005: 'IP_DROP_MEMBERSHIP': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(347): note: see previous definition of 'IP_DROP_MEMBERSHIP'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(142): warning C4005: 'IP_DONTFRAGMENT': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(350): note: see previous definition of 'IP_DONTFRAGMENT'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(738): error C2011: 'ip_mreq': 'struct' type redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\winsock.h(360): note: see declaration of 'ip_mreq'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(914): error C2061: syntax error: identifier 'IPPROTO'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(918): error C2059: syntax error: '}'
../../../../ext/nokogiri/html_document.c(144): error C2365: 'type': redefinition; previous definition was 'data variable'
C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared\ws2ipdef.h(916): note: see declaration of 'type'
../../../../ext/nokogiri/html_document.c(167): warning C4047: 'function': 'VALUE (__cdecl *)()' differs in levels of indirection from 'UINT8'
../../../../ext/nokogiri/html_document.c(167): warning C4024: 'rb_define_method': different types for formal and actual parameter 3
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX64\x64\cl.EXE"' : return code '0x2'
Stop.
rake aborted!
Command failed with status (2): [nmake...]

Tasks: TOP => compile => compile:x64-mswin64_140 => compile:nokogiri:x64-mswin64_140 => copy:nokogiri:x64-mswin64_140:2.5.5 => tmp/x64-mswin64_140/nokogiri/2.5.5/nokogiri.so
(See full trace by running task with --trace)

Expected behavior

Ideally Nokogiri would built out of the box on MSVC.

Environment

Windows 10 x64. Ruby compiled locally with MSVC 2019 16.5

$ ruby -v ruby 2.5.5p157 (2019-03-15) [x64-mswin64_140]

$ gem list

LOCAL GEMS

ast (2.4.0) bigdecimal (default: 1.3.4) bundle (0.0.1) bundler (2.1.4) cmath (default: 1.0.0) concourse (0.31.0) csv (default: 1.0.0) date (default: 1.0.0) docile (1.3.2) fiddle (default: 1.0.0) fileutils (default: 1.0.2) hoe (3.22.1) hoe-bundler (1.5.0) hoe-debugging (2.0.0) hoe-gemspec (1.0.0) hoe-git (1.6.0) io-console (default: 0.4.6) ipaddr (default: 1.2.0) json (default: 2.1.0) mini_portile2 (2.5.0) minitest (5.14.0) openssl (default: 2.1.2) parallel (1.19.1) parser (2.7.0.5) psych (default: 3.0.2) racc (1.4.16) rainbow (3.0.0) rake (13.0.1) rake-compiler (1.1.0) rake-compiler-dock (1.0.1) rdoc (6.2.1, default: 6.0.1) rexical (1.0.7) rexml (3.2.4) rubocop (0.80.1) ruby-progressbar (1.10.1) scanf (default: 1.0.0) simplecov (0.18.5) simplecov-html (0.12.2) sync (0.5.0) term-ansicolor (1.7.1) tins (1.24.1) unicode-display_width (1.6.1) webrick (default: 1.4.2)

jmarrec commented 4 years ago

I managed to compile on MSVC by adding macro definitions to avoid the winsocket redefinition issues.

flavorjones commented 4 years ago

(CCing @larskanis who know more about Windows than I do and may be able to help.)

Hi, @jmarrec, thanks for opening this issue. It looks like you've jumped to a solution in #2016, which is great, thank you -- but I'd like to have a conversation here to more deeply understand the problem you're trying to solve.

Your comments here, and in the PR, about jaro_winkler seems like a distraction from the core problem that I understand, which is "Does Nokogiri compile under MSVC?". Can you help me understand why you brought it up, and why it's added to the Gemfile in the PR? I'd like to consider jaro_winkler out of scope, but can't until I understand why you're mentioning it.

I don't know what conan is, or why it's brought up here. If you're compiling Nokogiri from source, it's going to assume you have a zlib library installed to link against. If there are issues compiling the vendored libxml2 or libxslt then I'd like to understand what those problems are and fix them, rather than introduce the XY problem of making conan work for you.

If that we can restate the problem without jaro_winkler or conan, I'd like to do that. If that's not possible, I'd like to understand why.

flavorjones commented 4 years ago

In the meantime, I've started the process of downloading and installing a Windows 10 virtualbox VM with VS 2019 to try to reproduce what you might be seeing. That will ... take some time.

jmarrec commented 4 years ago

@flavorjones yeah thanks for getting back to me, and I apologize is this is somewhat messy :)

I'm going to quote something I wrote in #2016 so it's all here:

This fixes the redefinition issues, but ideally the packaged (=vendored) dependencies (zlib, libxml, lixslt) would work out of the box (I am using conan to get the dependencies and passing some arguments such as --with-xxx-dir to make it work right now)

TL;DR

So to summarize:

flavorjones commented 4 years ago

@jmarrec Thanks for the additional context.

I'll note that jaro_winkler is only a development dependency, and not a runtime dependency. If you're having to build from source, you can safely remove rubocop from your Gemfile, no big deal.

If you'd like to remove the Gemfile patch from #2016, and let the PR pipeline run, it should go green and I'd be happy to merge it.

I'll update #2016 with this note as well.

MSP-Greg commented 4 years ago

@flavorjones

  1. There is an mswin Ruby master build available as an GitHub release artifact. It's easy to use in Actions, and ruby/openssl is running CI against it at https://github.com/ruby/openssl/runs/497301673

  2. extconf/mkmf is stopping right away when I try to install the gem.

Are you interested in testing with mswin in CI?

jmarrec commented 4 years ago

Added a TODO to the OP above with three items, only one of which is addressed in #2016.

flavorjones commented 4 years ago

@jmarrec Great, thanks. I'm removing the v1.11.0 milestone marker, then, because this is a bit bigger problem than I'm ready to take on right now.

@MSP-Greg Sorry for not responding yet to your other CI-related issues, will circle back on those when I have a moment.

MSP-Greg commented 4 years ago

@flavorjones

Thanks. I know you've used Concourse-CI for a while, and times are different now.

Actions is a bit different, and some of the problems people had with AppVeyor & Travis are now being handled by Ruby people.

larskanis commented 4 years ago

I successfully mix MSVC compiled binaries into MINGW code in several projects and it should work the other way around as well. That's what I usually recommend users, when a library isn't available/compatible for the particular platform.

Regarding MSVC support in nokogiri I can not really help - I don't use MSVC and don't have any interest in doing so. But sure, I'll keep maintaining the MINGW port.

flavorjones commented 3 years ago

I'd like to close this, as I'm not sure what remains to be done and I am unaware of any ongoing work in this area.

If MSVC still does not compile Nokogiri, I'm open to a PR that addresses the issue, but I won't be doing that work myself and so I'd like to close this issue or find an owner who's willing to commit to defining and finishing the work. I'd expect setting up CI for MSVC to be part of that work, both to demonstrate the problems and to demonstrate that they've been solved.

KoellM commented 3 years ago

1.11.0 and 1.11.1 can not be installed on MSVC. This is a patch:

  # ext/nokogiri/extconf.rb

  # Before
  # ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "z", headers: "zlib.h", func: "gzdopen")

  # After
  # The change maybe affect other platforms, I’m not sure
  ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "zlib", headers: "zlib.h", func: "gzdopen")
flavorjones commented 3 years ago

OK, I'm going to close this for the reasons I've mentioned above.

Once again, I'm open to PRs that address specific MSVC issues, but then I would like these each treated as separate, addressable issues -- using the bug report or installation problem templates -- so that we understand the failure modes and can have a conversation about how to fix it.

What I really want is someone to help set up CI of some kind on MSVC so that we have a feedback loop on proposed and actual changes. This is an opportunity for people who depend on MSVC to show up in the community and contribute.

@KoellM if you'd like to have a conversation about the failure you're trying to address with the suggested patch, can you please open a new "installation difficulties" issue, and include all the necessary logs from the failed install? Thanks.

MSP-Greg commented 3 years ago

What I really want is someone to help set up CI of some kind on MSVC

Testing against Ruby mswin master can be done with GitHub Actions. ruby/openssl has been doing it for quite a while, see:

https://github.com/ruby/openssl/blob/f2d004679a62408a89d7304b229c24e789b94776/.github/workflows/test.yml#L41

flavorjones commented 3 years ago

@MSP-Greg thanks once again for being a voice in support of Github Actions. If you want to submit a PR introducing MSVC test into the CI suite (is that the same as mswin? I honestly have no idea) then I'm open to it, especially if you're a Windows user.

flavorjones commented 3 years ago

@MSP-Greg maybe here I should also qualify my remarks: I'd like some way to validate that CI is reproducing what MSVC users are doing in the real world. Which is why I keep asking Windows users to do this work.

I want to avoid the antipattern of spending time setting up a red build, then spending time getting red to green, and then discovering that real-world cases are actually harder/simpler/different. How can we mitigate that risk?