How to set a copt that points to a file? Or, how to get a non-CC source into the sandbox during cc compilation

203 views
Skip to first unread message

Gary Miguel

unread,
Jun 23, 2023, 6:48:31 PM6/23/23
to bazel-discuss
I have a cc_library.
I want to set "-fsanitize-ignorelist" to point to a file in my repo.
E.g., I have:
foo.cc
BUILD.bazel
ignorelist.txt

and in BUILD.bazel:
cc_library(
  name = "foo",
  copts = ["-fsanitize-ignorelist=" <TODO what goes here?>],
  srcs = ["foo.cpp"],
)

I've tried setting ignorelist.txt as a data dependency, and then referring to it with
$(location), but that doesn't work. I get:
clang: error: no such file or directory: 'bazel-out/k8-fastbuild/ignorelist.txt'

Filip Filmar

unread,
Jun 23, 2023, 7:00:10 PM6/23/23
to Gary Miguel, bazel-discuss
I recently used a dirty trick to achieve something similar. In case you want to be on your way quickly.

I suspect the issue is that a `data` dependency is not available in the sandbox used for compilation. You can verify if you run your compilation with local sandbox strategy - if it passes, then that's probably it.

What I did was to rename the file such that its name ends with ".h". It can then be used in the `hdrs`, and $location will work, and it will be available during compilation.

F


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/f16741dd-b304-4beb-acf1-c8b378f82282n%40googlegroups.com.

Filip Filmar

unread,
Jun 23, 2023, 7:01:59 PM6/23/23
to Gary Miguel, bazel-discuss
On Fri, Jun 23, 2023 at 3:59 PM Filip Filmar <fil...@gmail.com> wrote:
I suspect the issue is that a `data` dependency is not available in the sandbox used for compilation.


"Files needed by this rule at runtime. "  --- so indeed, `data` is not available in the sandbox at compile time.

F

Gary Miguel

unread,
Jun 23, 2023, 9:11:18 PM6/23/23
to bazel-discuss
Thanks that works!

Filip Filmar

unread,
Jul 5, 2023, 5:55:00 PM7/5/23
to Gary Miguel, bazel-discuss

fil...@gmail.com

unread,
Oct 21, 2024, 4:20:53 PMOct 21
to bazel-discuss
Hi, it's me from the future.  Please use the new bazel feature from the previous message.

It turned out that my dirty trick has a fatal flaw.  Don't ask how I know. :/

The c++ build rules have additional smarts, and will prune the included file from the set of deps needed to rebuild the target. The end result is, you will get your artifact built initially, but if the artifact changes, the targets depending on them will not be rebuilt. Which is not a good thing to have in bazel. I was also told that the approach might work with `textual_hdrs`, but I haven't tried.
Reply all
Reply to author
Forward
0 new messages