From b23c33f72a65167a67c40b5174b0a42ffbffa265 Mon Sep 17 00:00:00 2001 From: Liu Jiaming Date: Mon, 4 Apr 2022 15:54:46 +0800 Subject: [PATCH] Docs: instructions for use as external dependency --- README.md | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 122f0da..3233b9d 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,60 @@ # bazel_iwyu -Bazel Support for IWYU. No Compilation Database needed. + +Bazel Support for IWYU. No Compilation Database needed. +Inspired by the [Bazel-Clang-Tidy](https://github.com/erenon/bazel_clang_tidy) project. ## How To Use 1. Build and Install IWYU 0.18.0+ (Not needed for Linux x86_64 on `master`) -2. Run IWYU +2. In your WORKSPACE file, add + +```python +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "com_github_storypku_bazel_iwyu", + sha256 = "", + strip_prefix = "bazel_iwyu-" + urls = [ + "https://github.com/storypku/bazel_iwyu/archive/.tar.gz", + ], +) + +load("@com_github_storypku_bazel_iwyu//bazel:dependencies.bzl", "bazel_iwyu_dependencies") +bazel_iwyu_dependencies() +``` + +3. Add the following to your bazelrc. (E.g., `.bazelrc`) + +``` +build:iwyu --aspects @com_github_storypku_bazel_iwyu//bazel/iwyu:iwyu.bzl%iwyu_aspect +build:iwyu --output_groups=report ``` + +4. Run IWYU + +```shell bazel build --config=iwyu //path/to/pkg:target ``` -3. Apply fixes +5. Apply fixes Suppose IWYU binaries/scripts can be found on PATH: -``` +```shell fix_includes.py --nosafe_headers < bazel-bin/path/to/pkg/.iwyu.txt ``` for Linux-x86_64, You may find it convenient to have the top-level "external" symlink -``` +```shell ln -s bazel-out/../../../external external ``` And run -``` +```shell external/iwyu_prebuilt_pkg/bin/fix_includes.py --nosafe_headers < bazel-bin/path/to/pkg/.iwyu.txt ``` @@ -38,3 +65,7 @@ external/iwyu_prebuilt_pkg/bin/fix_includes.py --nosafe_headers < bazel-bin/path 3. [ ] More IWYU mappings for other 3rd-party libraries, e.g., ABSL, Boost, Eigen, etc. 4. [ ] Gather multiple X.iwyu.txt into one. 5. [ ] Support for custom mapping files and IWYU options from users. + +## How to Contribute +As with other OSS projects, suggestions and PRs are welcome! +