Skip to content

Commit dcf36c5

Browse files
committed
Merge branch 'feature/cmake_msvc_tmp' into feature/test_coverage
2 parents 4288657 + a5f1da7 commit dcf36c5

File tree

7 files changed

+184
-92
lines changed

7 files changed

+184
-92
lines changed

CMakeLists.txt

Lines changed: 72 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,52 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
5656
endif()
5757
endif()
5858

59+
set(FLB_EXTRA_CMAKE_CXX_FLAGS)
60+
set(FLB_EXTRA_CMAKE_CXX_LINK_FLAGS)
61+
62+
# For consistency with MSVC debug C/C++ runtime (/MTd and /MDd options),
63+
# which is used for the Debug build and which automatically adds _DEBUG.
64+
add_compile_definitions($<$<CONFIG:Debug>:_DEBUG>)
65+
5966
# Update CFLAGS
6067
if (MSVC)
68+
# Use static C runtime
69+
if (NOT (CMAKE_VERSION VERSION_LESS "3.15"))
70+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
71+
endif()
72+
add_compile_options(/MT$<$<CONFIG:Debug>:d>)
73+
# Replace (/|-)MD(d?) with (/|-)MT(d?) to avoid D9025 warning
74+
foreach(config_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug Release RelWithDebInfo MinSizeRel)
75+
string(TOUPPER ${config_type} upper_config_type)
76+
set(flag_var "CMAKE_C_FLAGS_${upper_config_type}")
77+
string(REGEX REPLACE "(^| |\\t|\\r|\\n)(-|/)(MD)(d?)($| |\\t|\\r|\\n)" "\\1\\2MT\\4\\5" ${flag_var} "${${flag_var}}")
78+
endforeach()
79+
set(flag_var)
80+
set(upper_config_type)
81+
set(config_type)
82+
83+
# Make compiler aware of source code using UTF-8 encoding
84+
add_compile_options(/utf-8)
85+
6186
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
6287
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
6388

6489
# Use custom CFLAGS for MSVC
6590
#
6691
# /Zi ...... Generate pdb files.
67-
# /MT ...... Static link C runtimes.
6892
# /wd4711 .. C4711 (function selected for inline expansion)
6993
# /wd4100 .. C4100 (unreferenced formal parameter)
7094
# /wd5045 .. C5045 (Spectre mitigation)
7195
#
7296
# Restore /OPT:REF after setting /Debug, enable /OPT:ICF for 64-bit
7397
# builds per Microsoft recommended best practices.
74-
set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /DNDEBUG /O2 /Zi /wd4100 /wd4711 /wd5045")
98+
set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /Zi /wd4100 /wd4711 /wd5045")
7599
set(CMAKE_EXE_LINKER_FLAGS "/DEBUG /OPT:REF /INCREMENTAL:NO")
76100
set(CMAKE_SHARED_LINKER_FLAGS "/DEBUG /OPT:REF /INCREMENTAL:NO")
77-
set(CMAKE_BUILD_TYPE None)
78101
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
79102
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:ICF")
80103
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:ICF")
81104
endif()
82-
83-
# Use add_compile_options() to set /MT since Visual Studio
84-
# Generator does not notice /MT in CMAKE_C_FLAGS.
85-
add_compile_options(/MT)
86105
else()
87106
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
88107
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
@@ -104,17 +123,23 @@ else()
104123
endif()
105124
endif()
106125

107-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FLB_FILENAME__=__FILE__")
126+
add_compile_definitions(__FLB_FILENAME__=__FILE__)
108127

109128
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l")
110129
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -latomic")
111-
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic")
130+
# CMAKE_CXX_LINK_FLAGS will be extended with FLB_EXTRA_CMAKE_CXX_LINK_FLAGS,
131+
# when / if C++ language support will be enabled.
132+
# Until C++ language support is enabled, CMAKE_CXX_LINK_FLAGS is empty / undefined.
133+
set(FLB_EXTRA_CMAKE_CXX_LINK_FLAGS "${FLB_EXTRA_CMAKE_CXX_LINK_FLAGS} -latomic")
112134
endif()
113135
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
114136
set(FLB_SYSTEM_FREEBSD On)
115137
add_definitions(-DFLB_SYSTEM_FREEBSD)
116138
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -lutil")
117-
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -lutil")
139+
# CMAKE_CXX_LINK_FLAGS will be extended with FLB_EXTRA_CMAKE_CXX_LINK_FLAGS,
140+
# when / if C++ language support will be enabled.
141+
# Until C++ language support is enabled, CMAKE_CXX_LINK_FLAGS is empty / undefined.
142+
set(FLB_EXTRA_CMAKE_CXX_LINK_FLAGS "${FLB_EXTRA_CMAKE_CXX_LINK_FLAGS} -lutil")
118143
endif()
119144

