-
Notifications
You must be signed in to change notification settings - Fork 108
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
Do not write to user data directories on build. Fix docs.rs documentation generation #231
Conversation
This change addresses the same problem as #185. It turns out that build scripts are only meant to write to OUT_DIR, and in general it is untidy to write things all over the place. docs.rs is specially sensitive to this. Also, docs.rs does not set the feature flag "docsrs" by itself, but a Cargo package metadata section can be used to instruct docs.rs to pass that flag to Cargo.
Tested by making the usual build artifacts folder a symlink to |
OUT_DIR
as a data directory in build scripts
That is very(!) clever. But if I am understanding correctly, this only tells us that building for doc.rs is likely to succeed. We still have the issue of building for conventional platforms, and this line concerns me: Line 19 in 25d37ce
Won't this line break non-doc.rs builds? In other words, won't I am new to this issue, so please forgive me if my comments are completely off-base. But assuming that's right, I wonder how hard it would be to incorporate one of the techniques mentioned in this issue: rust-lang/docs.rs#147 |
However, to play it safe, I could refactor the code to only pay attention to |
Well, let me make sure I am not misunderstanding. When I build this, I see the following directories created in my
I am afraid they are being created there instead of in:
Am I making a mistake?
Yes, and thank you for doing this. We should definitely get this working. Also, I noticed this: https://docs.rs/about/builds#detecting-docsrs |
No, you're not making any mistakes 😄. That was an intended change on my part, and as I've said I didn't notice anything wrong with it. However, I didn't look too deep into the assumptions the code makes about the directory layout, so in the commits I've just pushed I brought back the previous behavior for non-docs.rs builds as discussed. I'm fairly sure that for docs.rs builds the changes made by this PR are appropriate. |
// The Cargo documentation recommends that build scripts | ||
// place their generated files at OUT_DIR too, but we | ||
// don't change that for now for normal builds. | ||
if cfg!(docsrs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was expecting to see if std::env::var("DOCS_RS").is_ok()
here.
Is there a reason to prefer this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This source file is used by both the build script and the application code. By checking for the feature flag we can prevent the DOCS_RS
environment variable from interferring with the application code, and make sure that this code path is taken only on the intended environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good argument. Let's see what happens.
It's sad that the documentation build still fails, but now at least now we know it's because the Maybe we should set |
I think this is worth a shot. |
Huh. No change: https://docs.rs/crate/afl/0.12.4/builds/555863 |
Here is the "/opt/rustwide/cargo-home/bin/cargo" "+nightly" "rustdoc" "--lib" "-Zrustdoc-map" "-Z" "unstable-options" "--config" "build.rustflags=[\"--cfg\", \"docsrs\"]" "--config" "build.rustdocflags=[\"-Z\", \"unstable-options\", \"--emit=invocation-specific\", \"--resource-suffix\", \"-20220508-1.62.0-nightly-cb1219871\", \"--static-root-path\", \"/\", \"--cap-lints\", \"warn\", \"--disable-per-crate-search\"]" "-Zunstable-options" "--config=doc.extern-map.registries.crates-io=\"https://docs.rs/{pkg_name}/{version}/x86_64-unknown-linux-gnu\"" "-j3" "--target" "x86_64-unknown-linux-gnu" If I run this command, a But if I remove the Also, I noticed this in the Configuration keys section of the Cargo Book:
This suggests to me that |
Good catch! The |
You raised a good point here. One thought I had was, maybe we switch to checking the |
@AlexTMjugador I feel like we were close to getting this over the finish line. Do you think you might still work on this? |
I want to work on this (and other things), but I don't have much free time available right now. I hope to be more available in a week or two. |
This docs.rs generation issue is trickier than I anticipated. I might get back to it at some point, but at the moment I'm not doing it. If anyone else is interested in taking care of it, feel free to let me know and go ahead 😄 |
This change addresses the same problem as #185. It turns out that build scripts are only meant to write to
OUT_DIR
, and in general it is untidy to write things all over the place. docs.rs is specially sensitive to this.Also, docs.rs does not set the feature flag
docsrs
by itself, but a Cargo package metadata section can be used to instruct docs.rs to pass that flag to Cargo.I have not tested the change.