Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
Fangrui Song edited this page Dec 25, 2017 · 43 revisions

Build

Default (--variant=release)

This should meet most users' need.

$ ./waf configure --prefix ~/.local/stow/cquery  # --prefix is optional, it specifies install directory
$ ./waf build    # -g -O3, built build/release/bin/cquery
$ ./waf install  # optional, copies the executable to $PREFIX/bin/cquery

Debug (--variant=debug)

Use this setting if you want to use gdb/lldb to debug cquery.

$ ./waf configure --variant=debug
$ ./waf build --variant=debug  # -g -O0, built build/debug/bin/cquery

GCC sometimes emits better debug information, pass --check-cxx-compiler=g++ if you want to use g++ instead of clang++ to build cquery.

Address sanitizer (--variant=asan)

$ ./waf configure --variant=asan
$ ./waf build --variant=asan  # -g -O -fsanitize=address,undefined, built build/asan/bin/cquery

System clang instead of bundled clang+llvm-*-*-*

Default build (--variant=release) uses bundled clang+llvm. If you have clang installed on your system and do not want to see build/release/lib/clang+llvm-4.0.0-x86_64-linux-gnu-ubuntu-14.04/ installed to your PREFIX:

# If you have `llvm-config-3.9` in your $PATH
./waf configure --variant=system --use-system-clang --llvm-config=llvm-config-3.9

Other bundled versions:

./waf configure --variant=clang5 --bundled-clang=5.0.0

5.0.0 is not recommended because a bug was introduced before 5.0.0 and the fix https://reviews.llvm.org/D37700 is not included in the 5.0.0 release. You may see bogus unterminated #if errors.

Windows

It is recommended to use Windows 10 (build >= 14972) and enable Developer Mode, as the build script will create several symbolic links during the build process. If creating symbolic link is not possible (most possibly due to lacking privilege), it will do a copy instead.

Install Visual Studio 2017 Build Tools, Python and 7-Zip. 7z.exe is expected to be in PATH. You may then simply:

python waf configure
python waf build

waf install is not possible on Windows, instead you could simply copy build\release\bin\*.

To use system clang:

python waf configure --use-system-clang --clang-prefix "C:\Program Files\LLVM\"

Generate compile_commands.json

Guillaume Papin(@Scarcasm) has a thorough article about compilation databases.

% mkdir build
% (cd build; cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=YES ..)
% ln -s build/compile_commands.json

Bear is a tool that generates a compilation database for clang tooling. It can be used for any project based on Makefile.

bear make
# generates compile_commands.json
ninja -t compdb rule_names... > compile_commands.json

Load the clang_compilation_database tool in your wscript:

def configure(conf):
    conf.load('clang_compilation_database')
./waf configure build
ln -s build/compile_commands.json

Editor configuration

Diagnostics

Dump JSON requests and responses:

sudo sysdig -As999 --unbuffered -p '%evt.type %evt.buffer' "proc.pid=$(pgrep -fn build/app) and fd.type=pipe" | egrep -v '^Content|^$'

Passing the option --log-stdin-stdout-to-stderr.

Some issues introduce diagnostic methods: