Skip to content

cpp: Add an include guard to wit.h - #1797

Open
cpetig wants to merge 1 commit into
bytecodealliance:mainfrom
cpetig:upstream-wit-h-guard
Open

cpetig wants to merge 1 commit into
bytecodealliance:mainfrom
cpetig:upstream-wit-h-guard

Conversation

@cpetig

@cpetig cpetig commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

wit.h is emitted into the output directory of every set of generated C++
bindings. If two such directories are on the include path (for example when a
component uses the bindings of several worlds), #pragma once does not stop
the second copy from being parsed, as it is a different file, and the types in
wit.h are redefined. Add a classic WIT_BINDGEN_WIT_H_DEFINED include guard
next to #pragma once.

Tested with cargo run -- test --languages rust,c,cpp ... tests/runtime/simple-future tests/runtime/strings.

`wit.h` is emitted into the output directory of every generated set of
bindings. When two such directories are on the include path, `#pragma once`
does not prevent the second copy from being processed, as the files are
different, which results in redefinition errors. Add a classic include
guard in addition.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cpetig cpetig added the gen-cpp Related to the C++ code generator label Nov 28, 2026
@@ -1,4 +1,6 @@
#pragma once

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the #pragma once still necessary with an ifdef guard?

This branch has not been deployed

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

Labels

gen-cpp Related to the C++ code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants