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

Move generated code to src directory #189

Closed
wants to merge 2 commits into from
Closed

Move generated code to src directory #189

wants to merge 2 commits into from

Conversation

Amanita-muscaria
Copy link

Moved the generated code to the source directory so IDEs have an easier time finding definitions

Amanita Muscaria added 2 commits February 2, 2020 18:11
Moved the generated code to the source directory so IDEs have an easier time finding definitions
@psychon
Copy link
Owner

psychon commented Feb 3, 2020

I can understand making things easier for IDEs, however cargo publish becomes really sad when the build script modifies the source directory. If I read https://doc.rust-lang.org/cargo/reference/build-script-examples.html correctly, this can actually cause breakage:

In general, build scripts should not modify any files outside of OUT_DIR. It may seem fine on the first blush, but it does cause problems when you use such crate as a dependency, because there's an implicit invariant that sources in .cargo/registry should be immutable. cargo won't allow such scripts when packaging.

@Amanita-muscaria
Copy link
Author

Oh, well, damn. I had no idea.

@psychon
Copy link
Owner

psychon commented Feb 3, 2020

What are you using? I heard about rust-analyzer and there is already an open issue there for this kind of thing: rust-lang/rust-analyzer#1964

Another option would be to change the way code is generated in x11rb.

Right now, code is generated by build.rs in $OUT_DIR.
Instead, one could ship the generated code with x11rb and get rid of build.rs. However, I do not want generated code in Git, so this option would be a little complicated. It needs some magic so that the generated code is picked up by cargo publish and shipped together with the other code. However, at the same time something (outside of cargo?) would need to generate the code when building from git.

Basically... this option would mean that building x11rb from git would become more complicate since cargo build would fail and instead something like make build would be necessary.

These are the two options that I can think of for this right now. Nothing is "obviously nice". However, it would still be nice to get rid of the python dependency when building from crates.io....

@Amanita-muscaria
Copy link
Author

I've been using CLion lately. Haven't tried it out on VSCode as yet. Is there a reason the code is generated at all?

@psychon
Copy link
Owner

psychon commented Feb 10, 2020

Is there a reason the code is generated at all?

Well, what is the alternative?

My preferred solution would be "no generated code in Git" (as is now; otherwise it is too easy to have things get out of sync and diffs become huge and noisy) but "generated code in the download from crates.io (and no build.rs)". However, I do not think this is possible.

@Amanita-muscaria
Copy link
Author

Just generate the code once and don't bother doing it for each build?

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.

2 participants