Skip to content

Windows CI failing with Rust 1.91: libgit2_sys linking errors via vergen-git2 #3914

@jolestar

Description

@jolestar

Problem

Windows CI builds are failing after upgrading to Rust 1.91.1 with unresolved external symbol errors from libgit2_sys.

Error Details

liblibgit2_sys-bd82eeea6732340b.rlib(f6e81ea219c0b9f3-fs_path.o) : error LNK2019: unresolved external symbol __imp_OpenProcessToken referenced in function current_user_sid
liblibgit2_sys-bd82eeea6732340b.rlib(f6e81ea219c0b9f3-fs_path.o) : error LNK2019: unresolved external symbol __imp_CheckTokenMembership referenced in function git_fs_path_owner_is
liblibgit2_sys-bd82eeea6732340b.rlib(f6e81ea219c0b9f3-rand.o) : error LNK2019: unresolved external symbol __imp_CryptAcquireContextA referenced in function getseed
...
fatal error LNK1120: 15 unresolved externals

All missing symbols are from Windows API:

  • advapi32.lib: Registry APIs, Token management, SID operations
  • crypt32.lib: Cryptographic functions

Root Cause

  1. Dependency Chain: vergen-git2libgit2-syslibgit2 (C library)
  2. Build Script Issue: The linking errors occur in the build script compilation phase, not the main binary
  3. Chicken-and-Egg Problem:
    • Build scripts need to link libgit2_sys to compile
    • But linking instructions in build.rs only affect the main binary, not build scripts
    • Cannot add system libraries via cargo:rustc-link-lib in build.rs because build.rs hasn't compiled yet

Current Workaround

Temporarily disabled Windows CI in cross-platform checks (PR #3899).

Potential Solutions

Option 1: Use Static Linking for libgit2

[dependencies.vergen-git2]
features = ["git", "git2"]  # Use bundled git

Option 2: Replace vergen-git2

Alternative crates that don't depend on libgit2:

  • vergen (older version without git2 dependency)
  • vergen-lib (lightweight alternative)
  • Build version info at release time only

Option 3: Conditional Compilation

#[cfg(not(target_os = "windows"))]
use vergen_git2::{...};

#[cfg(target_os = "windows")]
// Use alternative versioning strategy

Option 4: Use vcpkg for libgit2 on Windows

Set up vcpkg to provide pre-built libgit2 with correct system library dependencies.

Option 5: Fix in vergen-git2/libgit2-sys Upstream

  • File issue with vergen-git2 repo
  • Ensure proper Windows system library linkage in build scripts
  • May require changes to libgit2-sys build configuration

Investigation Needed

  1. Test vergen-git2 with different feature flags
  2. Try alternative versioning crates
  3. Check if newer libgit2-sys version fixes Windows linking
  4. Evaluate impact of removing git info from Windows builds

Related

Priority

Medium - Windows CI is blocked but Linux/macOS builds work fine. Windows developers can still build locally using different configurations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions