Skip to content

Windows mingw #137

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

Merged
merged 3 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/windows_mingw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Windows mingw

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
BUILD_TYPE: Release
CLICKHOUSE_USER: clickhouse_cpp_cicd
CLICKHOUSE_PASSWORD: clickhouse_cpp_cicd

#
# CLICKHOUSE_HOST: localhost
# CLICKHOUSE_PORT: 9000
# CLICKHOUSE_USER: default
# CLICKHOUSE_PASSWORD:
# CLICKHOUSE_DB: default
#
# CLICKHOUSE_SECURE_HOST: github.demo.trial.altinity.cloud
# CLICKHOUSE_SECURE_PORT: 9440
# CLICKHOUSE_SECURE_USER: demo
# CLICKHOUSE_SECURE_PASSWORD: demo
# CLICKHOUSE_SECURE_DB: default
#
# CLICKHOUSE_SECURE2_HOST: gh-api.clickhouse.tech
# CLICKHOUSE_SECURE2_PORT: 9440
# CLICKHOUSE_SECURE2_USER: explorer
# CLICKHOUSE_SECURE2_PASSWORD:
# CLICKHOUSE_SECURE2_DB: default

jobs:
build:
runs-on: windows-latest

strategy:
fail-fast: false
matrix:
include:
- { sys: mingw64, env: x86_64 }
- { sys: ucrt64, env: ucrt-x86_64 } # Experimental!
# - { sys: clang64, env: clang-x86_64 } # have issues with linking see comments in Clang-related section in clickhouse/CMakeLists.txt

defaults:
run:
shell: msys2 {0}

steps:
- uses: actions/checkout@v2
- uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.sys }}
update: true
install: >-
mingw-w64-${{matrix.env}}-cmake
mingw-w64-${{matrix.env}}-make
mingw-w64-${{matrix.env}}-gcc
mingw-w64-${{matrix.env}}-openssl
mingw-w64-${{matrix.env}}-ninja
mingw-w64-${{matrix.env}}-wget
mingw-w64-${{matrix.env}}-ca-certificates
tar

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_TESTS=ON
# -DWITH_OPENSSL=ON was not able to make it work (some strange issues with CA paths, need debug)

- name: Build
run: cmake --build build --config ${{env.BUILD_TYPE}} --target all

- name: Start tls offoader proxy
# that mimics non-secure clickhouse running on localhost
# by tunneling queries to remote tls server
# (needed because we can't start real clickhouse instance on windows)
run: |
wget https://github.com/filimonov/go-tlsoffloader/releases/download/v0.1.2/go-tlsoffloader_0.1.2_Windows_x86_64.tar.gz
tar -xvzf go-tlsoffloader_0.1.2_Windows_x86_64.tar.gz
./go-tlsoffloader.exe -l localhost:9000 -b github.demo.trial.altinity.cloud:9440 &

- name: Test
run: ./build/ut/clickhouse-cpp-ut.exe

- name: Test (simple)
run: ./build/tests/simple/simple-test.exe
14 changes: 14 additions & 0 deletions clickhouse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static
)

IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# there is a problem with __builtin_mul_overflow call at link time
# the error looks like: ... undefined reference to `__muloti4' ...
# caused by clang bug https://bugs.llvm.org/show_bug.cgi?id=16404
# explicit linking to compiler-rt allows to workaround the problem
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --rtlib=compiler-rt")

# some workaround for linking issues on linux:
# /usr/bin/ld: CMakeFiles/simple-test.dir/main.cpp.o: undefined reference to symbol '_Unwind_Resume@@GCC_3.0'
# /usr/bin/ld: /lib/x86_64-linux-gnu/libgcc_s.so.1: error adding symbols: DSO missing from command line
# FIXME: that workaround breaks clang build on mingw
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib gcc_s)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static gcc_s)
ENDIF ()
Expand Down Expand Up @@ -108,3 +117,8 @@ IF (WITH_OPENSSL)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib OpenSSL::SSL)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static OpenSSL::SSL)
ENDIF ()

IF (WIN32 OR MINGW)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib wsock32 ws2_32)
TARGET_LINK_LIBRARIES (clickhouse-cpp-lib-static wsock32 ws2_32)
ENDIF ()
5 changes: 4 additions & 1 deletion clickhouse/base/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

