Bear is a tool that generates a compilation database for clang tooling.
The JSON compilation database is used in the clang project to provide information on how a single compilation unit is processed. With this, it is easy to re-run the compilation with alternate programs.
Some build system natively supports the generation of JSON compilation database. For projects which does not use such build tool, Bear generates the JSON file during the build process.
How to install
Bear is packaged for many distributions. Check out your package manager. Or build it from source.
How to use
After installation the usage is like this:
bear -- <your-build-command>
The output file called compile_commands.json is saved in the current directory.
For more options you can check the man page or pass --help parameter. Note that if you want to pass parameter to Bear, pass those before the -- sign, everything after that will be the build command.
Please be aware that some package manager still ship our old 2.4.x release. In that case please omit the extra -- sign or consult your local documentation.
For more, read the man pages or wiki of the project, which talks about limitations, known issues and platform specific usage.
Problem reports
Before you open a new problem report, please look at the wiki if your problem is a known one with documented workaround. It's also helpful to look at older (maybe closed) issues before you open a new one.
If you decided to report a problem, try to give as much context as it would help me to reproduce the error you see. If you just have a question about the usage, please don't be shy, ask your question in an issue or in chat.
If you found a bug, but also found a fix for it, please share it with me and open a pull request.
Please follow the contribution guide when you do these.
Thanks to JetBrains for donating product licenses to help develop Bear.
from https://github.com/rizsotto/Bear
-----
How to build
Bear should be quite portable on UNIX operating systems. It has been tested on FreeBSD, GNU/Linux and OS X.
Build dependencies
- C++ compiler, to compile the sources. (Should support C++17 dialect.)
- CMake, to configure the build. (Minimum version is 3.12) And a build tool supported by CMake.
- pkg-config to look up dependencies' compiler flags.
- protoc and grpc_cpp_plugin commands. (See gRPC dependencies.)
Dependencies
The dependencies can come from OS packages or the build will fetch the sources and build locally.
Developer dependencies:
- python >= 3.5
- googletest >= 1.10
- lit >= 0.7
Build commands
Ideally, you should build Bear in a separate build directory.
cmake -DENABLE_UNIT_TESTS=OFF -DENABLE_FUNC_TESTS=OFF $BEAR_SOURCE_DIR
make all
make install
You can configure the build process with passing arguments to cmake.
One of the flags you might want to pay attention is the CMAKE_INSTALL_LIBDIR flag, which has to be the directory name for libraries. The value of this varies for different distribution: debian derivatives are using lib/i386-linux-gnu and lib/x86_64-linux-gnu, while many other distributions are simple lib and lib64 directories. Check out where the system libc.so is. And use that directory name for the CMAKE_INSTALL_LIBDIR. (If your system has it as /lib/x86_64-linux-gnu/libc.so, then lib/x86_64-linux-gnu is the value you need to use.) Passing the flag looks like this:
cmake -DCMAKE_INSTALL_LIBDIR=lib/x86_64-linux-gnu ... $BEAR_SOURCE_DIR
To enable multilib support, an extra CMake flag is needed. ENABLE_MULTILIB is defined by this project and will change where Bear looks for files. To use multilib, you need to make the CMAKE_INSTALL_LIBDIR set right. (See the paragraph above.) Passing the flag looks like this:
cmake -DENABLE_MULTILIB=ON ... $BEAR_SOURCE_DIR
To run test during the build process, you will need to install the test frameworks and re-configure the build. For unit testing Bear uses googletest, which will be built from source if not already installed.
# install `lit` the functional test framework into a python virtualenv
mkvirtualenv bear
pip install lit
# it's important to re-run the configure step again
cmake $BEAR_SOURCE_DIR
cmake --build $build_dir --parallel 4
OS specific notes
Install dependencies from packages on Fedora 32/33
dnf install python cmake pkg-config
dnf install json-devel spdlog-devel fmt-devel grpc-devel grpc-plugins
dnf install gtest-devel gmock-devel # optional for running the tests
Install dependencies from packages on Arch
pacman -S python cmake pkg-config
pacman -S grpc spdlog fmt nlohmann-json
pacman -S gtest gmock # optional for running the tests
Install dependencies from packages on Ubuntu 20.04
apt-get install python cmake pkg-config
apt-get install libfmt-dev libspdlog-dev nlohmann-json3-dev \
libgrpc++-dev protobuf-compiler-grpc libssl-dev
Install dependencies from packages from Brew
brew install fmt spdlog nlohmann-json grpc pkg-config
Install dependencies from packages on Alpine edge
apk add git cmake pkgconf make g++
apk add fmt-dev spdlog-dev nlohmann-json protobuf-dev grpc-dev c-ares-dev
Platform: macOS
Xcode < 11 or macOS < 10.15 users should get LLVM Clang binaries and headers. Make sure that clang++ -v returns the correct InstalledDir. This is because std::filesystem is not available on Clang supplied with Xcode < 11, and std::filesystem::path is not available in system C++ dylib for macOS < 10.15.
If OpenSSL is installed via Brew, and it's keg-only, run the following (before the build) for pkg-config to find it as grpc's dependency:
export PKG_CONFIG_PATH=$(brew --prefix)/opt/openssl@1.1/lib/pkgconfigfrom https://github.com/rizsotto/Bear/blob/master/INSTALL.md-----Swallow
Swallow is a tool that generates a compilation database for clang tooling.
It simulates a bulid by "swallowing" build commands. If it sees a GCC command that it thinks generates a compilation unit, it prevents it from running and logs it into a compile_commands.json.
Sometimes clang based tooling isn't smart enough to do the right thing. If the -c command is used, it will attempt to clangify the command to help other tooling out. See swallow --help for more info after building.
Building
Needs rust, camke and a c compiler.
mkdir build
cd build
cmake ..
make
make install
Credits
This project draws heavily on code from https://github.com/rizsotto/Bear, thanks for the hard work!
from https://github.com/sphaerophoria/swallow
No comments:
Post a Comment