Skip to content

Commit ff40ea4

Browse files
committed
Add support for MinGW.
1 parent e251d21 commit ff40ea4

File tree

9 files changed

+117
-12
lines changed

9 files changed

+117
-12
lines changed

.github/workflows/windows_mingw.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Windows mingw
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
env:
10+
BUILD_TYPE: Release
11+
CLICKHOUSE_USER: clickhouse_cpp_cicd
12+
CLICKHOUSE_PASSWORD: clickhouse_cpp_cicd
13+
14+
#
15+
# CLICKHOUSE_HOST: localhost
16+
# CLICKHOUSE_PORT: 9000
17+
# CLICKHOUSE_USER: default
18+
# CLICKHOUSE_PASSWORD:
19+
# CLICKHOUSE_DB: default
20+
#
21+
# CLICKHOUSE_SECURE_HOST: github.demo.trial.altinity.cloud
22+
# CLICKHOUSE_SECURE_PORT: 9440
23+
# CLICKHOUSE_SECURE_USER: demo
24+
# CLICKHOUSE_SECURE_PASSWORD: demo
25+
# CLICKHOUSE_SECURE_DB: default
26+
#
27+
# CLICKHOUSE_SECURE2_HOST: gh-api.clickhouse.tech
28+
# CLICKHOUSE_SECURE2_PORT: 9440
29+
# CLICKHOUSE_SECURE2_USER: explorer
30+
# CLICKHOUSE_SECURE2_PASSWORD:
31+
# CLICKHOUSE_SECURE2_DB: default
32+
33+
jobs:
34+
build:
35+
runs-on: windows-latest
36+
37+
strategy:
38+
fail-fast: false
39+
matrix:
40+
include:
41+
- { sys: mingw64, env: x86_64 }
42+
- { sys: mingw32, env: i686 }
43+
- { sys: ucrt64, env: ucrt-x86_64 } # Experimental!
44+
# - { sys: clang64, env: clang-x86_64 } # have issues with linking see comments in Clang-related section in clickhouse/CMakeLists.txt
45+
46+
defaults:
47+
run:
48+
shell: msys2 {0}
49+
50+
steps:
51+
- uses: actions/checkout@v2
52+
- uses: msys2/setup-msys2@v2
53+
with:
54+
msystem: ${{ matrix.sys }}
55+
update: true
56+
install: >-
57+
mingw-w64-${{matrix.env}}-cmake
58+
mingw-w64-${{matrix.env}}-make
59+
mingw-w64-${{matrix.env}}-gcc
60+
mingw-w64-${{matrix.env}}-openssl
61+
mingw-w64-${{matrix.env}}-ninja
62+
mingw-w64-${{matrix.env}}-wget
63+
mingw-w64-${{matrix.env}}-ca-certificates
64+
tar
65+
66+
- name: Configure CMake
67+
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON
68+
# -DWITH_OPENSSL=ON was not able to make it work (some strange issues with CA paths, need debug)
69+
70+
- name: Build
71+
run: cmake --build build --config ${{env.BUILD_TYPE}} --target all
72+
73+
- name: Start tls offoader proxy
74+
# that mimics non-secure clickhouse running on localhost
75+
# by tunneling queries to remote tls server
76+
# (needed because we can't start real clickhouse instance on windows)
77+
run: |
78+
wget https://github.com/filimonov/go-tlsoffloader/releases/download/v0.1.2/go-tlsoffloader_0.1.2_Windows_x86_64.tar.gz
79+
tar -xvzf go-tlsoffloader_0.1.2_Windows_x86_64.tar.gz
80+
./go-tlsoffloader.exe -l localhost:9000 -b github.demo.trial.altinity.cloud:9440 &
81+
82+
- name: Test
83+
run: ./build/ut/clickhouse-cpp-ut.exe
84+
85+
- name: Test (simple)
86+
run: ./build/tests/simple/simple-test.exe

clickhouse/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static
5151
)
5252

5353
IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
54+
# there is a problem with __builtin_mul_overflow call at link time
55+
# the error looks like: ... undefined reference to `__muloti4' ...
56+
# caused by clang bug https://bugs.llvm.org/show_bug.cgi?id=16404
57+
# explicit linking to compiler-rt allows to workaround the problem
5458
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --rtlib=compiler-rt")
59+
60+
# some workaround for linking issues on linux:
61+
# /usr/bin/ld: CMakeFiles/simple-test.dir/main.cpp.o: undefined reference to symbol '_Unwind_Resume@@GCC_3.0'
62+
# /usr/bin/ld: /lib/x86_64-linux-gnu/libgcc_s.so.1: error adding symbols: DSO missing from command line
63+
# FIXME: that workaround breaks clang build on mingw
5564
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib gcc_s)
5665
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static gcc_s)
5766
ENDIF ()
@@ -108,3 +117,8 @@ IF (WITH_OPENSSL)
108117
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib OpenSSL::SSL)
109118
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static OpenSSL::SSL)
110119
ENDIF ()
120+
121+
IF (WIN32 OR MINGW)
122+
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib wsock32 ws2_32)
123+
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static wsock32 ws2_32)
124+
ENDIF ()

