This is not an officially supported Google product.
This project aims at making it easy to install Bazel projects on local workstations.
installer
rule:
sudo
).In the WORKSPACE
file of your Bazel project add the following:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_github_google_rules_install",
urls = ["https://github.com/google/bazel_rules_install/releases/download/0.3/bazel_rules_install-0.3.tar.gz"],
sha256 = "ea2a9f94fed090859589ac851af3a1c6034c5f333804f044f8f094257c33bdb3",
strip_prefix = "bazel_rules_install-0.3",
)
load("@com_github_google_rules_install//:deps.bzl", "install_rules_dependencies")
install_rules_dependencies()
load("@com_github_google_rules_install//:setup.bzl", "install_rules_setup")
install_rules_setup()
In the BUILD
file of the package where you want to add an installer add
the following:
# In file src/path/to/pkg/BUILD:
load("@com_github_google_rules_install//installer:def.bzl", "installer")
installer(
name = "install_foo",
data = [":foo"],
)
Run the installer
using bazel run
. The following example installs foo
in
~/bin
:
bazel run //src/path/to/pkg:install_foo -- ~/bin
If you need to use sudo
to install a file in a system directory:
sudo bazel
.-s
to the installer.bazel run //src/path/to/pkg:install_foo -- -s /usr/local/bin
By default installer
uses targets built with -c opt
. To disable this
override of a command line flag use compilation_mode = ""
attribute:
installer(
name = "install_foo",
compilation_mode = "",
data = [":foo"],
)
Alternatively you can force a debug build:
installer(
name = "install_foo_dbg",
compilation_mode = "dbg",
data = [":foo"],
)