Skip to content
Open
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
82 changes: 66 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,52 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
endif()
endif()

set(FLB_EXTRA_CMAKE_CXX_FLAGS)
set(FLB_EXTRA_CMAKE_CXX_LINK_FLAGS)

# For consistency with MSVC debug C/C++ runtime (/MTd and /MDd options),
# which is used for the Debug build and which automatically adds _DEBUG.
add_compile_definitions($<$<CONFIG:Debug>:_DEBUG>)

# Update CFLAGS
if (MSVC)
# Use static C runtime
if (NOT (CMAKE_VERSION VERSION_LESS "3.15"))
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
add_compile_options(/MT$<$<CONFIG:Debug>:d>)
# Replace (/|-)MD(d?) with (/|-)MT(d?) to avoid D9025 warning
foreach(config_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug Release RelWithDebInfo MinSizeRel)
string(TOUPPER ${config_type} upper_config_type)
set(flag_var "CMAKE_C_FLAGS_${upper_config_type}")
string(REGEX REPLACE "(^| |\\t|\\r|\\n)(-|/)(MD)(d?)($| |\\t|\\r|\\n)" "\\1\\2MT\\4\\5" ${flag_var} "${${flag_var}}")
endforeach()
set(flag_var)
set(upper_config_type)
set(config_type)

# Make compiler aware of source code using UTF-8 encoding
add_compile_options(/utf-8)

add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)

# Use custom CFLAGS for MSVC
#
# /Zi ...... Generate pdb files.
# /MT ...... Static link C runtimes.
# /wd4711 .. C4711 (function selected for inline expansion)
# /wd4100 .. C4100 (unreferenced formal parameter)
# /wd5045 .. C5045 (Spectre mitigation)
#
# Restore /OPT:REF after setting /Debug, enable /OPT:ICF for 64-bit
# builds per Microsoft recommended best practices.
set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /DNDEBUG /O2 /Zi /wd4100 /wd4711 /wd5045")
set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /Zi /wd4100 /wd4711 /wd5045")
set(CMAKE_EXE_LINKER_FLAGS "/DEBUG /OPT:REF /INCREMENTAL:NO")
set(CMAKE_SHARED_LINKER_FLAGS "/DEBUG /OPT:REF /INCREMENTAL:NO")
set(CMAKE_BUILD_TYPE None)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:ICF")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:ICF")
endif()

# Use add_compile_options() to set /MT since Visual Studio
# Generator does not notice /MT in CMAKE_C_FLAGS.
add_compile_options(/MT)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
Expand All @@ -102,17 +121,23 @@ else()
endif()
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FLB_FILENAME__=__FILE__")
add_compile_definitions(__FLB_FILENAME__=__FILE__)

if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l")
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -latomic")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -latomic")
# CMAKE_CXX_LINK_FLAGS will be extended with FLB_EXTRA_CMAKE_CXX_LINK_FLAGS,
# when / if C++ language support will be enabled.
# Until C++ language support is enabled, CMAKE_CXX_LINK_FLAGS is empty / undefined.
set(FLB_EXTRA_CMAKE_CXX_LINK_FLAGS "${FLB_EXTRA_CMAKE_CXX_LINK_FLAGS} -latomic")
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(FLB_SYSTEM_FREEBSD On)
add_definitions(-DFLB_SYSTEM_FREEBSD)
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -lutil")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -lutil")
# CMAKE_CXX_LINK_FLAGS will be extended with FLB_EXTRA_CMAKE_CXX_LINK_FLAGS,
# when / if C++ language support will be enabled.
# Until C++ language support is enabled, CMAKE_CXX_LINK_FLAGS is empty / undefined.
set(FLB_EXTRA_CMAKE_CXX_LINK_FLAGS "${FLB_EXTRA_CMAKE_CXX_LINK_FLAGS} -lutil")
endif()

# *BSD is not supported platform for wasm-micro-runtime except for FreeBSD.
Expand Down Expand Up @@ -452,9 +477,12 @@ if(FLB_UNICODE_ENCODER)
endif()

