Dependencies only during proc_macro evaluation

Hi,
I'm working on a deployment scripting framework, which I'd like to be configured with Rust code.

As such, I want to create various macros that can double-check the configuration values.
For example, url!("https://example.com") will make sure it's a valid URL while compiling.

For that check, I want to use the url-crate, but nothing from that crate ends up in the TokenStream-output or the rest of the code-base, so ideally I would rather not have that dependency in the final binary.
(My currently favored architecture will upload the compiled binary to the target host, so keeping binary size low is relatively important.)

Any idea if this is possible? Cargo's dev-dependencies and build-dependencies are not available during macro evaluation, so those don't work.

Thanks in advance.

These would be normal dependencies of the proc-macro crate itself. Since the crate that runs proc macro is separate form the crate that uses the macro, these deps are separate too.

2 Likes

Ah, thanks.

I thought they would get pulled into my main crate, because that depends on the macro-crate and then it would be a transitive dependency. But I can confirm that the binary gets bigger when I add the url-dependency to the main crate (and use it in the code somewhere, so that it doesn't get optimized out).

Looking at how aggressive the compiler is, I guess, it would optimize it out anyways, even if it were to count as a transitive dependency.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.