120145
# *BSD is not supported platform for wasm-micro-runtime except for FreeBSD.
@@ -525,9 +550,12 @@ if(FLB_UNICODE_ENCODER)
525550
endif()
526551

527552
if(FLB_COVERAGE)
528-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage -fprofile-arcs -ftest-coverage")
553+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage -fprofile-arcs -ftest-coverage -fprofile-update=atomic")
529554
if (FLB_UNICODE_ENCODER)
530-
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage -fprofile-arcs -ftest-coverage")
555+
# CMAKE_CXX_FLAGS will be extended with FLB_EXTRA_CMAKE_CXX_FLAGS,
556+
# when / if C++ language support will be enabled.
557+
# Until C++ language support is enabled, CMAKE_CXX_FLAGS is empty / undefined.
558+
set(FLB_EXTRA_CMAKE_CXX_FLAGS "${FLB_EXTRA_CMAKE_CXX_FLAGS} -g -O0 --coverage -fprofile-arcs -ftest-coverage -fprofile-update=atomic")
531559
endif()
532560
set(CMAKE_BUILD_TYPE "Debug")
533561
endif()
@@ -544,9 +572,7 @@ if(FLB_COMPILER_STRICT_POINTER_TYPES)
544572
endif()
545573

546574
# Enable Debug symbols if specified
547-
if(MSVC)
548-
set(CMAKE_BUILD_TYPE None) # Avoid flag conflicts (See CMakeList.txt:L18)
549-
elseif(FLB_RELEASE)
575+
if(FLB_RELEASE)
550576
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
551577
elseif(FLB_DEBUG)
552578
set(CMAKE_BUILD_TYPE "Debug")
@@ -665,6 +691,12 @@ endif()
665691

666692
# MPack
667693
add_definitions(-DMPACK_EXTENSIONS=1)
694+
# MPack read / write tracking seems to have issues with nested types,
695+
# so it needs to be disabled explicitly, because otherwise MPack
696+
# read / write tracking is automatically enabled for the Debug build
697+
# (when _DEBUG macro is defined) with some compilers, like MSVC
698+
# (refer to https://learn.microsoft.com/en-us/cpp/c-runtime-library/debug).
699+
add_definitions(-DMPACK_READ_TRACKING=0 -DMPACK_WRITE_TRACKING=0)
668700
add_subdirectory(${FLB_PATH_LIB_MPACK} EXCLUDE_FROM_ALL)
669701

670702
# Miniz (zip)
@@ -752,13 +784,30 @@ if(FLB_UTF8_ENCODER)
752784
add_subdirectory(${FLB_PATH_LIB_TUTF8E} EXCLUDE_FROM_ALL)
753785
endif()
754786

