Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# clangd configuration for the Bazel-driven C++ build.
#
# Requires a compile_commands.json at the workspace root. Generate it with:
# bazel run //:refresh_compile_commands
#
# See CONTRIBUTING.md ("Editor / clangd setup") for the full workflow.

CompileFlags:
CompilationDatabase: .
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ coverage.xml
*.pt2
examples/torchtrt_aoti_example/torchtrt_aoti_example
CLAUDE.md

# clangd compilation database (generated by `bazel run //:refresh_compile_commands`)
/compile_commands.json
/external/
19 changes: 19 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")

config_setting(
Expand Down Expand Up @@ -162,3 +163,21 @@ alias(
"//conditions:default": ":libtorchtrt_runtime_tar",
}),
)

# ---------------------------------------------------------------------------
# Developer tooling
# ---------------------------------------------------------------------------
# Generates `compile_commands.json` at the workspace root for clangd-based
# editors. Output is gitignored. Run on first checkout and after material
# build-graph changes:
# bazel run //:refresh_compile_commands
# See CONTRIBUTING.md ("Editor / clangd setup") for details.
refresh_compile_commands(
name = "refresh_compile_commands",
tags = ["manual"],
targets = [
"//core/...",
"//cpp/...",
"//tests/...",
],
)
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ Do try to fill an issue with your feature or bug before filling a PR (op support

Our build system relies on `bazel` (https://bazel.build/). Though there are many ways to install `bazel`, the preferred method is to use `bazelisk` (https://github.com/bazelbuild/bazelisk) which makes it simple to set up the correct version of bazel on the fly. Additional development dependencies can be installed via the `requirements-dev.txt` file.

#### Editor / clangd setup (optional)

For C++ code intelligence (go-to-definition, accurate diagnostics, completions) in any clangd-based editor — e.g. VSCode with the [clangd extension](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd), Cursor, Neovim, Emacs — generate a Bazel-aware compilation database:

```sh
bazel run //:refresh_compile_commands
```

This writes `compile_commands.json` at the workspace root (gitignored). Re-run it after pulling changes that materially affect the build graph (new targets, new headers, dependency bumps). The repo's `.clangd` file picks up the database automatically.

This is opt-in: developers who don't use clangd are unaffected, and the underlying `hedron_compile_commands` extractor is declared as a Bazel `dev_dependency`, so it does not enter the dep graph of consumers building against torch_tensorrt.

#### Communication

The primary location for discussion is GitHub issues and Github discussions. This is the best place for questions about the project and discussion about specific issues.
Expand Down
12 changes: 12 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ git_override(
remote = "https://github.com/narendasan/rules_pkg",
)

# Developer tooling: clangd-compatible compile_commands.json extractor.
# `dev_dependency = True` keeps this out of the dep graph for any project that
# consumes torch_tensorrt as a Bazel module. Refresh with:
# bazel run //:refresh_compile_commands
# See CONTRIBUTING.md ("Editor / clangd setup") for details.
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
git_override(
module_name = "hedron_compile_commands",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
commit = "0e990032f3c5a866e72615cf67e5ce22186dcb97",
)

new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")

local_torch = use_repo_rule("//toolchains:local_torch.bzl", "local_torch")
Expand Down
12 changes: 12 additions & 0 deletions toolchains/ci_workspaces/MODULE.bazel.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ git_override(
remote = "https://github.com/narendasan/rules_pkg",
)

# Developer tooling: clangd-compatible compile_commands.json extractor.
# `dev_dependency = True` keeps this out of the dep graph for any project that
# consumes torch_tensorrt as a Bazel module. Refresh with:
# bazel run //:refresh_compile_commands
# See CONTRIBUTING.md ("Editor / clangd setup") for details.
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
git_override(
module_name = "hedron_compile_commands",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
commit = "0e990032f3c5a866e72615cf67e5ce22186dcb97",
)

local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")

torch_nccl_detect = use_repo_rule("//toolchains/torch_nccl:defs.bzl", "torch_nccl_detect")
Expand Down
Loading