Skip to content
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

proc-macro panic when deriving uniffi::Record #2426

Open
kriswuollett opened this issue Feb 3, 2025 · 1 comment
Open

proc-macro panic when deriving uniffi::Record #2426

kriswuollett opened this issue Feb 3, 2025 · 1 comment

Comments

@kriswuollett
Copy link

kriswuollett commented Feb 3, 2025

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)
@jplatte
Copy link
Collaborator

jplatte commented Feb 3, 2025

If you want to debug this yourself, I would recommend building on nightly with RUSTFLAGS='-Zproc-macro-backtrace'. (I think that's the right flag name, just building on nightly without flags might get you a hint in the error message with the right name of the option)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants