Skip to content

Change Compilation on Windows (Part II)#22650

Draft
thiagoftsm wants to merge 24 commits into
netdata:masterfrom
thiagoftsm:compile_on_windows
Draft

Change Compilation on Windows (Part II)#22650
thiagoftsm wants to merge 24 commits into
netdata:masterfrom
thiagoftsm:compile_on_windows

Conversation

@thiagoftsm
Copy link
Copy Markdown
Contributor

@thiagoftsm thiagoftsm commented Jun 7, 2026

Summary

Netdata is adjusting internal codes and compilation environment, allowing the source code to be compiled directly on Windows.

This PR gives the first step to achieve goal given in #22551: "Pivot the Windows build to MSYSTEM=UCRT64 so the C side of the agent matches the C runtime, data model, and CRT linkage of the Rust toolchain. Unblocks in-process Rust FFI on Windows and lets us drop the bundled MSYS2 root from the installer."

Test Plan
  1. Check CI, and verify everything works as expected on it.
  2. Also, compile on you local computer using msys.
Additional Information
For users: How does this change affect me?

Summary by cubic

Switch Windows builds to MSYS2 UCRT64 and drop all mingw64 paths. This unblocks Rust FFI and fixes Windows-specific build issues (Judy word size, syslog constants, libbacktrace, claim), while skipping POSIX-only tools.

  • Refactors

    • Enforce UCRT64 across helpers and CI: PowerShell wrappers set MSYSTEM=UCRT64; compile-and-run-windows.sh and msys2-dependencies.sh hard-check; compile-on-windows.sh auto-sets it and uses /ucrt64/bin/cmake.
    • Use UCRT64 toolchain paths: DDK headers at /ucrt64/include/ddk for the driver; FindGo searches /ucrt64/lib/go/bin (drop /mingw64).
    • Dev/tooling: CLion env switched to UCRT64; NetdataProtobuf finds protoc via PATH; libbacktrace config runs via bash; NetdataClaim links with -mwindows.
    • Skip POSIX-only helpers on Windows: do not build nd-run; do not require or build ndsudo (still used on POSIX). On Linux link libcap when available.
    • Fix Windows builds: Judy uses unsigned long long for Word_t on Win64 and casts masks/sentinels to Word_t; define syslog priority constants; alias wcscasecmp to _wcsicmp.
    • Harden Windows install prefix validation to require /opt/netdata.
    • Bundle libyaml with CMAKE_POLICY_VERSION_MINIMUM=3.5 for CMake 3.28+.
  • Migration

    • Build with MSYSTEM=UCRT64; ensure C:\msys64\ucrt64\bin is on PATH.
    • Install UCRT64 packages only, e.g. ucrt64/mingw-w64-ucrt-x86_64-go, ucrt64/mingw-w64-ucrt-x86_64-cmake, ucrt64/mingw-w64-ucrt-x86_64-curl, ucrt64/mingw-w64-ucrt-x86_64-nsis, ucrt64/mingw-w64-ucrt-x86_64-libyaml, ucrt64/mingw-w64-ucrt-x86_64-zstd.

Written for commit 914d74c. Summary will update on new commits.

Review in cubic

@thiagoftsm thiagoftsm requested review from a team, Ferroin and vkalintiris as code owners June 7, 2026 16:52
@github-actions github-actions Bot added area/packaging Packaging and operating systems support area/build Build system (autotools and cmake). labels Jun 7, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 12 files

Confidence score: 2/5

  • There is clear regression risk in CMakeLists.txt: BEFORE is placed incorrectly for target_include_directories, which can cause CMake parse/configuration failures.
  • packaging/windows/clion-msys-mingw64-environment.bat has a high-impact toolchain misconfiguration (GOROOT set to the MSYS2 prefix) that can make Go/CMake resolve the wrong root on Windows builds.
  • Given multiple medium/high-severity, high-confidence Windows build-path issues (MSYSTEM ordering, PATH precedence/quoting), this is not yet a safe merge without fixes.
  • Pay close attention to CMakeLists.txt, packaging/windows/clion-msys-mingw64-environment.bat, packaging/windows/compile-on-windows.sh, packaging/windows/clion-msys-msys-environment.bat - build/toolchain resolution can select incorrect binaries or fail configuration.
