diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ac7f77..4779daa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] build_type: [Debug, Release] include: - os: ubuntu-latest @@ -20,6 +20,9 @@ jobs: - os: macos-latest cc: clang cxx: clang++ + - os: windows-latest + cc: cl + cxx: cl runs-on: ${{ matrix.os }} @@ -39,12 +42,25 @@ jobs: brew install clang-format zstd libsodium || true # cmake is already available on macOS runners + - name: Install dependencies (Windows) + if: matrix.os == 'windows-latest' + run: | + # Install vcpkg dependencies + vcpkg install zstd:x64-windows libsodium:x64-windows + # Visual Studio Build Tools are already available + - name: Set up environment run: | echo "CC=${{ matrix.cc }}" >> $GITHUB_ENV echo "CXX=${{ matrix.cxx }}" >> $GITHUB_ENV - - name: Configure CMake + - name: Configure CMake (Windows) + if: matrix.os == 'windows-latest' + shell: cmd + run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DBFC_WITH_ZSTD=ON -DBFC_WITH_SODIUM=ON + + - name: Configure CMake (Unix) + if: matrix.os != 'windows-latest' run: | cmake -B build \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ @@ -53,16 +69,30 @@ jobs: -DBFC_WITH_ZSTD=ON \ -DBFC_WITH_SODIUM=ON - - name: Build + - name: Build (Windows) + if: matrix.os == 'windows-latest' + shell: cmd + run: cmake --build build --config ${{ matrix.build_type }} --parallel + + - name: Build (Unix) + if: matrix.os != 'windows-latest' run: cmake --build build --config ${{ matrix.build_type }} -j$(nproc 2>/dev/null || sysctl -n hw.ncpu) - - name: Run tests - if: matrix.build_type == 'Debug' + - name: Run tests (Windows) + if: matrix.build_type == 'Debug' && matrix.os == 'windows-latest' + shell: cmd + run: | + cd build + ctest --output-on-failure --parallel --config ${{ matrix.build_type }} + + - name: Run tests (Unix) + if: matrix.build_type == 'Debug' && matrix.os != 'windows-latest' run: | cd build ctest --output-on-failure --parallel $(nproc 2>/dev/null || sysctl -n hw.ncpu) - name: Test CLI functionality + if: matrix.os != 'windows-latest' run: | # Create test data mkdir -p test_data @@ -219,6 +249,7 @@ jobs: rm -rf test_encrypted.bfc test_keyfile.bfc test_enc_comp.bfc test.key - name: Run benchmarks + if: matrix.os != 'windows-latest' run: | cd build/benchmarks ./benchmark_crc32c diff --git a/src/lib/bfc_crc32c.c b/src/lib/bfc_crc32c.c index c3e8ea9..5fbbe4e 100644 --- a/src/lib/bfc_crc32c.c +++ b/src/lib/bfc_crc32c.c @@ -19,7 +19,11 @@ #include #if defined(__x86_64__) || defined(_M_X64) +#ifdef _WIN32 +#include +#else #include +#endif #include #define HAS_X86_64 1 #elif defined(__aarch64__) || defined(_M_ARM64) @@ -52,10 +56,17 @@ static void init_crc32c_table(void) { #ifdef HAS_X86_64 static int detect_sse42_support(void) { unsigned int eax, ebx, ecx, edx; +#ifdef _WIN32 + int cpuinfo[4]; + __cpuid(cpuinfo, 1); + ecx = cpuinfo[2]; + return (ecx & (1 << 20)) != 0; // SSE4.2 bit +#else if (__get_cpuid(1, &eax, &ebx, &ecx, &edx)) { return (ecx & bit_SSE4_2) != 0; } return 0; +#endif } static uint32_t crc32c_hw_x86(uint32_t crc, const void* data, size_t len) { diff --git a/src/lib/bfc_os.h b/src/lib/bfc_os.h index 7ccac47..b24ff04 100644 --- a/src/lib/bfc_os.h +++ b/src/lib/bfc_os.h @@ -21,7 +21,17 @@ #include #ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include #include +// Define missing POSIX constants for Windows +#ifndef S_IFLNK +#define S_IFLNK 0120000 // Symbolic link file type +#endif +// Define missing POSIX types for Windows +#ifndef ssize_t +typedef SSIZE_T ssize_t; +#endif #else #include #include diff --git a/src/lib/bfc_reader.c b/src/lib/bfc_reader.c index 7e842ab..4571f96 100644 --- a/src/lib/bfc_reader.c +++ b/src/lib/bfc_reader.c @@ -25,7 +25,12 @@ #include #include #include +#ifdef _WIN32 +#include +#define access _access +#else #include +#endif #define READ_BUFFER_SIZE 65536