rules_cc icon indicating copy to clipboard operation
rules_cc copied to clipboard

Rule based toolchains should expand `args` with `data`

Open keith opened this issue 10 months ago • 2 comments

I wrote a args rule like this:

cc_args(
    name = "asan_compile_args",
    actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
    args = [
        "-fno-sanitize-recover=all",
        "-fsanitize=address",
        "-fsanitize-ignorelist=$(location //bazel/internal:asan-suppressions.txt)",
    ],
    data = [
        "//bazel/internal:asan-suppressions.txt",
    ],
)

Which I think we should be able to support

keith avatar Feb 25 '25 00:02 keith

The cc_args.format attribute can do this today, and can handle expansion of directory rules from bazel_skylib as well as files and cc_variables. I don't think there's a significant reason to not support this though.

armandomontanez avatar Apr 01 '25 17:04 armandomontanez

Putting a file in cc_args.format doesn't work because the format argument is missing allow_files = True. As a workaround, the file can be wrapped in a filegroup:

filegroup(
    name = "example",
    srcs = ["example.txt"],
)

cc_args(
    name = "default_flags",
    actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
    args = [
        "--example={example}",
    ],
    format = {"example": ":example"},
    data = [":example"],
)

jscissr avatar May 06 '25 09:05 jscissr