clickhouse/base/platform.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
#if defined(_win32_) || defined(_win64_)
1515
# define _win_
16-
# define _WIN32_WINNT 0x0600 // The WSAPoll function is defined on Windows Vista and later.
16+
# if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0600)
17+
# undef _WIN32_WINNT
18+
# define _WIN32_WINNT 0x0600 // The WSAPoll function is defined on Windows Vista and later.
19+
# endif
1720
# define WIN32_LEAN_AND_MEAN 1 // don't include too much header automatically
1821
#endif
1922

clickhouse/base/socket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const std::error_category& getErrorCategory() noexcept {
7676
}
7777

7878
void SetNonBlock(SOCKET fd, bool value) {
79-
#if defined(_unix_)
79+
#if defined(_unix_) || defined(__CYGWIN__)
8080
int flags;
8181
int ret;
8282
#if defined(O_NONBLOCK)

clickhouse/base/socket.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <string>
99

1010
#if defined(_win_)
11-
# pragma comment(lib, "Ws2_32.lib")
12-
1311
# include <winsock2.h>
1412
# include <ws2tcpip.h>
1513
#else

clickhouse/base/sslsocket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ SSLSocket::SSLSocket(const NetworkAddress& addr, const SSLParams & ssl_params, S
153153
auto peer_certificate = SSL_get_peer_certificate(ssl);
154154

155155
if (!peer_certificate)
156-
throw std::runtime_error("Failed to verify SSL connection: server provided no ceritificate.");
156+
throw std::runtime_error("Failed to verify SSL connection: server provided no certificate.");
157157

158158
if (const auto verify_result = SSL_get_verify_result(ssl); verify_result != X509_V_OK) {
159159
auto error_message = X509_verify_cert_error_string(verify_result);

clickhouse/client.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ std::ostream& operator<<(std::ostream& os, const ClientOptions& opt) {
6969
os << " SSL ("
7070
<< " ssl_context: " << (ssl_options.ssl_context ? "provided by user" : "created internally")
7171
<< " use_default_ca_locations: " << ssl_options.use_default_ca_locations
72-
<< " use_default_ca_locations: " << ssl_options.use_default_ca_locations
7372
<< " path_to_ca_files: " << ssl_options.path_to_ca_files.size() << " items"
7473
<< " path_to_ca_directory: " << ssl_options.path_to_ca_directory
7574
<< " min_protocol_version: " << ssl_options.min_protocol_version
76-
<< " min_protocol_version: " << ssl_options.max_protocol_version
75+
<< " max_protocol_version: " << ssl_options.max_protocol_version
7776
<< " context_options: " << ssl_options.context_options
7877
<< ")";
7978
}

contrib/absl/base/policy_checks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
// Operating System Check
3737
// -----------------------------------------------------------------------------
3838

39-
#if defined(__CYGWIN__)
39+
#if 0 // defined(__CYGWIN__) // it looks like int128 part of absl we use works correctly on cygwin env.
4040
#error "Cygwin is not supported."
4141
#endif
4242

ut/ssl_ut.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ namespace {
2323

2424
#if defined(__linux__)
2525
// On Ubuntu 20.04 /etc/ssl/certs is a default directory with the CA files
26-
const auto DEAFULT_CA_DIRECTORY_PATH = "/etc/ssl/certs";
26+
const auto DEFAULT_CA_DIRECTORY_PATH = "/etc/ssl/certs";
2727
#elif defined(__APPLE__)
2828
// On macOS we will rely on Homebrew's OpenSSL installation
29-
const auto DEAFULT_CA_DIRECTORY_PATH = "/usr/local/etc/[email protected]/cert.pem";
29+
const auto DEFAULT_CA_DIRECTORY_PATH = "/usr/local/etc/[email protected]/cert.pem";
3030
#elif defined(_win_)
31+
// DEBUG ME: mingw - was not able to make it work. Every time it ends with exception:
32+
// "Failed to verify SSL connection, X509_v error: 20 unable to get local issuer certificate"
33+
const auto DEFAULT_CA_DIRECTORY_PATH = "/mingw64/ssl/cert.pem";
34+
// const auto DEFAULT_CA_DIRECTORY_PATH = "/mingw64/ssl/certs";
35+
// const auto DEFAULT_CA_DIRECTORY_PATH = "/mingw64/ssl/certs/ca-bundle.crt";
3136
#endif
3237

3338
INSTANTIATE_TEST_SUITE_P(
@@ -43,7 +48,7 @@ INSTANTIATE_TEST_SUITE_P(
4348
.SetPingBeforeQuery(true)
4449
.SetCompressionMethod(CompressionMethod::None)
4550
.SetSSLOptions(ClientOptions::SSLOptions()
46-
.SetPathToCADirectory(DEAFULT_CA_DIRECTORY_PATH)),
51+
.SetPathToCADirectory(DEFAULT_CA_DIRECTORY_PATH)),
4752
QUERIES
4853
}
4954
));
@@ -61,7 +66,7 @@ INSTANTIATE_TEST_SUITE_P(
6166
.SetPingBeforeQuery(true)
6267
.SetCompressionMethod(CompressionMethod::None)
6368
.SetSSLOptions(ClientOptions::SSLOptions()
64-
.SetPathToCADirectory(DEAFULT_CA_DIRECTORY_PATH)),
69+
.SetPathToCADirectory(DEFAULT_CA_DIRECTORY_PATH)),
6570
QUERIES
6671
}
6772
));

0 commit comments

Comments
 (0)