feat(build): replace unwraps by expects with useful messages in build.rs#136
feat(build): replace unwraps by expects with useful messages in build.rs#136jaoleal wants to merge 1 commit intosedited:masterfrom
Conversation
|
I got a problem while trying to build on windows, still working on that. But feedback on overall approach does apply, specially regarding the cmake crate. |
36ef06b to
b061f0a
Compare
|
Okay, apparently the problem was due flag conflict and is resolved in b061f0a CI is passing now. |
|
I agree with @alexanderwiederin and @yancyribbens . I think we should strive to have as few build and runtime dependencies as possible. I think there should be an easier way to surface a nicer error to address #135. |
|
Ok, so:
My rationale for addressing #135 with the cmake crate is thats the ""oficial"" way to do it, found it while searching how should i deal with Build Scripts, since it already have some more granular error handling and error messages i thought for it to be a better fit to address #135. The cmake is well-maintained and its only dependency is cc, which is already added in libbitcoinkernel-sys/Cargo.toml. On my slow laptop (i3-13gen + 8gbram) the build time were negligible. And this approach matches the same approach that was taken when using the By the other side, I understand if you guys still prefer the old approach. I can drop f8d36d and we can follow with 18d643a |
|
Applied requested changes. @yancyribbens please take a look if the current approach on a753eed suits. I tried to make the error handling more usefull than a single unwrap but not extending much. Now theres difference between when finding cmake and executing it. |
524020e to
e270c2c
Compare
|
Done! @yancyribbens |
|
Renaming the PR to match the current approach |
|
@yancyribbens done in 4956e1b. |
|
corrected capitalization on 26cdab4 |
|
LGTM - thanks for improving the messaging. |
alexanderwiederin
left a comment
There was a problem hiding this comment.
Thanks for the patience.
May I suggest a helper like this:
fn run_cmake(cmd: &mut Command) {
let status = cmd
.status()
.expect("cmake should be installed and available in PATH");
if !status.success() {
panic!("cmake exited with status: {status}");
}
}From what I understand expect on status only fires when cmake fails to spawn.
|
@jaoleal, are you still working on this? Appreciate that my review came rather late, so no pressure - but I am curious about what you think about my suggestion. |
Hi @alexanderwiederin, since the owner of the issue thats being addressed here is yancyribbens and, with him we drove this pull request to this current state where it simply replaces the unwraps with expects, Im much aligned with his suggestions here. They gave me the impression that we may want to be simple here, maybe that helper can be a unnecessary abstraction? But to be honest I think this pr is extended for what the issue touches and in my opinion every approach that was suggested addressed the issue really well, being just a question of taste to alternate between them, im trying to leave mine as absent as possible. @yancyribbens Can you give us a input on #136 (review) ? |
|
To clarify why I suggested the helper: from what I understand the current https://doc.rust-lang.org/std/process/struct.Command.html#method.status |
|
I think the current state of the PR address the issue that I had. That issue was that if @alexanderwiederin I think is pointing out that even if cmake is installed, it may fail for other reasons. Could that not be addressed with a followup issue/commit? I think it's a good idea to add the suggestion, however I think it should be specified in a separate commit message with what circumstances cmake might fail? |
|
The hesitation I have is that the second and third expects give the false impression that they catch execution failures, when From what I understand the first expect, "cmake should be installed and available in PATH.", accurately describes the only failure case I understand that this is all quite theoretical because it seems that none of us are actually testing this :) But that is how I understand the docs. Would you agree? |
Good point. The lets just remove the "others" and start another issue? The only thing this PR and commit should be fixing IMO is, if cmake is not installed, that an error says so.. |
|
Yes, that makes sense to me. @jaoleal, what do you think? nit: remove the |
|
Okay, I think i got what you guys meant. Check if 8b79693 fits. I have to confess that it was hard to implement that one. 😆 |
|
Hmmm the CI error appears to be a version conflict, it should be addressed in a different PR correct ? |
|
Can you rebase? It's hard to tell now since your branch is out of date it looks like. However, we are saying this should basically be a 1 line diff with the expect message: |
700bf2f to
7e84b1d
Compare
Yeah, thats what i tought that i pushed. I had some conflict problems with another branch, really sorry for that. Rebased and correctly addressed the suggestions in e302a77. The CI error remained even after rebase but i couldnt reproduce it on my end, these version conflict errors are really boring. |
|
This looks good to me. The CI error looks unrelated. |
|
Looks good to me! Let's hold off until the CI has been fixed. |
libbitcoinkernel-sys/build.rs` was executing a cmake binary from the environment and doing some manual flag and path configuration. The presented changes delegate the same job to the cmake crate which should handle dependencies accross environments.
But im not certain if the choice of not using this crate is on purpose.
fix: #135