-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
warning: extern
block uses type RustString
, which is not FFI-safe
#253
Comments
If the proposed fix above looks good, I'd be happy to open the PR for it! |
Thanks for reporting this and including steps to reproduce. We don't want For example, the following program: fn main() {
}
#[repr(C)]
pub struct RustString(String);
pub extern "C" fn return_rust_string() -> RustString {
unimplemented!()
} Would print the following in Compiling playground v0.0.1 (/playground)
warning: `extern` fn uses type `String`, which is not FFI-safe
--> src/main.rs:8:43
|
8 | pub extern "C" fn return_rust_string() -> RustString {
| ^^^^^^^^^^ not FFI-safe
|
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
= note: this struct has unspecified layout
= note: `#[warn(improper_ctypes_definitions)]` on by default Fortunately, we don't actually pass the Instead, we pass a pointer to the swift-bridge/crates/swift-bridge-ir/src/codegen/codegen_tests/string_codegen_tests.rs Lines 5 to 28 in 2724644
I'll PR a fix tonight. |
Thanks again for reporting this. The warning was fixed here #254 |
Thank you so much!! |
I exposed a transparent struct in Rust, which is used by a swift function exposed back to rust. This produces the error
Seems this is related to RustStrings being used in a Swift function exposed to Rust, and the solution looks as simple as
Example code to reproduce level (rust):
and on the swift side:
(code is provided under the MIT license)
The text was updated successfully, but these errors were encountered: