bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.15k stars 4.05k forks source link

Document how to bring non-source tree absolute paths into your workspace. #8846

Open sertel opened 5 years ago

sertel commented 5 years ago

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

I'm trying to configure a simple C++ project with the following BUILD:

cc_binary(
    name = "my-llvm-project",
    srcs = glob(["*.cc"]),
    copts = ["-I/usr/inlcude/llvm-6.0/include"],
)

The error is:

The include path '/usr/inlcude/llvm-6.0/include' references a path outside of the execution root.

I also tried to use includes instead:

cc_binary(
    name = "my-llvm-project",
    srcs = glob(["*.cc"]),
    includes = ["/usr/inlcude/llvm-6.0/include"],
)

Bazel says:

in includes attribute of cc_binary rule //main:my-llvm-project: ignoring invalid absolute path '/usr/inlcude/llvm-6.0/include'

Even if I declare llvm as a library:

cc_library(
    name = "llvm-dep",
    hdrs = glob(["/usr/include/llvm-6.0/include/*.h",
    "/usr/include/llvm-6.0/include/**/*.h"]),
)

cc_binary(
    name = "my-llvm-project",
    srcs = glob(["*.cc"]),
    deps = ["llvm-dep"]
)

I get the following error message:

pattern cannot be absolute

If there is a preferred way of doing this in bazel then it should be in the docs.

What operating system are you running Bazel on?

Ubuntu LTS 18.04 (bionic) on the following kernel: Linux 4.4.0-17763-Microsoft (WSL)

What's the output of bazel info release?

release 0.27.1

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

I used the binary installer as described here: https://docs.bazel.build/versions/master/install-ubuntu.html#install-with-installer-ubuntu

Have you found anything relevant by searching the web?

This issue might be related: https://github.com/bazelbuild/bazel/issues/3239

sertel commented 5 years ago

I finally found this post: https://groups.google.com/forum/#!searchin/bazel-discuss/cc_library$20includes%7Csort:date/bazel-discuss/lsbxZxNjJQw/NKb7f_eJBwAJ It suggests to set up a local repository:

WORKSPACE:

new_local_repository(
    name = "llvm",
    path = "/usr/lib/llvm-6.0/include",
    build_file_content = """
package(default_visibility = ["//visibility:public"])
cc_library(
    name = "headers",
    hdrs = glob(["**/*.h"])
)
"""
)

BUILD:

package(default_visibility = ["//visibility:public"])

cc_binary(
    name = "my-llvm-project",
    srcs = glob(["*.cc"]),
    copts = ["-Iexternal/llvm"],
    deps = ["@llvm//:headers"]
)

I leave the issue open nevertheless because it would really be great to find this trivial use case on the documentation website. It would have been a great help for me.

aiuto commented 5 years ago

I changed the title to highlight that this is really a knowledge transfer problem. PTAL.

brianjenkins94 commented 4 years ago

Is creating a repository the generally accepted solution? Feels like there's still a documentation gap -- if not a knowledge gap here.

github-actions[bot] commented 8 months ago

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

hzeller commented 7 months ago

Is there a documentation in the meantime ? It would be good if bazel would emit an actionable error message, i.e. have a link to an explanation and how to fix or work-around.

The more people start using systems that expose includes in content-hash-derived paths (such as NixOS), being able to direct bazel to accept system headers in in paths outside its sandboxed comfort-zone is important.