Skip to content

Conversation

@eramongodb
Copy link
Contributor

@eramongodb eramongodb commented Oct 31, 2025

Related to CDRIVER-6085. Applies IWYU export pragmas to component headers in mongo-c-driver. Companion PR to mongodb/mongo-cxx-driver#1492.

To avoid potentially breaking downstream users, no include directives are removed by changes in this PR. However, component header includes are reordered to the top, with necessary fixes applied to impacted downstream components. These include:

  • <bson/bson.h>: missing <bson/bson_t.h> and <bson/error.h> (see: [CDRIVER-4153] Beginning of Header Hygiene & Verification #2053)
  • <bson/bson-vector.h>: missing <bson/bson_t.h> and <bson/bson-types.h>
  • <mongoc/mongoc-topology-description.h>: missing <mongoc/mongoc-server-description.h>.
  • <mongoc/mongoc-stream-tls-secure-transport.h>: missing <mongoc/mongoc-ssl.h> and <mongoc/mongoc-stream.h>.

(Aside: bson-private.h should probably be renamed to bson-types-private.h for consistency?)

Additionally, the bson-config.h header is exported by bson-macros.h and bson-compat.h, and bson-macros.h is exported by bson-compat.h. This is due to the global nature of these headers in providing system-defined entities (types, functions, macros, etc.). The various stdlib and system includes in bson-compat.h which are currently marked as "unused" by IWYU are left as-is (to avoid potentially breaking downstream users) and do not have the IWYU export pragma applied.

Note

Although IWYU supports the "private" pragma to denote private component headers which require the separate inclusion of the corresponding public header, this PR proposes we avoid this pattern in favor of supporting standalone-includable headers whenever able, even for private headers, by ensuring the corresponding public header is first included by the private header.

With the changes in this PR, the IWYU tool (via clangd or otherwise) may be used to start properly addressing "Condition 1" in CDRIVER-6085 via missing-header and unused-header diagnostics.

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