Search code examples
bazel

Does Bazel need external-repo BUILD files to be in $WORKSPACE_ROOT/external?


I made a repository for glfw with this:

load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")

new_git_repository(
  name = "glfw",
  build_file = "BUILD.glfw",
  remote = "https://github.com/glfw/glfw.git",
  tag = "3.2.1",
)

I put BUILD.glfw in the WORKSPACE root. When I built, I saw:

no such package '@glfw//': Not a regular file: [snipped/external/BUILD.glfw

I moved BUILD.glfw to external/BUILD.glfw and it seems to work, but I couldn't find documentation about this. The docs about new_git_repository say that build_file "...is a label relative to the main workspace."; I don't see anything about 'external' there.


Solution

  • This is due to an inconsistent semantical difference between the native and (newer) Skylark versions of new_git_repository. To use the native new_git_repository, comment/remove the load statement:

    # load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")