Skip to content

fix: work around problems with /Zi argument on windows.#1483

Merged
novas0x2a merged 1 commit intomainfrom
novas0x2a-fix-windows-dbg
Mar 13, 2026
Merged

fix: work around problems with /Zi argument on windows.#1483
novas0x2a merged 1 commit intomainfrom
novas0x2a-fix-windows-dbg

Conversation

@novas0x2a
Copy link
Copy Markdown
Collaborator

/Zi is not multiprocess-safe; it depends on spinning up an mspdbsrv.exe and interacting with it in unsafe ways. When multiple CMake targets build in parallel on Windows, this causes "PDB API call failed" (C1090) errors.

CMake's default debug flags can include /Zi. Bazel's MSVC toolchain already passes /Z7 (embed debug info in .obj), but CMake's /Zi overrides it. CMake added a better way to interact with this configuration in 3.25 with CMP0141.

So, my change does two things:

  1. Sets the default CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to Embedded, which is the equivalent of /Z7.
  2. Replaces /Zi (if found) in cmake's flags for Debug and RelWithDebInfo. (/Zi should only be present here if a project overrides the DEBUG_INFORMATION_FORMAT or if they're on an older cmake).

/Zi is not multiprocess-safe; it depends on spinning up an mspdbsrv.exe
and interacting with it in unsafe ways.

CMake's default debug flags can include /Zi, which uses a shared PDB file
via mspdbsrv.exe. When multiple CMake targets build in parallel on
Windows, this causes "PDB API call failed" (C1090) errors. Bazel's MSVC
toolchain already passes /Z7 (embed debug info in .obj), but CMake's /Zi
overrides it.

CMake added a better way to interact with this configuration in 3.25
with [CMP0141](https://cmake.org/cmake/help/latest/policy/CMP0141.html).

So, my change does two things:
1. Sets the default `CMAKE_MSVC_DEBUG_INFORMATION_FORMAT` to `Embedded`,
   which is the equivalent of /Z7.
2. Replaces /Zi (if found) in cmake's default flags for `Debug` and
   `RelWithDebInfo`. (/Zi should only be present here if a project
   overrides the DEBUG_INFORMATION_FORMAT or if they're on an older
   cmake).

This makes it extremely likely /Zi will not be used unless it is the
explicit intention of the rules_foreign_cc user.
@novas0x2a novas0x2a merged commit 68d3c20 into main Mar 13, 2026
5 checks passed
@novas0x2a novas0x2a deleted the novas0x2a-fix-windows-dbg branch March 13, 2026 07:02
rdesgroppes added a commit to DataDog/datadog-agent that referenced this pull request Mar 19, 2026
Moving the unreleased tip of main allows to address Bazel 9 related
issues instead of patching locally:
- bazel-contrib/rules_foreign_cc#1493
- bazel-contrib/rules_foreign_cc#1492

Other notable commits since:
- bazel-contrib/rules_foreign_cc#1483
- bazel-contrib/rules_foreign_cc#1490
- bazel-contrib/rules_foreign_cc#1496

Patches 0002 (DY/LD_LIBRARY_PATH) and 0003 (-j on make command line) are
still carried locally as neither has landed upstream yet (but we're
working on it).
rdesgroppes added a commit to DataDog/datadog-agent that referenced this pull request Mar 21, 2026
Moving the unreleased tip of main allows to address Bazel 9 related
issues instead of patching locally:
- bazel-contrib/rules_foreign_cc#1493
- bazel-contrib/rules_foreign_cc#1492

Other notable commits since:
- bazel-contrib/rules_foreign_cc#1483
- bazel-contrib/rules_foreign_cc#1490
- bazel-contrib/rules_foreign_cc#1496

Patches 0002 (DY/LD_LIBRARY_PATH) and 0003 (-j on make command line) are
still carried locally as neither has landed upstream yet (but we're
working on it).
gh-worker-dd-mergequeue-cf854d bot pushed a commit to DataDog/datadog-agent that referenced this pull request Mar 21, 2026
Depends on #48082.

### Motivation
Moving the unreleased tip of main allows to address Bazel 9 related issues instead of patching locally:
- bazel-contrib/rules_foreign_cc#1493
- bazel-contrib/rules_foreign_cc#1492 (`CcInfo` and other `Cc*` symbols)

Other notable commits since:
- bazel-contrib/rules_foreign_cc#1483
- bazel-contrib/rules_foreign_cc#1490
- bazel-contrib/rules_foreign_cc#1496

### Additional Notes
Patches 0002 (bazel-contrib/rules_foreign_cc#1452) and 0003 (bazel-contrib/rules_foreign_cc#1491) are still carried locally as neither has landed upstream yet (but we're working on it).

Co-authored-by: regis.desgroppes <regis.desgroppes@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant