Search code examples
buildbazel

How to change Bazel build output directory location


I have small project and after building it he layout looks like this.

|-- BUILD
|-- README.md
|-- VERSION
|-- WORKSPACE
|-- bazel-bin -> /home/bkch/.cache/bazel/_bazel_bkch/172376ca1288bc6e93208fc2d53c0b74/execroot/distroless/bazel-out/k8-fastbuild/bin
|-- bazel-distroless -> /home/bkch/.cache/bazel/_bazel_bkch/172376ca1288bc6e93208fc2d53c0b74/execroot/distroless
|-- bazel-out -> /home/bkch/.cache/bazel/_bazel_bkch/172376ca1288bc6e93208fc2d53c0b74/execroot/distroless/bazel-out
|-- bazel-testlogs -> /home/bkch/.cache/bazel/_bazel_bkch/172376ca1288bc6e93208fc2d53c0b74/execroot/distroless/bazel-out/k8-fastbuild/testlogs
|-- debian_archives.bzl

bazel-bin, bazel-out, bazel-distroless, bazel-testlogs are symbolic links to .cache in user root folder. Instead of the symbolic links I would like to build them in current workspace directory.

From the documentation I tried using --output_base=$PWD/output or --output_user_root=$PWD/output . The moment I use these options the bazel build is failing of various random reasons. But when I use bazel build //... with out these options the build succeeds.

enter image description here


Solution

  • I guess the answer might lie here... github.com/bazelbuild/bazel/issues/13601 we just need to have folder outside the project folder --output_base=$PWD/../output