Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install a project built with bazel?

Tags:

bazel

I am working on a project that is transitioning from CMake to Bazel. One critical feature that we are apparently losing in the bargain is the ability to install the project, so that it can be used by other (not necessarily Bazel) projects.

AFAICT, there is currently no built in support for installing a project?!

I need to create a portable (must work on at least Linux and MacOS) way to install the project. Specifically:

  • I need to be able to specify libraries, headers, executables, and other files (e.g. LICENSE) that need to be installed.
  • The user needs to be able to specify an absolute prefix where things should be installed.
    • I really, really should be able to execute the "install" step more than once, giving different prefixes each time, without Bazel getting confused (i.e. it must not try to "remember" what files it already installed, or if it does, must understand when the prefix is different from last time).
  • Libraries should be installed to the right place (e.g. lib64), or at least it should be possible for the user to specify the correct libdir.
  • The install step MUST NOT touch the time stamp on any file from a previous install that has not changed. (Ideally, Bazel itself would handle this; using the install command is tricky and has potential portability issues. Note platform requirements, above.)

What is the best way to go about doing this?

like image 898
Matthew Avatar asked Apr 21 '17 18:04

Matthew


1 Answers

Unless you want to do specific package (e.g. deb or rpm), you probably want to create an executable rule that does the install for you.

You can create a rule that would create an executable (e.g. a shell script) that does the install for you (e.g. do checksums to check if there are change to the installed file and does the actual copy of the files if they have changed). You would have to use the extension language to do, that would look similar to what the docker rules does to load an image with the incremental loader

Addition: I forgot to say that the install itself would be run by using the run command: bazel run install if the rule is named install in the top level BUILD file.

like image 50
Damien Martin-Guillerez Avatar answered Oct 25 '22 23:10

Damien Martin-Guillerez