Skip to content

prost-derive: Add #[(prost(prost_path = "::prost")] #1274

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jeremija
Copy link

@jeremija jeremija commented Apr 24, 2025

Add a new proc_macro attribute in prost-derive, which is used to let the macro implementation know about the value of
prost_build::Config::prost_path.

As a result, the derived messages no longer have ::prost hardcoded in them, and the configured path to th prost crate will be referenced everywhere in the generated code.

This change also adds support for configuring the path to
::prost_types via prost_build::Config::prost_types_path.

Fixes #939

@jeremija jeremija force-pushed the prost-derive-prost-path branch 5 times, most recently from 79a6508 to def86d2 Compare April 24, 2025 13:39
@jeremija
Copy link
Author

I didn't realize there was already #488 which basically does the same thing, and adds additional fix for prost_types.
I'd really want to get a fix for the original issue merged and fixed, so please let me know if there's anything I can do to help.

@chris-zen
Copy link

Do you have any plans to move this or #488 forward? I'm looking to wrap prost in my library so users don’t need to worry about the correct version—they can just rely on my library instead.

@jeremija jeremija force-pushed the prost-derive-prost-path branch 3 times, most recently from 6554a02 to c1dd2bb Compare May 7, 2025 10:05
@jeremija
Copy link
Author

jeremija commented May 7, 2025

I've updated this MR to also include the ability to re-export prost_types if desired. Also added a separate test crate to ensure the re-exports work as intended.

@demurgos
Copy link

demurgos commented May 7, 2025

I have an issue at work where my binary crate depends on two libs working with generated Prost code, except they use different major versions of Prost. With the hardcoded prost path, I can't fix it and have to wait until they update to the same version. However, any time a new Prost version is released and the libs get out of sync I'm back to being stuck.

With a way to override the path, I could use cargo to depend on both dependencies:

prost014 = {package="prost", version "0.14"}
prost015 = {package="prost", version "0.15"}

And it would avoid global coordination issues.

This PR would solve this issue neatly. 👍

jeremija added 3 commits June 25, 2025 11:32
Add a new proc_macro attribute in `prost-derive`, which is used to let
the macro implementation know about the value of
`prost_build::Config::prost_path`.

As a result, the generated types no longer have `::prost` hardcoded in
them, and a re-exported prost crate can be used instead along with
generated code.

Fixes tokio-rs#939
Similarly to the previous commit, this allows customization of the path
to `prost_types` crate in case a re-export is desired. This can now be
done by calling the `prost_build::Config::prost_types_path` method.
@jeremija jeremija force-pushed the prost-derive-prost-path branch from c1dd2bb to 76cf48b Compare June 25, 2025 09:33
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

Successfully merging this pull request may close these issues.

prost_build::Config::prost_path is unusable.
3 participants