bitcoin icon indicating copy to clipboard operation
bitcoin copied to clipboard

cmake: Revamp handling of data files for `{test,bench}_bitcoin` targets

Open hebasto opened this issue 1 year ago • 6 comments

This PR leverages the approach from the https://github.com/chaincodelabs/libmultiprocess project and introduces a new target_data_sources() function, which minimizes code needed to assign a *.json or *.raw data file to the test_bitcoin or bench_bitcoin target.

hebasto avatar Sep 14 '24 11:09 hebasto

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/30901.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK theuni, fjahr, Sjors

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

DrahtBot avatar Sep 14 '24 11:09 DrahtBot

Friendly ping @ryanofsky :)

hebasto avatar Sep 14 '24 11:09 hebasto

tACK 0c35be69cf2a18a7a9173d0f9f88116b4417c892

I have based #28792 on this now. It works and seems like a nicer way to do what I need there than the previous approach.

Take it with a grain of salt though because I don't think I am experienced enough with CMake to tell if there are any hidden issues with this approach or if there are even better ways to achieve this.

fjahr avatar Sep 20 '24 09:09 fjahr

Guix builds (on x86_64) [untrusted test-only build, possibly unsafe, not for production use]

File commit 197aa249551ea7b2280b6e187d2ad5378687beff
(master)
commit 0bc2b979eacf67662631c50e67d952450903d8b3
(master and this pull)
SHA256SUMS.part 521f76d55c6d0681... 82df3d90acea09eb...
*-aarch64-linux-gnu-debug.tar.gz d65768ddaa01b1e2... b55abed2172b7cf8...
*-aarch64-linux-gnu.tar.gz 7979cd76ea72491b... a1ea6ffd72a57c52...
*-arm-linux-gnueabihf-debug.tar.gz f10a6f5c23d9591a... 18b49aeb3bb57391...
*-arm-linux-gnueabihf.tar.gz 243389753c7ad79a... eff66b351f885633...
*-arm64-apple-darwin-unsigned.tar.gz 4de1c5efbfb6983a... 2fb0cc3e11743ea0...
*-arm64-apple-darwin-unsigned.zip 56768c5b2e77aa44... 5e9fdb3271af18d5...
*-arm64-apple-darwin.tar.gz 45f83ddd7d034ced... 6b9a11453016515c...
*-powerpc64-linux-gnu-debug.tar.gz dbd3fd28edfe8346... 3dcb12423b002833...
*-powerpc64-linux-gnu.tar.gz b30ca46023d94314... 6e6caa5f3db63e9a...
*-riscv64-linux-gnu-debug.tar.gz 3496ab1a2d69f873... eb08343fd8aaff84...
*-riscv64-linux-gnu.tar.gz e9fd9140d0c75276... 4185a04618d7f424...
*-x86_64-apple-darwin-unsigned.tar.gz 2d80ca5c684f9c3a... 0747b84d884272a7...
*-x86_64-apple-darwin-unsigned.zip 8d9c51153100b0a9... f31f6e03d65beb2d...
*-x86_64-apple-darwin.tar.gz 2a6c00e8b0e9e53b... 780ded24e6d27356...
*-x86_64-linux-gnu-debug.tar.gz 0d6d2b136adbc951... 8cf9d88b75d6268d...
*-x86_64-linux-gnu.tar.gz c8522c785d8bade4... 1b9e51de65d24364...
*.tar.gz fdfcfc0072ad02f3... f46aa53f989f4832...
guix_build.log c3f3df05bf999a2d... 8f0c9f28397fb3eb...
guix_build.log.diff f922aa1b8ac7af94...

DrahtBot avatar Sep 20 '24 16:09 DrahtBot

Rebased due to the conflict with the merged bitcoin/bitcoin#31503.

hebasto avatar Dec 17 '24 12:12 hebasto

re-ACK 9f14069fde2a612b1f350ab0b49cdb5d96e8ac3e

Confirmed only rebase since last review per git range-diff master 0c35be69cf2a18a7a9173d0f9f88116b4417c892 9f14069fde2a612b1f350ab0b49cdb5d96e8ac3e

fjahr avatar Dec 17 '24 13:12 fjahr

🚧 At least one of the CI tasks failed. Debug: https://github.com/bitcoin/bitcoin/runs/34533242400

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

DrahtBot avatar Jan 04 '25 11:01 DrahtBot

Rebased due to the conflict with the merged bitcoin/bitcoin#31542.

hebasto avatar Jan 09 '25 09:01 hebasto

Re-ACK 4185ad1cb12060337c2d66a9a66e37be1d10f4ce

Confirmed only change was a rebase.

fjahr avatar Jan 09 '25 12:01 fjahr

ACK 4185ad1cb12060337c2d66a9a66e37be1d10f4ce

My cmake knowledge is also limited, but I like that this removes duplication. E.g instead of base58_encode_decode.json.h and data/base58_encode_decode.json now test/CMakeLists.txt only contains the latter.

The build log looks the same, before and after:

[ 76%] Generating data/base58_encode_decode.json.h

Sjors avatar Jan 17 '25 13:01 Sjors

Friendly ping @theuni :)

hebasto avatar Feb 10 '25 09:02 hebasto

Also, since you're messing with this, please consider the CODEGEN option for add_custom_command, which would need feature-gating same as DEPENDS_EXPLICIT_OPT.

theuni avatar Feb 12 '25 19:02 theuni

  1. Rebased due to the conflict with the merged bitcoin/bitcoin#30911.
  2. Addressed the recent @theuni's feedback.
  3. Fixed minor bugs, such as: https://github.com/bitcoin/bitcoin/blob/18cc0a55595f9dc1f2e561743201a05754996b64/cmake/module/TargetDataSources.cmake#L6

Also, since you're messing with this, please consider the CODEGEN option for add_custom_command, which would need feature-gating same as DEPENDS_EXPLICIT_OPT.

Nice! Added.

Please note that cmake_policy(SET CMP0171 NEW) within TargetDataSources.cmake does not work for some reason. However, this behaviour is not documented by CMake.

hebasto avatar Feb 13 '25 12:02 hebasto

tACK 18cc0a55595f9dc1f2e561743201a05754996b64

Again, I am not an expert on cmake but I don't see any downsides in the latest changes and I can confirm it works. I am using this latest version in #28792 now. And I find the change on function names and args is making things a bit nicer.

fjahr avatar Feb 13 '25 20:02 fjahr

Hmm, something here has broken the dependency flattening. I'm seeing a stall again due to the file generation.

theuni avatar Feb 13 '25 21:02 theuni

Hmm, something here has broken the dependency flattening. I'm seeing a stall again due to the file generation.

What CMake version?

hebasto avatar Feb 13 '25 21:02 hebasto

@theuni

Hmm, something here has broken the dependency flattening. I'm seeing a stall again due to the file generation.

I've removed the MAIN_DEPENDENCY options (I don't recall the motivation behind their introduction). A comparison of the resulting build.ninja files reveals no changes in dependencies.

hebasto avatar Feb 21 '25 11:02 hebasto

I've removed the MAIN_DEPENDENCY options (I don't recall the motivation behind their introduction). A comparison of the resulting build.ninja files reveals no changes in dependencies.

I believe MAIN_DEPENDENCY is MSVC related, so it wouldn't show up in the build.ninja. Did it help with something there?

theuni avatar Feb 21 '25 18:02 theuni

@theuni

Hmm, something here has broken the dependency flattening. I'm seeing a stall again due to the file generation.

Ok, Ignore this. I believe I was testing with make, where the stall is expected. Ninja is indeed unchanged.

theuni avatar Feb 21 '25 18:02 theuni

re-ACK ecf54a32ed26a50e861fca559e43ec1f9dee93b7

Only removed MAIN_DEPENDENCY since last review.

fjahr avatar Feb 21 '25 20:02 fjahr

re-tACK ecf54a32ed26a50e861fca559e43ec1f9dee93b7

The range-diff shows that we persevere the DEPENDS_EXPLICIT_OPT check added in #30911.

Checked the same thing as last time: https://github.com/bitcoin/bitcoin/pull/30901#issuecomment-2598371523

My cmake knowledge is also limited, but I like that this removes duplication.

It still is, and this PR still does.

Sjors avatar Mar 03 '25 13:03 Sjors

I believe MAIN_DEPENDENCY is MSVC related, so it wouldn't show up in the build.ninja. Did it help with something there?

It:

is treated just like any value given to the DEPENDS option but also suggests to Visual Studio generators where to hang the custom command.

I'm not sure how useful it is.

hebasto avatar Mar 03 '25 13:03 hebasto