Search code examples
c++makefilebazel

output 'external/name/x/lib/lib.so' was not created using bazel make


I was trying to follow the example provided by Building Makefile using bazel post to build an external package in envoy. In the WORKSPACE file I added the following:

new_git_repository(
    name = "name",
    remote = "remote.git",
    build_file = "//foo/bazel/external:x.BUILD",
)

And foo/bazel/external/x.BUILD has the following contents:

load("@rules_foreign_cc//tools/build_defs:make.bzl", "make")

filegroup(
  name = "m_srcs",
  srcs = glob(["code/**"]),
)

make(
  name = "foo_bar",
  make_commands = ["make lib"],
  lib_source = ":m_srcs",
  shared_libraries = ["lib.so"],
)

and I set the visibility in foo/bazel/BUILD as package(default_visibility = ["//visibility:public"])

On executing bazel build -s @name//:foo_bar, I get the error that external/name/x/lib/lib.so was not created.

I checked the bazel-bin/external/name/x/logs/GNUMake.log and make completes successfully. I see that BUILD_TMPDIR directory has created lib.so. I think it should have been copied to EXT_BUILD_DEPS/lib, but I am not sure why it was not copied. Would appreciate any tips to debug the error.


Solution

  • Edited make command to manually copy the lib to expected folder - make_commands = ["make libs; cp lib.so $INSTALLDIR/lib/lib.so"]