Skip to content
Closed
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
41 changes: 36 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +20,9 @@ jobs:
- os: macos-latest
cc: clang
cxx: clang++
- os: windows-latest
cc: cl
cxx: cl

runs-on: ${{ matrix.os }}

Expand All @@ -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 }} \
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/lib/bfc_crc32c.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
#include <string.h>

#if defined(__x86_64__) || defined(_M_X64)
#ifdef _WIN32
#include <intrin.h>
#else
#include <cpuid.h>
#endif
#include <immintrin.h>
#define HAS_X86_64 1
#elif defined(__aarch64__) || defined(_M_ARM64)
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/bfc_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@
#include <stdio.h>

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <sys/stat.h>
#include <windows.h>
// 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 <sys/types.h>
#include <unistd.h>
Expand Down
5 changes: 5 additions & 0 deletions src/lib/bfc_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#ifdef _WIN32
#include <io.h>
#define access _access
#else
#include <unistd.h>
#endif

#define READ_BUFFER_SIZE 65536

Expand Down
Loading