kurtbuilds / ormlite

An ORM in Rust for developers that love SQL.
https://crates.io/crates/ormlite
MIT License
216 stars 11 forks source link

Unexpected token in derive attribute: Punct { char: ':', spacing: Joint, span: #93 bytes(26754..26759) } #38

Closed Manosgou closed 7 months ago

Manosgou commented 7 months ago

I am creating a Tauri application using the ormlite library to manage a sqlite database. I started developing the application in mac os environment without any problem. However, recently I tried to run the application on windows without success. The following error occurs in all database models.

#[derive(Model, Serialize, Deserialize, Clone, Debug)]
#[ormlite(table = "EventType")]
pub struct EventType {
    pub id: Option<u32>,
    pub name: String,
    pub color: String,
}
error: proc-macro derive panicked
  --> src\models.rs:13:10
   |
13 | #[derive(Model, Serialize, Deserialize, Clone, Debug)]
   |          ^^^^^
   |
   = help: message: Unexpected token in derive attribute: Punct { char: ':', spacing: Joint, span: #93 bytes(26754..26759) }

Ormlite version :"0.17.5"

kurtbuilds commented 7 months ago

Thank you for the report. Unfortunately I don't easily have a Windows machine to test on, and there's no logic in ormlite that is conditional on os.

Can you try running cargo expand on the project from the windows machine and share the output?

Manosgou commented 7 months ago

I haven't used cargo expand before, but the output doesn't show something special. I ran the command only for the models.rs file with only the Model derive. Am i doing something wrong?

mod models {
    use ormlite::model::Model;
    use serde::{Deserialize, Serialize};
    #[ormlite(table = "EventType")]
    pub struct EventType {
        pub id: Option<u32>,
        pub name: String,
        pub color: String,
    }
}
kurtbuilds commented 7 months ago

I wouldn't expect the latter code example to compile. You don't have the #[derive(Model)] attribute on that struct.

Manosgou commented 7 months ago

Of course, because it panics as soon as the cargo expand command is executed.

PS C:\Users\<User>\Desktop\<ProjectName>\src-tauri> cargo expand models
    Blocking waiting for file lock on build directory
    Checking <ProjectName>v0.0.0 (C:\Users\<User>\Desktop\<ProjectName>\src-tauri)
error: proc-macro derive panicked
  --> src\models.rs:13:10
   |
13 | #[derive(Model)]
   |          ^^^^^
   |
   = help: message: Unexpected token in derive attribute: Punct { char: ':', spacing: Joint, span: #82 bytes(26778..26783) }
error: proc-macro derive panicked

mod models {
    use ormlite::model::Model;
    use serde::{Deserialize, Serialize};
    #[ormlite(table = "EventType")]
    pub struct EventType {
        pub id: Option<u32>,
        pub name: String,
        pub color: String,
    }
}
kurtbuilds commented 7 months ago

That's strange. Would you be able to create a mini repo with repro steps? If I can run the expand myself, even if it's on Mac, I might be able to debug what's happening.

Manosgou commented 7 months ago

I uploaded the entire project, link

kurtbuilds commented 7 months ago

I spun up a Windows VM in Parallels (I'm on Mac), and I was able to run cargo build for that project in both Windows and on Mac. Can you be more specific about how you're encountering the error?

On Windows, i was on win 11, Visual Studio 2022, and rust 1.74.

Manosgou commented 7 months ago

I think there is something wrong with my Windows build and the problem is not related to the library. Anyway, I used github actions to compile the Windows version of my app without any issues. Thank you for your time and great work with ormlite, it's a fantastic tool.

kurtbuilds commented 7 months ago

Happy to help. LMK if you encounter other issues.