Skip to content

Commit 9a9bc1d

Browse files
authored
Vendor RAPIDS.cmake to avoid network call. (#1886)
This works around a problem where GitHub is rejecting requests to the `githubusercontent.com` CDN. We vendor the contents of `RAPIDS.cmake` from `rapidsai/rapids-cmake` to avoid a network call. xref: rapidsai/rapids-cmake#809 xref: rapidsai/build-infra#206 Original motivation for `RAPIDS.cmake`: rapidsai/rapids-cmake#45 The main design question raised by this PR is whether we still need this layer of indirection, or if inlining is acceptable (more lines of code, no centralized logic, but the contents of `RAPIDS.cmake` have been quite stable). Authors: - Bradley Dice (https://github.com/bdice) Approvers: - Peter Andreas Entschev (https://github.com/pentschev) - Kyle Edwards (https://github.com/KyleFromNVIDIA) URL: #1886
1 parent 82c3288 commit 9a9bc1d

File tree

5 files changed

+96
-12
lines changed

5 files changed

+96
-12
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
cmake_minimum_required(VERSION 3.30.4 FATAL_ERROR)
1616

17-
include(rapids_config.cmake)
17+
include(cmake/rapids_config.cmake)
1818

1919
include(rapids-cmake)
2020
include(rapids-cpm)

cmake/RAPIDS.cmake

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# =============================================================================
2+
# Copyright (c) 2021-2025, NVIDIA CORPORATION.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
# in compliance with the License. You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software distributed under the License
10+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
# or implied. See the License for the specific language governing permissions and limitations under
12+
# the License.
13+
# =============================================================================
14+
#
15+
# This is the preferred entry point for projects using rapids-cmake
16+
#
17+
# Enforce the minimum required CMake version for all users
18+
cmake_minimum_required(VERSION 3.30.4 FATAL_ERROR)
19+
20+
# Allow users to control which version is used
21+
if(NOT rapids-cmake-version OR NOT rapids-cmake-version MATCHES [[^([0-9][0-9])\.([0-9][0-9])$]])
22+
message(
23+
FATAL_ERROR "The CMake variable rapids-cmake-version must be defined in the format MAJOR.MINOR."
24+
)
25+
endif()
26+
27+
# Allow users to control which GitHub repo is fetched
28+
if(NOT rapids-cmake-repo)
29+
# Define a default repo if the user doesn't set one
30+
set(rapids-cmake-repo rapidsai/rapids-cmake)
31+
endif()
32+
33+
# Allow users to control which branch is fetched
34+
if(NOT rapids-cmake-branch)
35+
# Define a default branch if the user doesn't set one
36+
set(rapids-cmake-branch "branch-${rapids-cmake-version}")
37+
endif()
38+
39+
# Allow users to control the exact URL passed to FetchContent
40+
if(NOT rapids-cmake-url)
41+
# Construct a default URL if the user doesn't set one
42+
set(rapids-cmake-url "https://github.com/${rapids-cmake-repo}/")
43+
44+
# In order of specificity
45+
if(rapids-cmake-fetch-via-git)
46+
if(rapids-cmake-sha)
47+
# An exact git SHA takes precedence over anything
48+
set(rapids-cmake-value-to-clone "${rapids-cmake-sha}")
49+
elseif(rapids-cmake-tag)
50+
# Followed by a git tag name
51+
set(rapids-cmake-value-to-clone "${rapids-cmake-tag}")
52+
else()
53+
# Or if neither of the above two were defined, use a branch
54+
set(rapids-cmake-value-to-clone "${rapids-cmake-branch}")
55+
endif()
56+
else()
57+
if(rapids-cmake-sha)
58+
# An exact git SHA takes precedence over anything
59+
set(rapids-cmake-value-to-clone "archive/${rapids-cmake-sha}.zip")
60+
elseif(rapids-cmake-tag)
61+
# Followed by a git tag name
62+
set(rapids-cmake-value-to-clone "archive/refs/tags/${rapids-cmake-tag}.zip")
63+
else()
64+
# Or if neither of the above two were defined, use a branch
65+
set(rapids-cmake-value-to-clone "archive/refs/heads/${rapids-cmake-branch}.zip")
66+
endif()
67+
endif()
68+
endif()
69+
70+
include(FetchContent)
71+
if(rapids-cmake-fetch-via-git)
72+
FetchContent_Declare(
73+
rapids-cmake
74+
GIT_REPOSITORY "${rapids-cmake-url}"
75+
GIT_TAG "${rapids-cmake-value-to-clone}")
76+
else()
77+
string(APPEND rapids-cmake-url "${rapids-cmake-value-to-clone}")
78+
FetchContent_Declare(rapids-cmake URL "${rapids-cmake-url}")
79+
endif()
80+
FetchContent_GetProperties(rapids-cmake)
81+
if(rapids-cmake_POPULATED)
82+
# Something else has already populated rapids-cmake, only thing we need to do is setup the
83+
# CMAKE_MODULE_PATH
84+
if(NOT "${rapids-cmake-dir}" IN_LIST CMAKE_MODULE_PATH)
85+
list(APPEND CMAKE_MODULE_PATH "${rapids-cmake-dir}")
86+
endif()
87+
else()
88+
FetchContent_MakeAvailable(rapids-cmake)
89+
endif()

rapids_config.cmake renamed to cmake/rapids_config.cmake

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# =============================================================================
2-
# Copyright (c) 2018-2024, NVIDIA CORPORATION.
2+
# Copyright (c) 2018-2025, NVIDIA CORPORATION.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
# in compliance with the License. You may obtain a copy of the License at
@@ -11,7 +11,7 @@
1111
# or implied. See the License for the specific language governing permissions and limitations under
1212
# the License.
1313
# =============================================================================
14-
file(READ "${CMAKE_CURRENT_LIST_DIR}/VERSION" _rapids_version)
14+
file(READ "${CMAKE_CURRENT_LIST_DIR}/../VERSION" _rapids_version)
1515
if(_rapids_version MATCHES [[^([0-9][0-9])\.([0-9][0-9])\.([0-9][0-9])]])
1616
set(RAPIDS_VERSION_MAJOR "${CMAKE_MATCH_1}")
1717
set(RAPIDS_VERSION_MINOR "${CMAKE_MATCH_2}")
@@ -25,10 +25,5 @@ else()
2525
"Could not determine RAPIDS version. Contents of VERSION file:\n${_rapids_version_formatted}")
2626
endif()
2727

28-
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/RMM_RAPIDS-${RAPIDS_VERSION_MAJOR_MINOR}.cmake")
29-
file(
30-
DOWNLOAD
31-
"https://raw.githubusercontent.com/rapidsai/rapids-cmake/branch-${RAPIDS_VERSION_MAJOR_MINOR}/RAPIDS.cmake"
32-
"${CMAKE_CURRENT_BINARY_DIR}/RMM_RAPIDS-${RAPIDS_VERSION_MAJOR_MINOR}.cmake")
33-
endif()
34-
include("${CMAKE_CURRENT_BINARY_DIR}/RMM_RAPIDS-${RAPIDS_VERSION_MAJOR_MINOR}.cmake")
28+
set(rapids-cmake-version "${RAPIDS_VERSION_MAJOR_MINOR}")
29+
include("${CMAKE_CURRENT_LIST_DIR}/RAPIDS.cmake")

python/librmm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
cmake_minimum_required(VERSION 3.30.4 FATAL_ERROR)
1616

17-
include(../../rapids_config.cmake)
17+
include(../../cmake/rapids_config.cmake)
1818

1919
project(
2020
librmm-python

python/rmm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
cmake_minimum_required(VERSION 3.30.4 FATAL_ERROR)
1616

17-
include(../../rapids_config.cmake)
17+
include(../../cmake/rapids_config.cmake)
1818

1919
project(
2020
rmm-python

0 commit comments

Comments
 (0)