Skip to content
Draft
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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index/vendor/integration_tests/testcases
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:
jobs:
build:
runs-on: ubuntu-24.04
timeout-minutes: 5
timeout-minutes: 15

steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 8 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ module(
)

bazel_dep(name = "rules_go", version = "0.53.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "gazelle", version = "0.42.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.24.0")

go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(
go_deps,
"org_golang_google_protobuf",
)
6 changes: 4 additions & 2 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ Controls how to handle cyclic dependencies between translation units:
- `merge`: All groups forming a cycle will be merged into a single one **(default)**
- `warn`: Don't modify rules forming a cycle, let user handle it manually

### `# gazelle:cc_indexfile <path>`

Adds index file, containing mapping between headers to rules providing their definitions and/or implementation.
Index allow for automatic dependency resolution for targets not managed by the gazelle, eg. provided by integrated package manager or vendored inside repository.
Multiple `cc_indexfile` are allowed. It's recommended to use it only in top-level BUILD file.
Argument of the directive needs to be a repository-root relative or absolute path.
Visit [external dependenices section](#external-dependencies) to learn how to obtain indexes.

## Rules for target rule selection

The extension automatically selects the appropriate rule type based on the following criteria:
Expand Down Expand Up @@ -142,6 +150,27 @@ bazel_dep(name = "fmt", version = "11.1.4", repo_name = "fmt_repo")
#include "boost/chrono.hpp" // Warning: defined in @boost.chrono//:boost.chrono but not added as bazel_dep

```
#### Vendored external dependencies

External dependenices vendored as part of Bazel repository typically might not be managed by Gazelle. To allow for dependency resolution based on these sources it is required to create a index using `@gazelle_cc//index/vendor` binary.

```bash
bazel run @gazelle_cc//index/rules_foreign_cc -- --output=vendored.ccindex $PWD
```

The resulting index needs to be added to Gazelle directive in top-level `BUILD` file.

```bazel
# gazelle cc_indexfile vendored.ccindex
```

Additional options for `@gazelle_cc//index/rules_foreign_cc`:

| Flag | Default | Definition |
| ---- | ------- | ---------- |
| --select=\<selector> | //third_party/..., //external/..., //vendored/... | Provides a selector for rules that should be indexed. Multiple --select flags are allowed |
| --output=\<path> | ./vendor.ccidx | Output file for created index |
| --verbose | false | Enable verbose logging and debug information |

#### Other package managers

Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/EngFlow/gazelle_cc

go 1.23.2

require github.com/bazelbuild/bazel-gazelle v0.42.0
require (
github.com/bazelbuild/bazel-gazelle v0.42.0
google.golang.org/protobuf v1.36.6
)

require (
github.com/bazelbuild/buildtools v0.0.0-20240918101019-be1c24cc9a44 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ github.com/bazelbuild/buildtools v0.0.0-20240918101019-be1c24cc9a44 h1:FGzENZi+S
github.com/bazelbuild/buildtools v0.0.0-20240918101019-be1c24cc9a44/go.mod h1:PLNUetjLa77TCCziPsz0EI8a6CUxgC+1jgmWv0H25tg=
github.com/bazelbuild/rules_go v0.50.1 h1:/BUvuaB8MEiUA2oLPPCGtuw5V+doAYyiGTFyoSWlkrw=
github.com/bazelbuild/rules_go v0.50.1/go.mod h1:Dhcz716Kqg1RHNWos+N6MlXNkjNP2EwZQ0LukRKJfMs=
github.com/bmatcuk/doublestar/v4 v4.7.1 h1:fdDeAqgT47acgwd9bd9HxJRDmc9UAmPpc+2m0CXv75Q=
github.com/bmatcuk/doublestar/v4 v4.7.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools/go/vcs v0.1.0-deprecated h1:cOIJqWBl99H1dH5LWizPa+0ImeeJq3t3cJjaeOWUAL4=
golang.org/x/tools/go/vcs v0.1.0-deprecated/go.mod h1:zUrvATBAvEI9535oC0yWYsLsHIV4Z7g63sNPVMtuBy8=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
7 changes: 7 additions & 0 deletions index/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_suite(
name = "integration_tests",
tags = ["manual"],
tests = [
"//index/vendor/integration_tests:integration_tests_test",
],
)
30 changes: 30 additions & 0 deletions index/internal/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
load("@rules_go//go:def.bzl", "go_library")
load("@rules_go//proto:def.bzl", "go_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")

# gazelle:proto package

proto_library(
name = "bazel_proto",
srcs = ["build.proto"],
visibility = ["//index:__subpackages__"],
)

go_proto_library(
name = "bazel_go_proto",
importpath = "github.com/EngFlow/gazelle_cc/index/internal/bazel",
proto = ":bazel_proto",
visibility = ["//index:__subpackages__"],
)

go_library(
name = "bazel",
srcs = ["query.go"],
embed = [":bazel_go_proto"],
importpath = "github.com/EngFlow/gazelle_cc/index/internal/bazel",
visibility = ["//index:__subpackages__"],
deps = [
"//index/internal/collections",
"@org_golang_google_protobuf//proto",
],
)
Loading