Skip to content

feat(windows): add full Windows/MSVC support#11

Merged
zombocoder merged 17 commits into
mainfrom
feature/windows-support
Apr 30, 2026
Merged

feat(windows): add full Windows/MSVC support#11
zombocoder merged 17 commits into
mainfrom
feature/windows-support

Conversation

@sashml
Copy link
Copy Markdown
Collaborator

@sashml sashml commented Apr 28, 2026

Summary

Closes #9 — full Windows/MSVC build support for bfc, built on top of the existing feature/windows-support partial work.

  • New compat headers: bfc_win32_compat.h (lib) and cli_win32_compat.h (CLI) — full POSIX shims replacing inline definitions
  • SSE4.2 detection: unified #if defined(_MSC_VER) || defined(_WIN32) covering both MSVC and MinGW
  • MSVC warning fixes: C4206 (empty TU), C4244 (narrowing), C4267 (size_t conversions), C4456 (shadowing), C4100 (unused params), C4702 (unreachable code)
  • CMakeLists.txt: MSVC flags block (/W4 /WX /wd4996, _CRT_SECURE_NO_WARNINGS)
  • CI: Windows configure step uses $env:VCPKG_INSTALLATION_ROOT (not hardcoded path), PowerShell syntax, unified test step
  • Release workflow: bfc-<version>-windows-x86_64.zip with bfc.exe, bfc.lib, headers, install.bat
  • Test fixes: pre-existing assertion bug in test_reader.c; ZSTD-guard pattern fixed for MSVC C4702
  • README: Windows build instructions, prerequisites

Test plan

  • 10/10 unit tests pass on Windows (MSVC 19.x): ctest -C Debug100% tests passed
  • Clean build — zero /W4 /WX warnings
  • CI matrix green on windows-latest
  • Linux/macOS CI jobs unaffected

zombocoder and others added 5 commits October 16, 2025 18:43
- Add bfc_win32_compat.h with POSIX shims (ssize_t, usleep, clock_gettime,
  S_IS* macros, fseeko/ftello, mkdir, fileno)
- Add cli_win32_compat.h for CLI-layer POSIX shims (getopt, fnmatch,
  dirent, symlink stubs)
- Fix MSVC warnings-as-errors: C4206 (empty TU), C4244 (narrowing),
  C4267 (size_t conversions), C4456 (variable shadowing), C4100 (unused params),
  C4702 (unreachable code after ZSTD guard)
- Update CMakeLists.txt with MSVC /W4 /WX flags and _CRT_SECURE_NO_WARNINGS
- Add GitHub Actions CI matrix for windows-latest with vcpkg (zstd, libsodium)
- Add Windows release workflow with ZIP packaging and install.bat
- Fix test_reader.c pre-existing assertion bug (wrong expected string in
  partial-read test)
- Guard ZSTD-only test functions with #ifdef BFC_WITH_ZSTD body wrapping
- Update README with Windows build instructions
- Guard POSIX-only includes in benchmarks and examples with #ifndef _WIN32
- Add <sys/stat.h> to cli.h for Linux/macOS (S_ISSOCK, S_ISVTX missing)
- Suppress unused verify_entry_callback warning (pragma+attribute, all platforms)
- Guard <unistd.h> in encrypt_example.c with #ifndef _WIN32
- Map getpid to _getpid in bfc_win32_compat.h for Windows test_encrypt.c
@sashml sashml marked this pull request as ready for review April 28, 2026 06:43
@sashml sashml requested a review from zombocoder April 28, 2026 06:43
sashml added 6 commits April 28, 2026 09:39
- Set up MSVC vcvarsall + cmake + ninja for Windows via aminya/setup-cpp@v1
- Use unified shell: bash for configure, test, and Windows CLI steps
- Fix Windows env var references to bash-style ($VCPKG_INSTALLATION_ROOT)
- Convert Windows CLI test from PowerShell to bash (find bfc.exe)
…ions

- Remove global -D_GNU_SOURCE from CMakeLists (source files already define it);
  add guarded #define _GNU_SOURCE in cli.h before sys/stat.h for Linux S_ISSOCK
- Fix TOCTOU in create_parent_directories: use mkdir+EEXIST instead of stat+mkdir
- Fix TOCTOU in extract_file: remove upfront stat, use O_EXCL/O_NOFOLLOW atomically
- Fix TOCTOU in extract_directory: replace path-based chmod/utimensat with
  fd-based fchmod/futimens after opening directory with O_RDONLY|O_DIRECTORY
…rgets

- Linux/CLI: move _GNU_SOURCE to target_compile_definitions in CLI CMakeLists
  so it precedes all system headers (fixes S_ISSOCK/S_ISVTX undeclared)
- macOS: add _DARWIN_C_SOURCE in bfc_os.c to expose fdatasync under clang
- Windows/encrypt_example: include bfc_win32_compat.h for S_ISREG/open/close/mkdir;
  add src/lib to encrypt_example include path
- GCC: increase subdir_path/file_path buffer sizes in benchmark_writer.c
  to silence -Werror=format-truncation
- Remove #define _GNU_SOURCE from cmd_create.c and cmd_extract.c;
  CMake target_compile_definitions provides it for Linux without conflict
- Add #include <process.h> to bfc_win32_compat.h to declare _getpid
- Use fsync() fallback for bfc_os_sync() on macOS instead of fdatasync()
  (fdatasync availability under strict C17 is unreliable on macOS clang)
Comment thread src/cli/cmd_extract.c Fixed
sashml and others added 5 commits April 28, 2026 12:24
…hang

- Add O_BINARY flag to open() in test_end_to_end_encryption for the
  second extraction (line 386 was missing it, unlike line 364 which had it);
  without O_BINARY on Windows text-mode open converts LF->CRLF causing
  size mismatch assertion
- Suppress Windows assert() dialog box in test_main.c using _CrtSetReportMode
  so assertion failures print to stderr and exit instead of hanging on CI
On POSIX, replace the stat(path)+open(path) sequence with a single
open(O_RDONLY|O_DIRECTORY|O_NOFOLLOW) probe. Branch on errno instead:
- fd >= 0   → directory exists, update metadata via fd (fchmod/futimens)
- ENOENT    → create parent dirs then mkdir
- ENOTDIR/ELOOP → non-dir or symlink at path; unlink if -f, then mkdir
- other     → hard error

Windows path retains stat-based logic (O_DIRECTORY/O_NOFOLLOW unavailable).

Resolves GitHub Advanced Security CodeQL TOCTOU alert at cmd_extract.c:288.
@zombocoder zombocoder merged commit 422c669 into main Apr 30, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Windows support

3 participants