#if defined(_win32_) || defined(_win64_)
# define _win_
# define _WIN32_WINNT 0x0600 // The WSAPoll function is defined on Windows Vista and later.
# if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0600)
# undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600 // The WSAPoll function is defined on Windows Vista and later.
# endif
# define WIN32_LEAN_AND_MEAN 1 // don't include too much header automatically
#endif

Expand Down
2 changes: 1 addition & 1 deletion clickhouse/base/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const std::error_category& getErrorCategory() noexcept {
}

void SetNonBlock(SOCKET fd, bool value) {
#if defined(_unix_)
#if defined(_unix_) || defined(__CYGWIN__)
int flags;
int ret;
#if defined(O_NONBLOCK)
Expand Down
2 changes: 0 additions & 2 deletions clickhouse/base/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <string>

#if defined(_win_)
# pragma comment(lib, "Ws2_32.lib")

# include <winsock2.h>
# include <ws2tcpip.h>
#else
Expand Down
2 changes: 1 addition & 1 deletion clickhouse/base/sslsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ SSLSocket::SSLSocket(const NetworkAddress& addr, const SSLParams & ssl_params, S
auto peer_certificate = SSL_get_peer_certificate(ssl);

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

if (const auto verify_result = SSL_get_verify_result(ssl); verify_result != X509_V_OK) {
auto error_message = X509_verify_cert_error_string(verify_result);
Expand Down
3 changes: 1 addition & 2 deletions clickhouse/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ std::ostream& operator<<(std::ostream& os, const ClientOptions& opt) {
os << " SSL ("
<< " ssl_context: " << (ssl_options.ssl_context ? "provided by user" : "created internally")
<< " use_default_ca_locations: " << ssl_options.use_default_ca_locations
<< " use_default_ca_locations: " << ssl_options.use_default_ca_locations
<< " path_to_ca_files: " << ssl_options.path_to_ca_files.size() << " items"
<< " path_to_ca_directory: " << ssl_options.path_to_ca_directory
<< " min_protocol_version: " << ssl_options.min_protocol_version
<< " min_protocol_version: " << ssl_options.max_protocol_version
<< " max_protocol_version: " << ssl_options.max_protocol_version
<< " context_options: " << ssl_options.context_options
<< ")";
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/absl/base/policy_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// Operating System Check
// -----------------------------------------------------------------------------

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

Expand Down
4 changes: 2 additions & 2 deletions ut/columns_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ TEST(ColumnsCase, DateTime64_Swap_EXCEPTION) {

TEST(ColumnsCase, Date2038) {
auto col1 = std::make_shared<ColumnDate>();
std::time_t largeDate(25882ul * 86400ul);
const std::time_t largeDate(25882ull * 86400ull);
col1->Append(largeDate);

ASSERT_EQ(col1->Size(), 1u);
ASSERT_EQ(static_cast<std::uint64_t>(col1->At(0)), 25882ul * 86400ul);
ASSERT_EQ(largeDate, col1->At(0));
}

TEST(ColumnsCase, DateTime) {
Expand Down
13 changes: 9 additions & 4 deletions ut/ssl_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ namespace {

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

INSTANTIATE_TEST_SUITE_P(
Expand All @@ -43,7 +48,7 @@ INSTANTIATE_TEST_SUITE_P(
.SetPingBeforeQuery(true)
.SetCompressionMethod(CompressionMethod::None)
.SetSSLOptions(ClientOptions::SSLOptions()
.SetPathToCADirectory(DEAFULT_CA_DIRECTORY_PATH)),
.SetPathToCADirectory(DEFAULT_CA_DIRECTORY_PATH)),
QUERIES
}
));
Expand All @@ -61,7 +66,7 @@ INSTANTIATE_TEST_SUITE_P(
.SetPingBeforeQuery(true)
.SetCompressionMethod(CompressionMethod::None)
.SetSSLOptions(ClientOptions::SSLOptions()
.SetPathToCADirectory(DEAFULT_CA_DIRECTORY_PATH)),
.SetPathToCADirectory(DEFAULT_CA_DIRECTORY_PATH)),
QUERIES
}
));
Expand Down