Skip to content
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

enforce cmake-format and cmake-lint #4889

Closed
wants to merge 8 commits into from

Conversation

jameslamb
Copy link
Member

Contributes to rapidsai/build-planning#136

Proposes using cmake-format and cmake-lint here to standardize CMake code style, similar to the way that other RAPIDS libraries do.

The new files cpp/scripts/run-cmake-format.sh and cpp/cmake/config.json were borrowed and then lightly adapted from cuDF (code link).

All changes in CMakeLists.txt and .cmake files here were made automatically by cmake-format, like this:

FORMAT_FILE_URL="https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-25.02/cmake-format-rapids-cmake.json"
export RAPIDS_CMAKE_FORMAT_FILE=/tmp/rapids_cmake_ci/cmake-formats-rapids-cmake.json
mkdir -p $(dirname ${RAPIDS_CMAKE_FORMAT_FILE})
wget -O ${RAPIDS_CMAKE_FORMAT_FILE} ${FORMAT_FILE_URL}

@jameslamb jameslamb added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Jan 23, 2025
Copy link

copy-pr-bot bot commented Jan 23, 2025

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@jameslamb jameslamb changed the title WIP: enforce cmake-format and cmake-lint enforce cmake-format and cmake-lint Jan 23, 2025
@jameslamb jameslamb marked this pull request as ready for review January 23, 2025 20:22
@jameslamb jameslamb requested review from a team as code owners January 23, 2025 20:22
@jameslamb jameslamb requested a review from gforsyth January 23, 2025 20:22
Copy link

@gforsyth gforsyth left a comment

Choose a reason for hiding this comment

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

Looks good -- just a few small nits and nothing blocking. Need to run pre-commit to update the copyrights in the formatted files, too

.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
cpp/scripts/run-cmake-format.sh Outdated Show resolved Hide resolved
cpp/scripts/run-cmake-format.sh Outdated Show resolved Hide resolved
cpp/scripts/run-cmake-format.sh Outdated Show resolved Hide resolved
@jameslamb jameslamb requested a review from gforsyth January 23, 2025 21:13
Copy link

@gforsyth gforsyth left a comment

Choose a reason for hiding this comment

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

:shipit:

@gforsyth
Copy link

Hmm, looks like cmake-format formatted something extra, though

OPTIONS
"BUILD_BENCHMARKS OFF"
"BUILD_TESTS OFF"
)
Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't look right to me, I must have mistake in the config, sorry 😬

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry @gforsyth , let me take this back into draft and reduce the size of this diff. I should have done that from the beginning.

Choose a reason for hiding this comment

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

All good!

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I think it's looking better, could you check again?

I:

@jameslamb jameslamb marked this pull request as draft January 23, 2025 21:39
@jameslamb jameslamb changed the title enforce cmake-format and cmake-lint WIP: enforce cmake-format and cmake-lint Jan 23, 2025
Comment on lines +25 to +27
"markup": {
"enable_markup": false
},
Copy link
Member Author

Choose a reason for hiding this comment

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

This says "don't modify any comments"

ref: https://cmake-format.readthedocs.io/en/latest/configuration.html

Comment on lines +15 to +23
"rapids_cython_create_modules": {
"kwargs": {
"SOURCE_FILES": "?",
"LINKED_LIBRARIES": "?",
"MODULE_PREFIX": "?",
"ASSOCIATED_TARGETS": "?"
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Telling cmake-format the signature of this function helps it to split keyword arguments out one per line.

@jameslamb
Copy link
Member Author

/ok to test

@jameslamb jameslamb changed the title WIP: enforce cmake-format and cmake-lint enforce cmake-format and cmake-lint Jan 23, 2025
@jameslamb jameslamb marked this pull request as ready for review January 23, 2025 23:13
@jameslamb jameslamb requested a review from gforsyth January 24, 2025 03:25
Copy link
Contributor

@vyasr vyasr left a comment

Choose a reason for hiding this comment

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

I hate to expand scope on you too much, so feel free to push back, but since this kind of change is fairly low priority I think it's OK to delay it and take the opportunity to create a new hook in our repo encapsulating the logic we use to wrap the base cmakelang hooks. Presumably we're always going to want the same things: support for rapids-cmake functions (hopefully via some smarter fetching of the format file than the somewhat naive version I wrote for this hook originally in cudf), support for some extra functions like those from CPM or commonly defined functions in RAPIDS like ConfigureTest/ConfigureBench, the same "soft" failure behavior, etc. When I originally filed rapidsai/cudf#9484, and especially after we created https://github.com/rapidsai/pre-commit-hooks/ I had hoped we could generalize the cudf hook rather than copy it wholesale into every RAPIDS repo.

If preferred, we could also merge this PR and then work on the generalized hook afterwards, I just don't want to forget that we should probably do it.

CC @KyleFromNVIDIA

@jameslamb
Copy link
Member Author

delay it and take the opportunity to create a new hook in our repo encapsulating the logic we use to wrap the base cmakelang hooks

Ok sure.

Given that comment and rapidsai/cuspatial#1516 (comment), I'll rip out the CMake formatting part of rapidsai/build-planning#136 completely and put that into a different issue about finding a better long-term pattern that doesn't involve so much copying for files around the repos.

I'd only included it here because I'd made similar changes in response to recent reviews on the C++ wheels
work (rapidsai/raft#2531 (comment), rapidsai/cuvs#594 (comment)), so I thought this would be non-controversial. We have enough other stuff going on right now, don't need to be spending too much energy debating style-related stuff.

@gforsyth sorry to close a PR you spent time reviewing, thank you very much for doing that.

@jameslamb
Copy link
Member Author

Opened rapidsai/pre-commit-hooks#62 for that separate discussion about a better long-term pattern for CMake formatting.

@jameslamb jameslamb deleted the cmake-format branch January 24, 2025 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci CMake cuGraph improvement Improvement / enhancement to an existing function non-breaking Non-breaking change python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants