Skip to content

Allow use of CGP proc macros without explicit import of prelude #40

Description

@soareschen

Currently, the CGP pro macros are unhygenic, and requires import of cgp::prelude::* for the expanded syntax to work. Unfortunately, there is no equivalent of $crate in the proc macro world to help us bind CGP constructs with proper module path.

We would need to figure out how to properly scope CGP constructs inside the macro expansion, so that the macros could work even if users don't import the prelude.

Activity

  1. gkgoat1 commented on Dec 6, 2025

    @gkgoat1

    You can probably use ::cgp as a default with an attribute/attribute parameter to change the crate path in nested macro invocations

  2. gkgoat1 commented on Apr 13, 2026

    @gkgoat1

    @soareschen are you still considering this?

  3. soareschen commented on May 4, 2026

    @soareschen
    CollaboratorAuthor

    @gkgoat1 Thanks for asking. Yes it is in the plan but I haven't got the time to prioritize on this.

    The tentative plan is to add something like a cgp_macro_prelude module that will be imported together with cgp::prelude::*. With that, the CGP macros will refer to CGP constructs in the form like cgp_macro_prelude::DelegateComponent instead of the current bare DelegateComponent.

    This way, if you don't want to import everything in prelude, you only need to import cgp::cgp_macro_prelude to make it work with the macros.

    Using something like ::cgp::DelegateComponent might be a bit challenging at the moment, because it would make the macros not easily usable by internal CGP crates that don't yet have the cgp crate available. I might be able to define an internal crate with local renaming to make this work, but it is not clear if it could work at the moment.

    The biggest blocker was that the macro library has become pretty bloated, with a lot of pending refactoring to be done. I was hoping to fix the prelude together with the macro refactoring. But given the limited time, I will probably try to fix the prelude first, and then refactor the macro code later on.

  4. gkgoat1 commented on May 9, 2026

    @gkgoat1

    @gkgoat1 Thanks for asking. Yes it is in the plan but I haven't got the time to prioritize on this.

    The tentative plan is to add something like a cgp_macro_prelude module that will be imported together with cgp::prelude::*. With that, the CGP macros will refer to CGP constructs in the form like cgp_macro_prelude::DelegateComponent instead of the current bare DelegateComponent.

    This way, if you don't want to import everything in prelude, you only need to import cgp::cgp_macro_prelude to make it work with the macros.

    That doesn't fully resolve the issue though, you'd still need to import cgp_macro_prelude (which wrapper crates hiding their usage of CGP shouldn't need to specify)

    Using something like ::cgp::DelegateComponent might be a bit challenging at the moment, because it would make the macros not easily usable by internal CGP crates that don't yet have the cgp crate available. I might be able to define an internal crate with local renaming to make this work, but it is not clear if it could work at the moment.

    The idea for that could be that, like potential wrapper crates, internal crates specify themselves as the CGP path like ```rust
    #[cgp_path(crate)]

    so the macro would look there and not at `::cgp`
    
    > 
    > The biggest blocker was that the macro library has become pretty bloated, with a lot of pending refactoring to be done. I was hoping to fix the prelude together with the macro refactoring. But given the limited time, I will probably try to fix the prelude first, and then refactor the macro code later on.
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions