Skip to content
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

Conditional compilation based on imports (not an issue) #2

Closed
DevinR528 opened this issue Jul 13, 2020 · 3 comments
Closed

Conditional compilation based on imports (not an issue) #2

DevinR528 opened this issue Jul 13, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@DevinR528
Copy link

DevinR528 commented Jul 13, 2020

I saw you had mentioned something about extending realia to also conditionally compile based on crates. Today I saw this crate https://crates.io/crates/proc-macro-crate which at least accesses the Cargo.toml file? Just thought it might be helpful 🤷.

Edit: Ahh "downstream" dependencies, so this is the wrong way sorry nvm.

@mtkennerly
Copy link
Owner

Actually, that just gave me an idea. My previous attempts focused on using a build.rs to generate static crate info, but I see that proc-macro-crate checks std::env::var("CARGO_MANIFEST_DIR") in the proc macro itself. I checked, and that gives me the downstream crate's manifest dir, not Realia's, which I should then be able to pass to the cargo metadata command. That might just work!

mtkennerly added a commit that referenced this issue Jul 13, 2020
@mtkennerly
Copy link
Owner

Success :D I just published v0.2.0, which includes these new attributes:

  • #[realia::dep("your-crate", "a-dependency")]
  • #[realia::dep("your-crate", "a-dependency", "1.2.3")]
  • #[realia::dep_since("your-crate", "a-dependency", "1.2.3")]
  • #[realia::dep_before("your-crate", "a-dependencyo", "1.2.3")]
  • #[realia::dep_from_registry("your-crate", "a-dependency")]

The only caveats are:

  • You have to specify your crate's name, since the implementation relies on CARGO_MANIFEST_DIR. Otherwise, you'd get different results for cargo build in your project vs a downstream project.
  • I don't know how to reliably detect which features are enabled, so optional dependencies are ignored for now. When I'm assembling the arguments for cargo metadata, I only get to see how rustc was invoked, not how Cargo was invoked.

@DevinR528
Copy link
Author

Nice!! Glad it worked out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants