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

#[derive(CustomResource)] path dependencies #227

Closed
semtexzv opened this issue Apr 15, 2020 · 3 comments
Closed

#[derive(CustomResource)] path dependencies #227

semtexzv opened this issue Apr 15, 2020 · 3 comments
Labels
derive kube-derive proc_macro related wontfix This will not be worked on

Comments

@semtexzv
Copy link

semtexzv commented Apr 15, 2020

Current implementation of custom derive has a bunch or implicit assumptions about outer environment, which requires user to import crates under specific names.

I like to rename serde_json and k8s_openapi to json and k8s respectively, and It's impossible to do so currently
Changing the paths in the macro output to use undocumented re-exports from kube crate would solve this.

@clux
Copy link
Member

clux commented Apr 15, 2020

Oh, interesting. You mean like having the macro generate code that depends on something like:

use kube_derive::serde_json::Deserialize;

Would that work? I don't want kube_derive to depend explicitly on kube, but that probably wasn't what you meant.

@clux clux added the derive kube-derive proc_macro related label Apr 15, 2020
@semtexzv
Copy link
Author

semtexzv commented Apr 15, 2020

Yeah, could be. Goal is to reduce number of dependencies on external state in the custom derive.

//edit: I don't know whether you can import regular items from proc-macro crate.

@clux
Copy link
Member

clux commented Dec 25, 2020

Revisiting this. Having dug into this more, turns out there's an open issue in rust-lang about this being hard: rust-lang/rust#54363
Serde has a similar issue.

Practically, we would need some way to refer to the up to three runtime dependencies kube-derive has:

  • serde_json (needed in both codegen and generated code)
  • schemars (optional, only needed in runtime code, user needs to select feature flags)
  • k8s_openapi (needed only in runtime code, user needs to select feature flags)

As per the PR, I don't want to re-export these from kube, because kube-derive is actually fine as a stand-alone crate (schemars is only needed there). Strangely, the dependency tree is actually more natural this way around (kube re-exports kube-derive).

If it was possible for kube-derive to re-export these three with non-default features by itself, and then have users progressively enhance them with their own feature selection (because we can only have one version of a given package), then I would be in favour of it.

Unfortunately, proc_macro crates do not support this:

error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
   --> /home/clux/repos/kube-rs/kube-derive/src/lib.rs:209:1
    |
209 | pub use serde_json;
    | ^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

Thus, I am going to close this for now. Unless there's movement on this from the rust side, we are just going to list that you need to have these 2/3 crates available in scope - and not renamed - for kube-derive to work.

@clux clux added the wontfix This will not be worked on label Dec 25, 2020
@clux clux closed this as completed in 8337a94 Dec 26, 2020
clux added a commit that referenced this issue Dec 26, 2020
clarify inability to handle crate renames in kube-derive - closes #227
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
derive kube-derive proc_macro related wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants