How to add a dependency through a proc macro

⚓ rust    📅 2025-06-09    👤 surdeus    👁️ 1      

surdeus

Hi rust community,

I'm trying to create a proc-macro that takes a struct and wraps its fields in volatile_register::RW.
For example, a struct

struct A {
    x: u32,
    y: u32,
}

becomes

struct A {
    x: volatile_register::RW<u32>,
    y: volatile_register::RW<u32>,
}

I got the macro to work, however, for the code to work in the user crate, I need to add as a dependency both the proc macro crate and volatile_register, which feels incorrect. How can I make the macro bring all its necessary dependencies to the user crate.

3 posts - 2 participants

Read full topic

🏷️ rust_feed