if(FLB_COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage -fprofile-arcs -ftest-coverage -fprofile-update=atomic")
if (FLB_UNICODE_ENCODER)
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -g -O0 --coverage -fprofile-arcs -ftest-coverage")
# CMAKE_CXX_FLAGS will be extended with FLB_EXTRA_CMAKE_CXX_FLAGS,
# when / if C++ language support will be enabled.
# Until C++ language support is enabled, CMAKE_CXX_FLAGS is empty / undefined.
set(FLB_EXTRA_CMAKE_CXX_FLAGS "${FLB_EXTRA_CMAKE_CXX_FLAGS} -g -O0 --coverage -fprofile-arcs -ftest-coverage -fprofile-update=atomic")
endif()
set(CMAKE_BUILD_TYPE "Debug")
endif()
Expand All @@ -471,9 +499,7 @@ if(FLB_COMPILER_STRICT_POINTER_TYPES)
endif()

# Enable Debug symbols if specified
if(MSVC)
set(CMAKE_BUILD_TYPE None) # Avoid flag conflicts (See CMakeList.txt:L18)
elseif(FLB_RELEASE)
if(FLB_RELEASE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
elseif(FLB_DEBUG)
set(CMAKE_BUILD_TYPE "Debug")
Expand Down Expand Up @@ -592,6 +618,12 @@ endif()

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

# Miniz (zip)
Expand Down Expand Up @@ -677,6 +709,22 @@ if(FLB_UNICODE_ENCODER AND FLB_USE_SIMDUTF)
message(FATAL_ERROR "FLB_UNICODE_ENCODER requires FLB_USE_SIMDUTF")
endif()
enable_language(CXX)

# Perform delayed modification / extension of CMAKE_CXX_* variables.
if (MSVC)
# Replace (/|-)MD(d?) with (/|-)MT(d?) to avoid D9025 warning
foreach(config_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug Release RelWithDebInfo MinSizeRel)
string(TOUPPER ${config_type} upper_config_type)
set(flag_var "CMAKE_CXX_FLAGS_${upper_config_type}")
string(REGEX REPLACE "(^| |\\t|\\r|\\n)(-|/)(MD)(d?)($| |\\t|\\r|\\n)" "\\1\\2MT\\4\\5" ${flag_var} "${${flag_var}}")
endforeach()
set(flag_var)
set(upper_config_type)
set(config_type)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${FLB_EXTRA_CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}${FLB_EXTRA_CMAKE_CXX_LINK_FLAGS}")

set (CMAKE_CXX_STANDARD 11)
add_subdirectory(${FLB_PATH_LIB_SIMDUTF} EXCLUDE_FROM_ALL)
FLB_DEFINITION(FLB_HAVE_UNICODE_ENCODER)
Expand Down Expand Up @@ -737,7 +785,9 @@ macro(MK_SET_OPTION option value)
set(${option} ${value} CACHE INTERNAL "" FORCE)
endmacro()
MK_SET_OPTION(MK_SYSTEM_MALLOC ON)
MK_SET_OPTION(MK_DEBUG ON)
if(NOT MSVC)
MK_SET_OPTION(MK_DEBUG ON)
endif()

# Monkey backend event loop
if (FLB_EVENT_LOOP_EPOLL)
Expand Down
86 changes: 43 additions & 43 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,54 +746,54 @@ The following steps have been tested on a Windows Server 2022 Datacenter edition
2. **Install Flex and Bison**
1. Create a new file called `setup-flex-bison.ps1` and paste the following script:

```powershell
# Define variables for Flex and Bison
$flexBisonUrl = "https://sourceforge.net/projects/winflexbison/files/win_flex_bison3-latest.zip/download"
$downloadPath = "$env:TEMP\win_flex_bison.zip"
$extractPath = "C:\win_flex_bison"
$flexExe = "flex.exe"
$bisonExe = "bison.exe"

# Step 2: Download and Setup Flex and Bison
Write-Output "Downloading win_flex_bison..."
Invoke-WebRequest -Uri $flexBisonUrl -OutFile $downloadPath

# Create the extract directory if it does not exist
If (!(Test-Path -Path $extractPath)) {
New-Item -ItemType Directory -Path $extractPath
}
```powershell
# Define variables for Flex and Bison
$flexBisonUrl = "https://sourceforge.net/projects/winflexbison/files/win_flex_bison3-latest.zip/download"
$downloadPath = "$env:TEMP\win_flex_bison.zip"
$extractPath = "C:\win_flex_bison"
$flexExe = "flex.exe"
$bisonExe = "bison.exe"

# Step 2: Download and Setup Flex and Bison
Write-Output "Downloading win_flex_bison..."
Invoke-WebRequest -Uri $flexBisonUrl -OutFile $downloadPath

# Create the extract directory if it does not exist
If (!(Test-Path -Path $extractPath)) {
New-Item -ItemType Directory -Path $extractPath
}

# Extract the zip file
Write-Output "Extracting win_flex_bison..."
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($downloadPath, $extractPath)

# Rename the executables
Write-Output "Renaming executables..."
Rename-Item "$extractPath\win_flex.exe" "$extractPath\$flexExe" -Force
Rename-Item "$extractPath\win_bison.exe" "$extractPath\$bisonExe" -Force

# Add Flex and Bison path to system environment variables
Write-Output "Adding Flex and Bison path to environment variables..."
$envPath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
If ($envPath -notlike "*$extractPath*") {
[System.Environment]::SetEnvironmentVariable("Path", "$envPath;$extractPath", "Machine")
Write-Output "Path updated. Please restart your command prompt to apply changes."
} else {
Write-Output "Path already contains the Flex and Bison directory."
}
# Extract the zip file
Write-Output "Extracting win_flex_bison..."
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($downloadPath, $extractPath)

# Rename the executables
Write-Output "Renaming executables..."
Rename-Item "$extractPath\win_flex.exe" "$extractPath\$flexExe" -Force
Rename-Item "$extractPath\win_bison.exe" "$extractPath\$bisonExe" -Force

# Add Flex and Bison path to system environment variables
Write-Output "Adding Flex and Bison path to environment variables..."
$envPath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
If ($envPath -notlike "*$extractPath*") {
[System.Environment]::SetEnvironmentVariable("Path", "$envPath;$extractPath", "Machine")
Write-Output "Path updated. Please restart your command prompt to apply changes."
} else {
Write-Output "Path already contains the Flex and Bison directory."
}

# Cleanup
Remove-Item $downloadPath
# Cleanup
Remove-Item $downloadPath

Write-Output "Flex and Bison setup complete."
```
Write-Output "Flex and Bison setup complete."
```

2. Run the Script: Open PowerShell as administrator.

```powershell
.\setup-flex-bison.ps1
```
```powershell
.\setup-flex-bison.ps1
```

3. Restart the command prompt: After the script completes, restart your command prompt or Visual Studio for the changes to take effect.

Expand Down Expand Up @@ -853,7 +853,7 @@ The following steps have been tested on a Windows Server 2022 Datacenter edition
7. **Run the binary build**

```bash
cmake --build . --parallel 4 --clean-first
cmake --build . --config Release --parallel 4 --clean-first
```

**Notes**:
Expand Down
25 changes: 22 additions & 3 deletions dockerfiles/Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ RUN if ([System.Version] \"${env:CMAKE_VERSION}\" -ge [System.Version] \"3.20.0\
Write-Host \"${env:PATH}\"; `
[Environment]::SetEnvironmentVariable(\"PATH\", \"${env:PATH}\", [EnvironmentVariableTarget]::Machine);

ENV NINJA_HOME="C:\ninja"
ARG NINJA_VERSION="1.13.2"
ARG NINJA_URL="https://github.com/ninja-build/ninja/releases/download"

RUN $ninja_dist_name=\"ninja-win.zip\"; `
$ninja_dist=\"${env:TMP}\${ninja_dist_name}\"; `
$ninja_download_url=\"${env:NINJA_URL}/v${env:NINJA_VERSION}/${ninja_dist_name}\"; `
Write-Host \"Downloading Ninja...\"; `
Write-Host \"${ninja_download_url} -> ${ninja_dist}\"; `
Invoke-WebRequest -OutFile \"${ninja_dist}\" \"${ninja_download_url}\"; `
New-Item -Path \"${env:NINJA_HOME}\" -ItemType \"directory\"; `
Write-Host \"Extracting Ninja...\"; `
Write-Host \"${ninja_dist} -> ${env:NINJA_HOME}\"; `
Expand-Archive \"${ninja_dist}\" -Destination \"${env:NINJA_HOME}\"; `
Remove-Item -Force \"${ninja_dist}\"; `
$env:PATH=\"${env:PATH};${env:NINJA_HOME}\"; `
Write-Host \"Setting PATH...\"; `
Write-Host \"${env:PATH}\"; `
[Environment]::SetEnvironmentVariable(\"PATH\", \"${env:PATH}\", [EnvironmentVariableTarget]::Machine);

ENV WIN_FLEX_BISON_VERSION="2.5.22" `
WIN_FLEX_BISON_HOME="C:\WinFlexBison" `
WIN_FLEX_BISON_DOWNLOAD_URL="https://github.com/lexxmark/winflexbison/releases/download"
Expand Down Expand Up @@ -169,17 +189,16 @@ COPY . /src/
ARG BUILD_PARALLEL=1
SHELL ["cmd", "/S", "/C"]
RUN call "%MSVS_HOME%\VC\Auxiliary\Build\vcvars64.bat" && `
cmake -G "NMake Makefiles" `
cmake -G "Ninja" `
-DOPENSSL_ROOT_DIR='C:\dev\vcpkg\packages\openssl_x64-windows-static' `
-DFLB_LIBYAML_DIR='C:\dev\vcpkg\packages\libyaml_x64-windows-static' `
-DFLB_SIMD=On `
-DCMAKE_BUILD_TYPE=Release `
-DFLB_SHARED_LIB=Off `
-DFLB_EXAMPLES=Off `
-DFLB_DEBUG=Off `
-DFLB_RELEASE=On `
..\ && `
cmake --build . --config Release -j "%BUILD_PARALLEL%"
cmake --build . -j "%BUILD_PARALLEL%"

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

Expand Down
25 changes: 19 additions & 6 deletions lib/onigmo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,40 @@ endif()

# Update CFLAGS
if (MSVC)
# Use static C runtime
if (NOT (CMAKE_VERSION VERSION_LESS "3.15"))
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
add_compile_options(/MT$<$<CONFIG:Debug>:d>)
# Replace (/|-)MD(d?) with (/|-)MT(d?) to avoid D9025 warning
foreach(config_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug Release RelWithDebInfo MinSizeRel)
string(TOUPPER ${config_type} upper_config_type)
set(flag_var "CMAKE_C_FLAGS_${upper_config_type}")
string(REGEX REPLACE "(^| |\\t|\\r|\\n)(-|/)(MD)(d?)($| |\\t|\\r|\\n)" "\\1\\2MT\\4\\5" ${flag_var} "${${flag_var}}")
endforeach()
set(flag_var)
set(upper_config_type)
set(config_type)

# Make compiler aware of source code using UTF-8 encoding
add_compile_options(/utf-8)

add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)

# Use custom CFLAGS for MSVC
#
# /Zi ...... Generate pdb files.
# /MT ...... Static link C runtimes.
# /wd4711 .. C4711 (function selected for inline expansion)
# /wd4100 .. C4100 (unreferenced formal parameter)
# /wd5045 .. C5045 (Spectre mitigation)
#
set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /DNDEBUG /O2 /Zi /wd4100 /wd4711 /wd5045")
set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /Zi /wd4100 /wd4711 /wd5045")
set(CMAKE_EXE_LINKER_FLAGS "/Debug /INCREMENTAL:NO")
set(CMAKE_BUILD_TYPE None)

# We need this line in order to link libonigmo.lib statically.
# Read onigmo/README for details.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DEXPORT -DHAVE_CONFIG_H")
# Use add_compile_options() to set /MT since Visual Studio
# Generator does not notice /MT in CMAKE_C_FLAGS.
add_compile_options(/MT)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
endif()
Expand Down
Loading