Building Makefile using bazel

后端 未结 1 1160
天命终不由人
天命终不由人 2021-01-06 04:05

I am trying to build Makefile of a submodule in a bazel project. I see that bazel does provide genrule to execute bash command. I am facing two issues currently -

相关标签:
1条回答
  • 2021-01-06 05:04

    Instead of rolling your own genrule to build a (presumably C++) project that uses a Makefile, check out rules_foreign_cc instead. rules_foreign_cc is used by envoy and other various large C++ programs to build external CMake and Make based dependencies.

    See the simple_make example. In it, you would first make a filegroup to collect all the sources and files related to the project to be built, including the Makefile itself:

    filegroup(
        name = "sources",
        srcs = glob(["**"]),
        visibility = ["//simple_make:__subpackages__"],
    )
    

    Then, call rules_foreign_cc's make rule, which also comes with other make-specific attributes like prefix, make_env_vars, and even a way to override the entire make command with make_commands. In this example, we're just using the lib_source and static_libraries attributes:

    load("@rules_foreign_cc//tools/build_defs:make.bzl", "make")
    
    make(
        name = "make_lib",
        lib_source = "//simple_make/code:sources",
        static_libraries = ["liba.a"],
    )
    

    Finally, run bazel build //package/to:make_lib to invoke the make rule.

    How do I update update submodule before executing genrule?

    Try not to do this especially if it updates the sources of the project in-place. genrules and other rules should not modify the state of your sources during a build, but instead only build output files. Consider running a separate script to update submodules prior to the build.

    0 讨论(0)
提交回复
热议问题