zqy
zqy

Reputation: 131

How can I expand a relative path to full path for cxx_builtin_include_directories in cc_common.create_cc_toolchain_config_info in bazel?

When declaring a cc_common.create_cc_toolchain_config_info and provide cxx_builtin_include_directories, I found the need to fully specify a include path. I only know the relative path of the directory in the crosstool.bzl file in def _impl(ctx), how can I expand that fully? For example

def _impl(ctx):
    cxx_builtin_include_directories = ["relative/clang/include"]
    return cc_common.create_cc_toolchain_config_info(
        ctx = ctx,
        features = features,
        tool_paths = tool_paths,
        cxx_builtin_include_directories = cxx_builtin_include_directories,
        # ...
    )

cc_toolchain_config = rule(
    implementation = _impl,
    attrs = {},
    provides = [CcToolchainConfigInfo],
)

How can I expand "relative/clang/include" to a real path?

Upvotes: 1

Views: 595

Answers (1)

Brian Silverman
Brian Silverman

Reputation: 3858

There's a special syntax for doing this. It looks like "%package(@your_toolchain//relative/clang/include)%", with @your_toolchain replaced with your repository's name

Those directives get expanded when generating compiler command lines. I'm not aware of any documentation besides the source.

Upvotes: 1

Related Questions