Skip to content

Commit 184a8ab

Browse files
authored
Merge pull request NVIDIA#1452 from NVIDIA/better-clangd-integration
help clangd find the compilation database for IDE code complete goodness
2 parents 37fc793 + 034b85a commit 184a8ab

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ callgrind.*
1313
*.o
1414
a.out
1515
*.code-workspace
16+
sanitizer-ignorelist.txt

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ message(STATUS "Build year : ${STDEXEC_BUILD_YEAR}")
6868
message(STATUS)
6969

7070
# Integrate with LLVM/clang tooling
71-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
71+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/clangd_compile_info.cmake)
7272

7373
# Write the version header
7474
rapids_cmake_write_version_file(include/stdexec_version_config.hpp)

cmake/clangd_compile_info.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_utilities.cmake)
17+
18+
# Tell cmake to generate a json file of compile commands for clangd:
19+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
20+
21+
# Symlink the compile command output to the source dir, where clangd will find it.
22+
set(compile_commands_file "${CMAKE_BINARY_DIR}/compile_commands.json")
23+
set(compile_commands_link "${CMAKE_SOURCE_DIR}/compile_commands.json")
24+
message(STATUS "Creating symlink from ${compile_commands_link} to ${compile_commands_file}...")
25+
stdexec_execute_non_fatal_process(COMMAND
26+
"${CMAKE_COMMAND}" -E rm -f "${compile_commands_link}")
27+
stdexec_execute_non_fatal_process(COMMAND
28+
"${CMAKE_COMMAND}" -E touch "${compile_commands_file}")
29+
stdexec_execute_non_fatal_process(COMMAND
30+
"${CMAKE_COMMAND}" -E create_symlink "${compile_commands_file}" "${compile_commands_link}")

cmake/cmake_utilities.cmake

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Passes all args directly to execute_process while setting up the following
17+
# results variables and propagating them to the caller's scope:
18+
#
19+
# - stdexec_process_exit_code
20+
# - stdexec_process_stdout
21+
# - stdexec_process_stderr
22+
#
23+
# If the command
24+
# is not successful (e.g. the last command does not return zero), a non-fatal
25+
# warning is printed.
26+
function(stdexec_execute_non_fatal_process)
27+
execute_process(${ARGN}
28+
RESULT_VARIABLE stdexec_process_exit_code
29+
OUTPUT_VARIABLE stdexec_process_stdout
30+
ERROR_VARIABLE stdexec_process_stderr
31+
)
32+
33+
if (NOT stdexec_process_exit_code EQUAL 0)
34+
message(WARNING
35+
"execute_process failed with non-zero exit code: ${stdexec_process_exit_code}\n"
36+
"${ARGN}\n"
37+
"stdout:\n${stdexec_process_stdout}\n"
38+
"stderr:\n${stdexec_process_stderr}\n"
39+
)
40+
endif()
41+
42+
set(stdexec_process_exit_code "${stdexec_process_exit_code}" PARENT_SCOPE)
43+
set(stdexec_process_stdout "${stdexec_process_stdout}" PARENT_SCOPE)
44+
set(stdexec_process_stderr "${stdexec_process_stderr}" PARENT_SCOPE)
45+
endfunction()

include/stdexec/__detail/__transform_completion_signatures.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// include these after __execution_fwd.hpp
2121
#include "__completion_signatures.hpp"
2222
#include "__concepts.hpp"
23-
#include "__debug.hpp"
23+
#include "__debug.hpp" // IWYU pragma: keep
2424
#include "__diagnostics.hpp"
2525
#include "__senders_core.hpp"
2626
#include "__meta.hpp"

0 commit comments

Comments
 (0)