uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

proc-macro panic when deriving `uniffi::Record`

Open kriswuollett opened this issue 8 months ago • 1 comments

Not sure if this is a Rust problem or uniffi-rs or not, but when trying to build this example.zip for #2425 the following error occurs on the struct:

error: proc-macro derive panicked
 --> crates/example/ast/src/types/metadata.rs:2:39
  |
2 | #[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
  |                                       ^^^^^^^^^^^^^^
  |
  = help: message: called `Option::unwrap()` on a `None` value

Code snippet:

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct Metadata(serde_json::Value);

#[cfg(feature = "uniffi")]
uniffi::custom_type!(Metadata, String, {
    lower: |s| serde_json::to_string(&s).unwrap(),
    try_lift: |s| Ok(serde_json::from_str(&s).unwrap()),
});

Package:

[package]
name = "appbiotic-example-ast"
version = "0.1.0"
edition = "2021"

[features]
default = ["uniffi"]
uniffi = ["dep:uniffi"]

[dependencies]
serde = { version = "1.0.217", features = ["derive"] }
serde_json = { version = "1.0.138" }
thiserror = "2.0.11"
uniffi = { git = "http://github.com/mozilla/uniffi-rs", rev = "9c83e1de164b4168bd33bd991d22184ee9f6c856", optional = true }

I say I'm not sure if it is a Rust problem or not because I sometimes seem to also get another associated error which shows up on the uniffi::custom_type! part which gets cleared up with a cargo clean and/or restart the rust-analyzer (in vscode):

proc-macro panicked: failed to load macro: Failed to get file metadata for /Users/kris/Code/appbiotic/example/target/debug/deps/libuniffi_macros-3ff8cce37c02a9b3.dylib: No such file or directory (os error 2)rust-analyzer[macro-error](https://rust-analyzer.github.io/manual.html#macro-error)

kriswuollett avatar Feb 03 '25 16:02 kriswuollett