787+
# All cases when C++ language support is needed should be checked here
788+
if((FLB_UNICODE_ENCODER AND FLB_USE_SIMDUTF) OR FLB_RIPSER)
789+
enable_language(CXX)
790+
791+
# Perform delayed modification / extension of CMAKE_CXX_* variables.
792+
if(MSVC)
793+
# Replace (/|-)MD(d?) with (/|-)MT(d?) to avoid D9025 warning
794+
foreach(config_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug Release RelWithDebInfo MinSizeRel)
795+
string(TOUPPER ${config_type} upper_config_type)
796+
set(flag_var "CMAKE_CXX_FLAGS_${upper_config_type}")
797+
string(REGEX REPLACE "(^| |\\t|\\r|\\n)(-|/)(MD)(d?)($| |\\t|\\r|\\n)" "\\1\\2MT\\4\\5" ${flag_var} "${${flag_var}}")
798+
endforeach()
799+
set(flag_var)
800+
set(upper_config_type)
801+
set(config_type)
802+
endif()
803+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${FLB_EXTRA_CMAKE_CXX_FLAGS}")
804+
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}${FLB_EXTRA_CMAKE_CXX_LINK_FLAGS}")
805+
806+
set(CMAKE_CXX_STANDARD 11)
807+
endif()
808+
755809
# simdutf
756810
if(FLB_UNICODE_ENCODER AND FLB_USE_SIMDUTF)
757-
if (NOT FLB_USE_SIMDUTF)
758-
message(FATAL_ERROR "FLB_UNICODE_ENCODER requires FLB_USE_SIMDUTF")
759-
endif()
760-
enable_language(CXX)
761-
set (CMAKE_CXX_STANDARD 11)
762811
add_subdirectory(${FLB_PATH_LIB_SIMDUTF} EXCLUDE_FROM_ALL)
763812
FLB_DEFINITION(FLB_HAVE_UNICODE_ENCODER)
764813
endif()
@@ -818,7 +867,9 @@ macro(MK_SET_OPTION option value)
818867
set(${option} ${value} CACHE INTERNAL "" FORCE)
819868
endmacro()
820869
MK_SET_OPTION(MK_SYSTEM_MALLOC ON)
821-
MK_SET_OPTION(MK_DEBUG ON)
870+
if(NOT MSVC)
871+
MK_SET_OPTION(MK_DEBUG ON)
872+
endif()
822873

823874
# Monkey backend event loop
824875
if (FLB_EVENT_LOOP_EPOLL)
@@ -915,8 +966,6 @@ endif()
915966

916967
# ripser
917968
if(FLB_RIPSER)
918-
enable_language(CXX)
919-
set (CMAKE_CXX_STANDARD 11)
920969
add_subdirectory(${FLB_PATH_LIB_RIPSER} EXCLUDE_FROM_ALL)
921970
FLB_DEFINITION(FLB_HAVE_RIPSER)
922971
endif()

DEVELOPER_GUIDE.md

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -746,54 +746,54 @@ The following steps have been tested on a Windows Server 2022 Datacenter edition
746746
2. **Install Flex and Bison**
747747
1. Create a new file called `setup-flex-bison.ps1` and paste the following script:
748748

749-
```powershell
750-
# Define variables for Flex and Bison
751-
$flexBisonUrl = "https://sourceforge.net/projects/winflexbison/files/win_flex_bison3-latest.zip/download"
752-
$downloadPath = "$env:TEMP\win_flex_bison.zip"
753-
$extractPath = "C:\win_flex_bison"
754-
$flexExe = "flex.exe"
755-
$bisonExe = "bison.exe"
756-
757-
# Step 2: Download and Setup Flex and Bison
758-
Write-Output "Downloading win_flex_bison..."
759-
Invoke-WebRequest -Uri $flexBisonUrl -OutFile $downloadPath
760-
761-
# Create the extract directory if it does not exist
762-
If (!(Test-Path -Path $extractPath)) {
763-
New-Item -ItemType Directory -Path $extractPath
764-
}
749+
```powershell
750+
# Define variables for Flex and Bison
751+
$flexBisonUrl = "https://sourceforge.net/projects/winflexbison/files/win_flex_bison3-latest.zip/download"
752+
$downloadPath = "$env:TEMP\win_flex_bison.zip"
753+
$extractPath = "C:\win_flex_bison"
754+
$flexExe = "flex.exe"
755+
$bisonExe = "bison.exe"
756+
757+
# Step 2: Download and Setup Flex and Bison
758+
Write-Output "Downloading win_flex_bison..."
759+
Invoke-WebRequest -Uri $flexBisonUrl -OutFile $downloadPath
760+
761+
# Create the extract directory if it does not exist
762+
If (!(Test-Path -Path $extractPath)) {
763+
New-Item -ItemType Directory -Path $extractPath
764+
}
765765
766-
# Extract the zip file
767-
Write-Output "Extracting win_flex_bison..."
768-
Add-Type -AssemblyName System.IO.Compression.FileSystem
769-
[System.IO.Compression.ZipFile]::ExtractToDirectory($downloadPath, $extractPath)
770-
771-
# Rename the executables
772-
Write-Output "Renaming executables..."
773-
Rename-Item "$extractPath\win_flex.exe" "$extractPath\$flexExe" -Force
774-
Rename-Item "$extractPath\win_bison.exe" "$extractPath\$bisonExe" -Force
775-
776-
# Add Flex and Bison path to system environment variables
777-
Write-Output "Adding Flex and Bison path to environment variables..."
778-
$envPath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
779-
If ($envPath -notlike "*$extractPath*") {
780-
[System.Environment]::SetEnvironmentVariable("Path", "$envPath;$extractPath", "Machine")
781-
Write-Output "Path updated. Please restart your command prompt to apply changes."
782-
} else {
783-
Write-Output "Path already contains the Flex and Bison directory."
784-
}
766+
# Extract the zip file
767+
Write-Output "Extracting win_flex_bison..."
768+
Add-Type -AssemblyName System.IO.Compression.FileSystem
769+
[System.IO.Compression.ZipFile]::ExtractToDirectory($downloadPath, $extractPath)
770+
771+
# Rename the executables
772+
Write-Output "Renaming executables..."
773+
Rename-Item "$extractPath\win_flex.exe" "$extractPath\$flexExe" -Force
774+
Rename-Item "$extractPath\win_bison.exe" "$extractPath\$bisonExe" -Force
775+
776+
# Add Flex and Bison path to system environment variables
777+
Write-Output "Adding Flex and Bison path to environment variables..."
778+
$envPath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
779+
If ($envPath -notlike "*$extractPath*") {
780+
[System.Environment]::SetEnvironmentVariable("Path", "$envPath;$extractPath", "Machine")
781+
Write-Output "Path updated. Please restart your command prompt to apply changes."
782+
} else {
783+
Write-Output "Path already contains the Flex and Bison directory."
784+
}
785785
786-
# Cleanup
787-
Remove-Item $downloadPath
786+
# Cleanup
787+
Remove-Item $downloadPath
788788
789-
Write-Output "Flex and Bison setup complete."
790-
```
789+
Write-Output "Flex and Bison setup complete."
790+
```
791791
792792
2. Run the Script: Open PowerShell as administrator.
793793
794-
```powershell
795-
.\setup-flex-bison.ps1
796-
```
794+
```powershell
795+
.\setup-flex-bison.ps1
796+
```
797797
798798
3. Restart the command prompt: After the script completes, restart your command prompt or Visual Studio for the changes to take effect.
799799
@@ -853,7 +853,7 @@ The following steps have been tested on a Windows Server 2022 Datacenter edition
853853
7. **Run the binary build**
854854
855855
```bash
856-
cmake --build . --parallel 4 --clean-first
856+
cmake --build . --config Release --parallel 4 --clean-first
857857
```
858858
859859
**Notes**:

dockerfiles/Dockerfile.windows

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ RUN if ([System.Version] \"${env:CMAKE_VERSION}\" -ge [System.Version] \"3.20.0\
8888
Write-Host \"${env:PATH}\"; `
8989
[Environment]::SetEnvironmentVariable(\"PATH\", \"${env:PATH}\", [EnvironmentVariableTarget]::Machine);
9090

91+
ENV NINJA_HOME="C:\ninja"
92+
ARG NINJA_VERSION="1.13.2"
93+
ARG NINJA_URL="https://github.com/ninja-build/ninja/releases/download"
94+
95+
RUN $ninja_dist_name=\"ninja-win.zip\"; `
96+
$ninja_dist=\"${env:TMP}\${ninja_dist_name}\"; `
97+
$ninja_download_url=\"${env:NINJA_URL}/v${env:NINJA_VERSION}/${ninja_dist_name}\"; `
98+
Write-Host \"Downloading Ninja...\"; `
99+
Write-Host \"${ninja_download_url} -> ${ninja_dist}\"; `
100+
Invoke-WebRequest -OutFile \"${ninja_dist}\" \"${ninja_download_url}\"; `
101+
New-Item -Path \"${env:NINJA_HOME}\" -ItemType \"directory\"; `
102+
Write-Host \"Extracting Ninja...\"; `
103+
Write-Host \"${ninja_dist} -> ${env:NINJA_HOME}\"; `
104+
Expand-Archive \"${ninja_dist}\" -Destination \"${env:NINJA_HOME}\"; `
105+
Remove-Item -Force \"${ninja_dist}\"; `
106+
$env:PATH=\"${env:PATH};${env:NINJA_HOME}\"; `
107+
Write-Host \"Setting PATH...\"; `
108+
Write-Host \"${env:PATH}\"; `
109+
[Environment]::SetEnvironmentVariable(\"PATH\", \"${env:PATH}\", [EnvironmentVariableTarget]::Machine);
110+
91111
ENV WIN_FLEX_BISON_VERSION="2.5.22" `
92112
WIN_FLEX_BISON_HOME="C:\WinFlexBison" `
93113
WIN_FLEX_BISON_DOWNLOAD_URL="https://github.com/lexxmark/winflexbison/releases/download"
@@ -175,17 +195,16 @@ COPY . /src/
175195
ARG BUILD_PARALLEL=1
176196
SHELL ["cmd", "/S", "/C"]
177197
RUN call "%MSVS_HOME%\VC\Auxiliary\Build\vcvars64.bat" && `
178-
cmake -G "NMake Makefiles" `
198+
cmake -G "Ninja" `
179199
-DOPENSSL_ROOT_DIR='C:\dev\vcpkg\packages\openssl_x64-windows-static' `
180200
-DFLB_LIBYAML_DIR='C:\dev\vcpkg\packages\libyaml_x64-windows-static' `
181201
-DFLB_SIMD=On `
182-
-DCMAKE_BUILD_TYPE=Release `
183202
-DFLB_SHARED_LIB=Off `
184203
-DFLB_EXAMPLES=Off `
185204
-DFLB_DEBUG=Off `
186205
-DFLB_RELEASE=On `
187206
..\ && `
188-
cmake --build . --config Release -j "%BUILD_PARALLEL%"
207+
cmake --build . -j "%BUILD_PARALLEL%"
189208

190209
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
191210

lib/chunkio/src/cio_file_win32.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include <inttypes.h>
21+
#include <limits.h>
2122
#include <stdio.h>
2223

2324
#include <chunkio/chunkio_compat.h>
@@ -76,6 +77,8 @@ int cio_file_native_map(struct cio_file *cf, size_t map_size)
7677
DWORD desired_access;
7778
size_t file_size;
7879
size_t actual_map_size;
80+
DWORD actual_map_size_high;
81+
DWORD actual_map_size_low;
7982
int ret;
8083

8184
if (cf == NULL) {
@@ -131,10 +134,18 @@ int cio_file_native_map(struct cio_file *cf, size_t map_size)
131134

132135
/* CreateFileMappingA requires size as two DWORDs (high and low) */
133136
/* Use actual_map_size to ensure consistency */
137+
#if SIZE_MAX > MAXDWORD
138+
actual_map_size_high = (DWORD)((actual_map_size >> (sizeof(DWORD) * CHAR_BIT))
139+
& 0xFFFFFFFFUL);
140+
actual_map_size_low = (DWORD)(actual_map_size & 0xFFFFFFFFUL);
141+
#else
142+
actual_map_size_high = 0;
143+
actual_map_size_low = (DWORD)actual_map_size;
144+
#endif
134145
cf->backing_mapping = CreateFileMappingA(cf->backing_file, NULL,
135146
desired_protection,
136-
(DWORD)(actual_map_size >> 32),
137-
(DWORD)(actual_map_size & 0xFFFFFFFFUL),
147+
actual_map_size_high,
148+
actual_map_size_low,
138149
NULL);
139150

140151
if (cf->backing_mapping == NULL) {

lib/librdkafka-2.10.1/src/rdkafka_ssl.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
#ifdef _WIN32
4141
#include <wincrypt.h>
4242
#pragma comment(lib, "crypt32.lib")
43-
#pragma comment(lib, "libcrypto.lib")
44-
#pragma comment(lib, "libssl.lib")
4543
#endif
4644

4745
#include <openssl/x509.h>

0 commit comments

Comments
 (0)