You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Types::collect(), the cxx crate checks for duplicate definitions of Rust identifiers.
This works for the proc macro (which is run per mod) but causes issues for the build script as it operates on a file level, gathering all APIs across all mods in the file. Thus, if the same type alias is declared in multiple mods in the same file then the build script will raise an error despite there being no issue with being able to generate the final C++ code.
error[cxxbridge]: the name `MyStruct` is defined multiple times
┌─ src/lib.rs:20:9
│
20 │ type MyStruct = crate::MyStruct;
│ ^^^^^^^^^^^^^ the name `MyStruct` is defined multiple times
Why do you need this?
APIs in an extern "C++" block may only reference types that are built-in to cxx and other types in the same mod, thus it is pretty reasonable to need to access the same type via an alias across multiple mods in the same file.
Possible fixes
The simplest fix would be to disable checking when calling Types::collect from the build script - but this would drop other checks that may still be valuable.
I believe the correct fix is to use a different set of checking logic instead - the current logic is only looking at Rust names and so isn't validating that the C++ names being emitted are not duplicated. Types::collect should add a parameter to indicate if the Rust or C++ names should be checked, and then perform the appropriate checks.
The text was updated successfully, but these errors were encountered:
In
Types::collect()
, the cxx crate checks for duplicate definitions of Rust identifiers.This works for the proc macro (which is run per
mod
) but causes issues for the build script as it operates on a file level, gathering all APIs across allmod
s in the file. Thus, if the same type alias is declared in multiplemod
s in the same file then the build script will raise an error despite there being no issue with being able to generate the final C++ code.Example
For :
Building this will cause an error to be raised
Why do you need this?
APIs in an
extern "C++"
block may only reference types that are built-in tocxx
and other types in the samemod
, thus it is pretty reasonable to need to access the same type via an alias across multiplemod
s in the same file.Possible fixes
The simplest fix would be to disable checking when calling
Types::collect
from the build script - but this would drop other checks that may still be valuable.I believe the correct fix is to use a different set of checking logic instead - the current logic is only looking at Rust names and so isn't validating that the C++ names being emitted are not duplicated.
Types::collect
should add a parameter to indicate if the Rust or C++ names should be checked, and then perform the appropriate checks.The text was updated successfully, but these errors were encountered: