-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Only enable vergen on docsrs #533
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
use std::error::Error; | ||
#[cfg(feature = "docsrs")] | ||
use vergen::EmitBuilder; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
emit_git_metadata()?; | ||
Ok(()) | ||
} | ||
|
||
#[cfg(feature = "docsrs")] | ||
fn emit_git_metadata() -> Result<(), Box<dyn Error>> { | ||
// Emit the instructions | ||
EmitBuilder::builder().all_git().emit()?; | ||
Ok(()) | ||
} | ||
|
||
#[cfg(not(feature = "docsrs"))] | ||
fn emit_git_metadata() -> Result<(), Box<dyn Error>> { | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Have you checked that this actually gets enabled with generating docsrs docs?
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 haven't tested it with the live docsrs, since I'm not sure how one would go about doing so.
My understanding is that the
docsrs
feature gets enabled bychumsky/Cargo.toml
Lines 67 to 69 in af4e2b1
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 don't think this would enable such a feature. The cfg flag just allows you to do
#[cfg(docsrs)]
(which would probably be sufficient for your purposes, fwiw, instead of adding a cargo feature).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.
Okay, I tried a few things in that direction, but haven't quite managed to get it to work as expected.
So I first tested the code with
RUSTFLAGS="--cfg docsrs" cargo doc --open
. (Because someone said that it's a workaround of some sort.) That only seems to pass the info to the Cargo.toml part. It doesn't pass the info to thelib.rs
file, since#[cfg(docsrs)]
inlib.rs
had no effect.Then I tested it with
cargo rustdoc --open -- --cfg docsrs
. This lets me do#[cfg(docsrs)]
inlib.rs
, but does not pass it to thebuild.rs
script. And importantly, it doesn't seem to let me make vergen an optional feature.I could probably find a variation where I get it to work, but it might almost be easier to make the
docsrs
stuff a feature.all-features = true
should turn on thedocsrs
feature. Unless of course, you've got a good idea. I'm definitely willing to try out more stuff.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.
Have you tried the command at the top of
guide.rs
?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 missed that command, thank you.
So I tested it just now:
Conditionally compiling vergen does not seem to be possible with
Conditionally compiling it with
--all-features
and thendocsrs = ["dep:vergen"]
does seem to work.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.
Ah, that's unfortunate :(
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.
Hmm, not sure I understood this message. So this does work?
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.
Yep, this pull request should work.