Architecture diagram
sequenceDiagram
    participant Dev as Developer Machine
    participant CI as CI/CD Pipeline
    participant MSYS as MSYS2 Shell
    participant CMake as CMake Build System
    participant Go as Go Toolchain
    participant DDK as Windows DDK Headers
    participant NSIS as NSIS Installer

    Note over Dev,NSIS: NEW: UCRT64 Build Environment on Windows

    Dev->>MSYS: Run compile-on-windows.sh / build.ps1
    MSYS->>MSYS: validate MSYSTEM=UCRT64
    MSYS->>MSYS: set MSYSTEM=UCRT64 (if not set)

    CI->>MSYS: Run install-dependencies.ps1
    MSYS->>MSYS: set MSYSTEM=UCRT64
    MSYS->>MSYS: invoke-msys2.ps1 with MSYSTEM=UCRT64
    MSYS->>MSYS: install only ucrt64/* packages (no mingw64)

    MSYS->>CMake: cmake -DCMAKE_BUILD_TYPE=...
    CMake->>CMake: NetdataPlatform.cmake - detect MSYSTEM=UCRT64
    alt MSYSTEM=UCRT64
        CMake->>CMake: include ucrt64 headers
    else MSYSTEM=MSYS
        CMake->>CMake: include msys headers
    else other (MINGW64 removed)
        CMake->>CMake: skip (no mingw64 include path)
    end

    Note over CMake,DDK: Driver compilation with UCRT64 DDK headers

    CMake->>CMake: locate DDK headers
    CMake->>DDK: target_include_directories(/ucrt64/include/ddk)
    DDK-->>CMake: provide driver headers
    CMake->>CMake: compile netdata_driver.sys

    Note over CMake,Go: Go toolchain discovery with UCRT64 priority

    CMake->>Go: find_program(go PATHS ... /ucrt64/lib/go/bin ...)
    Go-->>CMake: return go executable path

    Note over MSYS,NSIS: Packaging with UCRT64 NSIS

    MSYS->>NSIS: package.ps1 (MSYSTEM=UCRT64)
    NSIS-->>MSYS: create installer using ucrt64/mingw-w64-ucrt-x86_64-nsis

    Note over Dev,CI: CLion IDE configuration

    Dev->>Dev: configure CLion toolchain
    Dev->>Dev: set MSYSTEM=UCRT64
    Dev->>Dev: set GOROOT=C:\msys64\ucrt64
    Dev->>Dev: set PATH includes C:\msys64\ucrt64\bin
    Dev->>Dev: set PROTOBUF_PROTOC_EXECUTABLE=C:/msys64/ucrt64/bin/protoc.exe

    Note over MSYS: Validation gates

    alt MSYSTEM != UCRT64 in compile-and-run-windows.sh
        MSYS->>MSYS: exit 1 with error message
    end

    alt MSYSTEM != UCRT64 in msys2-dependencies.sh
        MSYS->>MSYS: exit 1 with error message
    end

    MSYS-->>Dev: build output (exe, sys, installer)
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread CMakeLists.txt Outdated
Comment thread packaging/windows/clion-msys-mingw64-environment.bat Outdated
Comment thread packaging/windows/compile-on-windows.sh
Comment thread packaging/windows/clion-msys-mingw64-environment.bat Outdated
Comment thread packaging/windows/clion-msys-msys-environment.bat Outdated
@thiagoftsm thiagoftsm marked this pull request as draft June 7, 2026 22:42
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread src/libnetdata/libjudy/vendored/Judy.h
@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Jun 8, 2026

You're iterating quickly on this pull request. To help protect your rate limits, cubic has paused automatic reviews on new pushes for now—when you're ready for another review, comment @cubic-dev-ai review.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 8, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build Build system (autotools and cmake). area/claim area/packaging Packaging and operating systems support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant