[RNE Rewrite] chore: set up clangd for C++ sources#1285
Merged
Conversation
Add a committed clangd config for the core package's C/C++ sources so the rewrite gets code intelligence and a shared, strict warning set: - compile_flags.txt: include roots / std / defines (third-party as -isystem so library warnings don't pollute our diagnostics); relative paths anchored to the package dir, so it is portable with no per-machine generation - .clangd: strict warning set (incl. -Wconversion/-Wsign-conversion) layered on top, with clangd's include cleaner disabled (ET umbrella headers) - .gitignore: track the shared config while keeping generated DBs local - CONTRIBUTING.md: document prerequisites and editor setup clang-tidy CI is a follow-up.
12 tasks
Add a lefthook pre-commit command that compiles staged cpp/ sources with the project's clangd warning set (compile_flags.txt + the -W flags in .clangd) and aborts the commit on any warning, keeping the editor and the commit gate in sync. It skips gracefully when no compiler or the provisioned ExecuTorch/JSI headers are available, so contributors who don't build native code are never blocked; bypass with `git commit --no-verify`.
Bring the existing cpp/ sources into compliance with the strict warning set so clangd (and the pre-commit guard) start clean: - comment out unused JSI host-function parameters (thisVal/args) using the /* name */ anonymous-parameter idiom - fix int -> size_t sign-conversions: route validated axis indices through a size_t axisIdx, make byte-offset sizes (hw, plane) size_t, and cast the few remaining count/index sites - reformat pre-existing clang-format drift in tokenizer.cpp
bc7528f to
b6084d6
Compare
barhanc
reviewed
Jun 26, 2026
Address review feedback: - skip with a notice if compile_flags.txt or .clangd are missing - read the last line of compile_flags.txt even without a trailing newline
barhanc
approved these changes
Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Sets up a committed clangd config for the core package's C/C++ sources so the rewrite gets code intelligence and a shared, strict warning set, and enforces that set at commit time. First step of #1271; clang-tidy CI is a follow-up (#1286).
compile_flags.txt— include roots /-std=c++20/ defines, with third-party headers (ExecuTorch/torch/JSI) as-isystemso their warnings don't pollute our diagnostics. Relative paths anchored to the package dir, so it is portable with no per-machine generation..clangd— strict warning set layered on top (incl.-Wconversion/-Wsign-conversion), with clangd's include cleaner disabled (ExecuTorch umbrella headers misreport includes).scripts/check-cpp-warnings.sh+lefthook.yml— apre-commitcommand that compiles stagedcpp/sources with the same warning set and aborts the commit on any warning, keeping the editor and the commit gate in sync. It skips gracefully (never blocks) when no compiler or the provisioned headers are available; bypass withgit commit --no-verify..gitignore— track the shared config while keeping generatedcompile_commands.jsonlocal.CONTRIBUTING.md— prerequisites (provisionedthird-party/include+yarn install), editor setup, and the pre-commit behavior.Introduces a breaking change?
Type of change
Tested on
Testing instructions
packages/react-native-executorch/third-party/includeand runyarn install.packages/react-native-executorch/cppin an editor with the clangd extension (MS C/C++ IntelliSense disabled); confirm the<executorch/...>/<jsi/jsi.h>includes resolve and the current sources are clean.cpp/core/dtype.cpp:-isystem).git addthat change andgit commit— the pre-commit hook aborts with the warning printed. Verified end-to-end via lefthook: warning →cpp-warnings ❌(exit 1); clean →✔️(exit 0). Revert afterwards.Related issues
#1271
Checklist