Skip to content

Commit 20560b9

Browse files
committed
A few improvements relating to clangd
- update the include paths in compile_flags.txt to fix lsp issues. - parallelize the execution of clangd in the clangd-check.sh script. - update clangd-check.sh to list headers that were not found. Tested on Linux, macOS, and Windows: there are no missing include files except for webgpu headers that are not used in the standard workerd build. Manual check: server.cc has no clangd include errors in vscode.
1 parent ed6e0ef commit 20560b9

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

compile_flags.txt

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
-stdlib=libc++
33
-xc++
44
-nostdinc
5-
-Ibazel-bin
6-
-Ibazel-bin/external/capnp-cpp/src
75
-Ibazel-bin/external/com_googlesource_chromium_base_trace_event_common/_virtual_includes/trace_event_common
86
-Ibazel-bin/external/dawn/include
9-
-Iexternal/capnp-cpp/src
7+
-Ibazel-bin/external/com_cloudflare_lol_html/_virtual_includes/lolhtml
108
-Iexternal/com_google_benchmark/include/
119
-Iexternal/dawn/include
1210
-Isrc
@@ -19,9 +17,19 @@
1917
-isystem/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/Current/Headers
2018
-isystemC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include
2119
-isystemc:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt
20+
-isystembazel-bin/_virtual_includes/icudata-embed
21+
-isystembazel-bin/external/capnp-cpp/src
22+
-isystembazel-bin/external/capnp-cpp/src/capnp/_virtual_includes/capnp
23+
-isystembazel-bin/external/capnp-cpp/src/capnp/compat/_virtual_includes/http-over-capnp
24+
-isystembazel-bin/external/capnp-cpp/src/capnp/compat/_virtual_includes/json
25+
-isystembazel-bin/external/capnp-cpp/src/kj/_virtual_includes/kj
26+
-isystembazel-bin/external/capnp-cpp/src/kj/_virtual_includes/kj-async
27+
-isystembazel-bin/external/capnp-cpp/src/kj/compat/_virtual_includes/kj-http
28+
-isystembazel-bin/external/capnp-cpp/src/kj/compat/_virtual_includes/kj-tls
2229
-isystembazel-bin/external/v8
2330
-isystembazel-bin/external/v8/icu
2431
-isystembazel-bin/src
32+
-isystembazel-workerd/external/ssl/src/include
2533
-isystemexternal/brotli/c/include
2634
-isystemexternal/com_googlesource_chromium_icu/source/common
2735
-isystemexternal/icu

tools/unix/clangd-check.sh

+38-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,46 @@
55

66
output_dir=$(mktemp -d)
77
top_of_tree=$(git rev-parse --show-toplevel)
8+
declare -a job_pids
9+
10+
# Guess at number of CPUs (could be probed, but portable requires work).
11+
jobs_max=8
12+
13+
# Check bash version to see if `wait -n` is supported. This allows waiting on first of any
14+
# process specified as an argument to wait to exit rather than waiting for all the processes
15+
# specified to exit. (ie batch vs stream).
16+
bash_major=$(echo $BASH_VERSION | sed -e 's/\..*/0000/')
17+
bash_minor=$(echo $BASH_VERSION | sed -e 's/^[^.]*\.//' -e 's/\..*//')
18+
bash_linear=$(($bash_major + $bash_minor))
19+
if [ ${bash_linear} -ge 50001 ]; then
20+
wait_args="-n"
21+
fi
822

923
cd "${top_of_tree}"
1024
for i in $(find . -name '*.h' -o -name '*.c++'); do
25+
if [ ${#job_pids[*]} -eq ${jobs_max} ]; then
26+
# macOS inparticular is stuck on an older version of bash and does not support `wait -n`
27+
# here so child processes will run as batch waiting for all to complete there.
28+
wait ${wait_args} "${job_pids[@]}"
29+
for job_pid in "${job_pids[@]}"; do
30+
if ! kill -0 ${job_pid} 2>/dev/null ; then
31+
unset job_pids[${job_pid}]
32+
fi
33+
done
34+
fi
1135
j=${output_dir}/$(echo $i | sed -e 's@^\./@@' -e s@/@_@g)
12-
echo Scanning $i =\> $j
13-
clangd --check=$i 1>$j 2>&1
36+
echo -n Scanning $i =\> $j
37+
clangd --check=$i 1>$j 2>&1 &
38+
echo " [$!]"
39+
job_pids[$!]=$!
1440
done
41+
42+
echo "Checking for broken includes."
43+
grep "not found" ${output_dir}/*
44+
45+
cat <<EOF
46+
47+
You may also want to inspect the output files for other issues.
48+
49+
Please update compile_flags.txt to resolve any issues found.
50+
EOF

0 commit comments

Comments
 (0)