Skip to content

feat(build): move to cmake crate for building script in build.rs#136

Open
jaoleal wants to merge 2 commits intosedited:masterfrom
jaoleal:cmake_crate
Open

feat(build): move to cmake crate for building script in build.rs#136
jaoleal wants to merge 2 commits intosedited:masterfrom
jaoleal:cmake_crate

Conversation

@jaoleal
Copy link
Contributor

@jaoleal jaoleal commented Feb 16, 2026

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

@jaoleal
Copy link
Contributor Author

jaoleal commented Feb 17, 2026

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.

@jaoleal jaoleal force-pushed the cmake_crate branch 2 times, most recently from 36ef06b to b061f0a Compare February 17, 2026 19:43
@jaoleal
Copy link
Contributor Author

jaoleal commented Feb 17, 2026

Okay, apparently the problem was due flag conflict and is resolved in b061f0a

CI is passing now.

@alexanderwiederin
Copy link
Contributor

Thanks @jaoleal!

I think the raw cmake approach is more explicit and already works well. To fix #135, we can find a simpler solution. Could you give an example of an environment where the old approach failed?

@yancyribbens
Copy link

To fix #135, we can find a simpler solution.To fix #135, we can find a simpler solution.

I agree, maybe if you could split this out into separate commits it would be more clear. As it stands, if you are only address #135, this seems very complex.

@sedited
Copy link
Owner

sedited commented Feb 23, 2026

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.

jaoleal added 2 commits March 2, 2026 20:35
Replace bare .unwrap() calls on cmake Command invocations with
descriptive error handling. The first cmake call (configure) now
specifically detects ErrorKind::NotFound and reports that cmake
is required with installation instructions. The build and install
calls use .expect() with clear messages and check exit status.
`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 also
handles dependencies accross environments.
@jaoleal
Copy link
Contributor Author

jaoleal commented Mar 3, 2026

Ok, so:

  1. 18d643a Concisely addresses Throw expect() message if deps are not found #135.
  2. f8d36d Delegates command handling to the cmake crate.

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 cc crate.

By the other side, I understand if you guys still prefer the old approach. I can drop f8d36d and we can follow with 18d643a

@@ -56,15 +56,15 @@ fn main() {
.arg(build_config)
.arg(format!("--parallel={num_jobs}"))
.status()
.unwrap();
.expect("Failed to run cmake build");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really add any useful information, so I wouldn't have bothered changing this. Although, you could improve this if you want to be what you expect, for example that the config and build directory are valid.


Command::new("cmake")
.arg("--install")
.arg(&build_dir)
.arg("--config")
.arg(build_config)
.status()
.unwrap();
.expect("Failed to run cmake install");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

@@ -42,7 +42,7 @@ fn main() {
.arg("-DENABLE_IPC=OFF")
.arg(format!("-DCMAKE_INSTALL_PREFIX={}", install_dir.display()))
.status()
.unwrap();
.expect("cmake is required to build libbitcoinkernel. Please install cmake and ensure it is in your PATH.");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems better, and is how I would have done it. Although, I probably would have just wrote cmake should be installed.

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.

Throw expect() message if deps are not found

4 participants