makefilebazelbazel-cpp

Buildfile not found in gnumake_src for rules_foreign_cc


I am using Bazel to build MakeFiles with the rules_foreignCC Library. When loading, it required me to download "https://mirror.bazel.build/ftpmirror.gnu.org/gnu/make/make-4.4.tar.gz" and "http://ftpmirror.gnu.org/gnu/make/make-4.4.tar.gz" but it's on a different location ( company network) so I used a http_archive. However, now I am getting

Error: Build file not found in the directory '' in external repository @@gnumake_src. Add a BUILD file to a directory to mark it as a package. and referenced by '@@rules_foreign_cc//toolchains:make_tool' .```
  Does anyone know how to fix this issue?

Solution

  • Put your target definition in the build_file_content of the http_archive.

    e.g. in your MODULE.bazel (or WORKSPACE), put the http_archive like this:

    # Stolen from https://github.com/bazelbuild/rules_foreign_cc/blob/d9367d28ad5292dd2ed42ae85223e79e845d0f3f/toolchains/built_toolchains.bzl#L10
    _RULES_FOREIGN_CC_ALL_CONTENT = """\
    filegroup(
        name = "all_srcs",
        srcs = glob(["**"]),
        visibility = ["//visibility:public"],
    )
    """
    
    http_archive(
        name = "gnumake_src",
        ...
        build_file_content = _RULES_FOREIGN_CC_ALL_CONTENT,
    )   
    

    Make sure that this is before the command to fetch rules_foreign_ccs dependencies in your MODULE.bazel (or WORKSPACE).