Skip to content

[Bug] Windows build fails: CMake logic errors and missing const in ggml-bitnet-mad.cpp #493

@giorgeor

Description

@giorgeor

When running setup_env.py on Windows to build BitNet, the setup and compilation fail due to two specific bugs.

First, setup_env.py passes hardcoded clang and clang++ paths to CMake, which conflicts with the -T ClangCL toolset flag on Windows. Second, once CMake succeeds, compilation fails because of a missing const qualifier in src/ggml-bitnet-mad.cpp.

Bug 1: setup_env.py CMake compiler arguments

Issue: In setup_env.py, the compile() function appends -DCMAKE_C_COMPILER=clang and -DCMAKE_CXX_COMPILER=clang++ universally. When building on Windows using the -T ClangCL toolset flag, explicitly setting the compiler path confuses CMake and MSBuild, causing the configuration to fail with The C compiler identification is unknown.

Fix: The hardcoded compiler flags should only be passed on non-Windows platforms.

In setup_env.py, updating the compile() function fixes this:

    # ... setup code ...
    if platform.system() == "Windows":
        run_command(["cmake", "-B", "build", *COMPILER_EXTRA_ARGS[arch], "-T", "ClangCL"], log_step="generate_build_files")
    else:
        run_command(["cmake", "-B", "build", *COMPILER_EXTRA_ARGS[arch], *OS_EXTRA_ARGS.get(platform.system(), []), "-DCMAKE_C_COMPILER=clang", "-DCMAKE_CXX_COMPILER=clang++"], log_step="generate_build_files")
    
    run_command(["cmake", "--build", "build", "--config", "Release"], log_step="compile")

Bug 2: Missing const qualifier in ggml-bitnet-mad.cpp

Issue: Once CMake configuration succeeds, building with MSBuild/ClangCL fails with the following error:

src\ggml-bitnet-mad.cpp(811,18): error : cannot initialize a variable of type 'int8_t *' (aka 'signed char *') with an rvalue of type 'const int8_t *' (aka 'const signed char *')

Fix: Around line 811 in src/ggml-bitnet-mad.cpp, y_col is assigned a const pointer but lacks the const keyword.

Change this:
int8_t * y_col = y + col * by;

To this:
const int8_t * y_col = y + col * by;

Environment Details
OS: Windows 11
Compiler: ClangCL via Visual Studio 2026 Build Tools
Model / Quantization: Tested with -md models/BitNet-b1.58-2B-4T -q i2_s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions