Skip to content

Commit 327e7a3

Browse files
authored
Native Windows support (#102)
This pull request introduces support for native Windows by adding Windows-specific implementations and conditional compilation to various parts of the codebase. The changes ensure compatibility with Windows systems while maintaining functionality on other platforms. ### Build System Updates: * Added a Windows runner (`windows-latest`) to the GitHub Actions workflow in `.github/workflows/cmake.yml`. Updated CMake configuration, build, and test steps to handle Windows-specific paths and commands. ### Codebase Updates for Windows Compatibility: * **CMake Adjustments**: Introduced conditional flags for MSVC in `cmake/CXXSniffer.cmake` to set appropriate compiler flags for Windows (`/W4`) versus other platforms (`-Wall -Wextra`). * **Datetime Handling**: Updated `Datetime::timegm` in `src/Datetime.cpp` to use `_putenv_s` and `_tzset` for setting the time zone on Windows. [[1]](diffhunk://#diff-87bf33523de4b0db7b37702262674dbf849e9f79686761c334c1cd04412b295eR3127-R3136) [[2]](diffhunk://#diff-87bf33523de4b0db7b37702262674dbf849e9f79686761c334c1cd04412b295eR3145) ### Filesystem (`FS.cpp`) Enhancements: * **Platform-Specific Includes and Macros**: Added Windows-specific headers and macros for filesystem operations, such as `_mkdir`, `_unlink`, and `FlushFileBuffers`. [[1]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR37-L45) [[2]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR74-R83) * **Path Operations**: Implemented Windows-specific logic for `Path::realpath`, `Path::expand`, and `Path::glob` to handle Windows paths and environment variables like `USERPROFILE`. [[1]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR181-R211) [[2]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR358-R388) [[3]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR426) [[4]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR437-R441) * **File and Directory Operations**: Added Windows-compatible implementations for file creation, removal, locking, unlocking, truncating, and directory operations like `create` and `remove_directory`. [[1]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR509-R511) [[2]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR522-R526) [[3]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR773-R779) [[4]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR1049-R1053) [[5]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR1065) [[6]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR1212) [[7]](diffhunk://#diff-46a62fa5a3343b36a9aae12dd7292196103643bcbee4e56901c9ed12ee8f87abR1251-R1275) ### Header File Updates: * Updated `src/FS.h` to include Windows-specific headers and define `mode_t` for compatibility. These changes collectively enable the codebase to function seamlessly on Windows platforms while preserving its behavior on Unix-like systems.
1 parent 121f757 commit 327e7a3

File tree

9 files changed

+328
-21
lines changed

9 files changed

+328
-21
lines changed

.github/workflows/cmake.yml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,40 @@ jobs:
2222
runner: macos-14
2323
- name: "macOS 13"
2424
runner: macos-13
25+
- name: "Windows"
26+
runner: windows-latest
2527
runs-on: ${{ matrix.runner }}
2628

2729
steps:
28-
- uses: actions/checkout@v4
30+
- uses: actions/checkout@v4
2931

30-
# Configure in-source build and tests
31-
- name: Configure CMake
32-
run: cmake -S . -B . -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
32+
# Configure in-source build and tests
33+
- name: Configure CMake
34+
shell: bash
35+
run: |
36+
if [ "$RUNNER_OS" = "Windows" ]; then
37+
cmake -S . -B build -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
38+
else
39+
cmake -S . -B . -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
40+
fi
3341
34-
- name: Build project
35-
run: cmake --build .
42+
- name: Build project
43+
shell: bash
44+
run: |
45+
if [ "$RUNNER_OS" = "Windows" ]; then
46+
cmake --build build
47+
else
48+
cmake --build .
49+
fi
3650
37-
- name: Test project
38-
run: make test
51+
- name: Test project
52+
shell: bash
53+
run: |
54+
if [ "$RUNNER_OS" = "Windows" ]; then
55+
cd build && ctest --output-on-failure
56+
else
57+
make test
58+
fi
3959
4060
integration-test:
4161
needs: build

cmake/CXXSniffer.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ else (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
2525
set (UNKNOWN true)
2626
endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
2727

28-
set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wsign-compare -Wreturn-type ${CMAKE_CXX_FLAGS}")
28+
if (NOT MSVC)
29+
set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wsign-compare -Wreturn-type ${CMAKE_CXX_FLAGS}")
30+
else()
31+
set (CMAKE_CXX_FLAGS "/W4 ${CMAKE_CXX_FLAGS}")
32+
endif()

src/Datetime.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,6 +3124,16 @@ time_t Datetime::timegm(struct tm* tm) {
31243124
time_t ret;
31253125
char* tz;
31263126
tz = getenv("TZ");
3127+
#ifdef _WIN32
3128+
_putenv_s("TZ", "UTC");
3129+
_tzset();
3130+
ret = mktime(tm);
3131+
if (tz)
3132+
_putenv_s("TZ", tz);
3133+
else
3134+
_putenv_s("TZ", "");
3135+
_tzset();
3136+
#else
31273137
setenv("TZ", "UTC", 1);
31283138
tzset();
31293139
ret = mktime(tm);
@@ -3132,6 +3142,7 @@ time_t Datetime::timegm(struct tm* tm) {
31323142
else
31333143
unsetenv("TZ");
31343144
tzset();
3145+
#endif
31353146
return ret;
31363147
}
31373148
#endif

0 commit comments

Comments
 (0)