'in-tree include directory with bazel custom toolchain
Is it possible to configure a Bazel custom toolchain to include directories in the repository?
Assume that I have following in the root of my repository:
sysroots/armhf/include/myheader.h
sysroots/amd64/include/myheader.h
myproject1/component.cpp
myproject2/component.cpp
I'd like to configure toolchain such that when I run bazel build --config armhf
, component.cpp
files including myheader.h
would get the header from sysroot/armhf/include
directory, and when I run bazel build --config amd64
, file from corresponding sysroot/amd64
directory were used.
This needs to work without having to modify projects containing component.cpp
files.
Essentially I would like to check in platform specific headers and binaries in the source repository along with the code.
Solution 1:[1]
If you haven't found it yet, you need to write C++ toolchains. The Configure C++ Toolchains Tutorial is a good place to start, if you have more specific questions they'll get better answers as separate questions. I'm going to answer specifically about the paths here.
Most of the paths are just normal paths relative to the execution root. That typically means external/<repo_name>/<package>/<name>
for paths in external repositories, or just <package>/<name>
for paths in the main repository. bazel-toolchain's pkg_path_from_label function implements this logic, for example. In your case, that's sysroots/armhf/include
for the first path.
cxx_builtin_include_directories is special. Paths there have unique syntaxes to generate absolute paths. The relevant one looks like "%package(@your_toolchain//relative/clang/include)%"
, with @your_toolchain
replaced with your repository's name. In your case that means something like "%package(@//sysroots/armhf)%/include/myheader.h"
. Depending on where the package boundary is (deepest folder with a BUILD file) more or less of that might need to be in the %package()
part.
Those directives get expanded when generating compiler command lines. I'm not aware of any documentation besides the source.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Brian Silverman |