microsoft / microsoft/BitNet

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

Open
#493 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
40.3k
Forks
3.7k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with setup_env.py and inspect compile() and its platform-specific CMake arguments, then review the reported assignment near line 811 in src/ggml-bitnet-mad.cpp. Run setup_env.py on Windows with the stated ClangCL configuration; done means CMake configuration and the Release build complete without either reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, python
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.