Skip to content

Commit

Permalink
BUILD, WORKSPACE: Add Hedron's Compile Commands Extractor for Bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
ivucica committed Sep 15, 2023
1 parent 29c257e commit 81e2093
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ __all.a
stamp-h1
config.status
configure
yatc.ico.png
yatc.ico.png
### Automatically added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor
# Ignore the `external` link (that is added by `bazel-compile-commands-extractor`). The link differs between macOS/Linux and Windows, so it shouldn't be checked in. The pattern must not end with a trailing `/` because it's a symlink on macOS/Linux.
/external
# Ignore links to Bazel's output. The pattern needs the `*` because people can change the name of the directory into which your repository is cloned (changing the `bazel-<workspace_name>` symlink), and must not end with a trailing `/` because it's a symlink on macOS/Linux.
/bazel-*
# Ignore generated output. Although valuable (after all, the primary purpose of `bazel-compile-commands-extractor` is to produce `compile_commands.json`!), it should not be checked in.
/compile_commands.json
# Ignore the directory in which `clangd` stores its local index.
/.cache/
19 changes: 19 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -841,3 +841,22 @@ genrule(
"$(location //tools/pictool:pictool) $(location YATC.pic) 1 $(location inv.bmp) --topic",
]),
)

load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")

refresh_compile_commands(
name = "refresh_compile_commands",

# Specify the targets of interest.
# For example, specify a dict of targets and any flags required to build.
targets = {
#"//:my_output_1": "--important_flag1 --important_flag2=true",
#"//:my_output_2": "",
"//:yatc": "",
},
# No need to add flags already in .bazelrc. They're automatically picked up.
# If you don't need flags, a list of targets is also okay, as is a single target string.
# Wildcard patterns, like //... for everything, *are* allowed here, just like a build.
# As are additional targets (+) and subtractions (-), like in bazel query https://docs.bazel.build/versions/main/query.html#expressions
# And if you're working on a header-only library, specify a test or binary target that compiles it.
)
18 changes: 18 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ local_repository(
path = __workspace_dir__ + "/vendor/github.com/bazelregistry/sdl2",
)


# Hedron's Compile Commands Extractor for Bazel
# https://github.com/hedronvision/bazel-compile-commands-extractor
http_archive(
name = "hedron_compile_commands",

# Replace the commit hash in both places (below) with the latest, rather than using the stale one here.
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/ed994039a951b736091776d677f324b3903ef939.tar.gz",
strip_prefix = "bazel-compile-commands-extractor-ed994039a951b736091776d677f324b3903ef939",
# When you first run this tool, it'll recommend a sha256 hash to put here with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = ..."
sha256 = "085bde6c5212c8c1603595341ffe7133108034808d8c819f8978b2b303afc9e7",
)
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
hedron_compile_commands_setup()
# To refresh C++ flags, run bazel run @hedron_compile_commands//:refresh_all


# Toolchains for Resource Compilation (.rc files on Windows).
#load("@bazel_tools//src/main/res:local_config_winsdk.bzl", "local_config_winsdk")
#local_config_winsdk()

0 comments on commit 81e2093

Please sign in to comment.