#include problems with new_local_repository

774 views
Skip to first unread message

Onath Claridge

unread,
Jun 24, 2015, 5:43:53 PM6/24/15
to bazel-...@googlegroups.com
Hi Bazelites,

I'm trying out new_local_repository, and cc_binary isn't play nicely with it. I've set up a "local repository" at /tmp/mylib, which consists of the files getx.h and getx.cc. In WORKSPACE of my project, I add
    new_local_repository(
        name = "mylib",
        path = "/tmp/mylib",
        build_file = "mylib.BUILD",
    )

In mylib.BUILD, I have
    cc_library(
        name = "getx",
        hdrs = ["getx.h"],
        srcs = ["getx.cc"],
        visibility = ["//visibility:public"],
    )

Then in my main project, I have system/hello.cc (the "system" package just being a convenient one to stick it in), which #include-s getx.h. Its compilation rule is
    cc_binary(
        name = "hello",
        srcs = ["hello.cc"],
        deps = ["@mylib//:getx"],
        copts = ["-I/tmp/mylib"],
    )

Then when I "bazel build system:hello", Bazel complains:
    in cc_binary rule //system:hello: The include path '/tmp/mylib' references a path outside of the execution root..

As an alternative, I split the -I flag into two components:
    copts = ["-I", "/tmp/mylib"]
In this case, Bazel complains:
    undeclared inclusion(s) in rule '//system:hello'
But unlike the previous case, if I build with -s, it spits out a command line, which runs successfully if I invoke it manually.

Am I missing something, or is cc_binary being overly cautious?

Thanks,
Onath

Austin Schuh

unread,
Jun 25, 2015, 2:05:00 AM6/25/15
to Onath Claridge, bazel-...@googlegroups.com
(Untested)
Try putting includes=['.'] in the library rule in the local repository BUILD file to include the path.

Austin

--
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/09165f70-5fc3-4e54-bd42-43836bcf48ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Onath Claridge

unread,
Jun 25, 2015, 12:36:48 PM6/25/15
to Austin Schuh, bazel-...@googlegroups.com
That did the trick, thanks!
Reply all
Reply to author
Forward
0 new messages