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
I tried to use a Shared type from one module inside another module, but have a quite strange error message:
error: `extern` block uses type `std::string::String`, which is not FFI-safe
--> linkage-test/src/two.rs:12:31
|
12 | fn IClass2_create(params: &CommonParams) -> SharedPtr<IClass2>;
| ^^^^^^^^^^^^^ not FFI-safe
|
note: the lint level is defined here
--> linkage-test/src/two.rs:1:1
|
1 | #[cxx::bridge]
| ^^^^^^^^^^^^^^
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
Here an MVP for this bug. CXX version 1.0.34.
The main.rs
pub mod one;
pub mod two;
#[cxx::bridge]
mod ffi {}
fn main() {
let a = one::ffi::CommonParams {
count: 123,
name: String::from("somename"),
};
let b = one::ffi::IClass1_create(&a);
println!("B is not empty: {}", b.get_name());
let c = two::ffi::IClass2_create(&a);
println!("C is not empty: {}", c.get_name());
}
You can see, that I can use the IClass1_create function properly, but can't use IClass2_create with the same argument.
Also, as you know, I can't use #[repr(...)] for shared types inside the #[cxx::bridge].
What should I do to prevent this error? Is it correct behavior? How can I fix or, maybe, workaround this?
P. S.
For now, I'm tried to defined the same Shared type CommonParam in the both modules, but it's cause compile failure, because he thinks, that there are two different types, and he can't handle the type as the argument of the function.
The text was updated successfully, but these errors were encountered:
I tried to use a Shared type from one module inside another module, but have a quite strange error message:
Here an MVP for this bug. CXX version 1.0.34.
The
main.rs
The
one.rs
The
two.rs
The
wrapper.hpp
I omit
wrapper.cpp
to simplify the example. Nothing interesting there.The
build.rs
You can see, that I can use the
IClass1_create
function properly, but can't useIClass2_create
with the same argument.Also, as you know, I can't use
#[repr(...)]
for shared types inside the#[cxx::bridge]
.What should I do to prevent this error? Is it correct behavior? How can I fix or, maybe, workaround this?
P. S.
For now, I'm tried to defined the same Shared type
CommonParam
in the both modules, but it's cause compile failure, because he thinks, that there are two different types, and he can't handle the type as the argument of the function.The text was updated successfully, but these errors were encountered: