How to fetch external dependencies in bazel

2.1k Views Asked by At

I want bazel to fetch an external dependency from a URL. The file is an rpm file. I added this in the WORKSPACE file in root dir:

http_archive(
    name = "mylib",
    url = "someURL/somefile.rpm",
    build_file = "example.BUILD"
)

When I try:

bazel fetch @mylib//...

It says:

"com.google.devtools.build.lib.syntax.EvalException: Expected a file with a .zip, .jar, .war, .tar, .tar.gz, .tgz, .tar.xz, .txz, or .tar.bz2 suffix"

Basically it is not allowing to download rpm deps. How can I achieve this ? How to download external dependency of type rpm.

2

There are 2 best solutions below

2
vincent On

You're trying to fetch an .rpm file, but it seems that bazel only accepts archive files with the suffixes .zip, .jar, .war, .tar, .tar.gz, .tgz, .tar.xz, .txz, or .tar.bz2.

0
Valentin Gazzola On

You certainly figured it out by now. Like @sebastian-nowak commented, you can do something like:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")

http_file(
    name = "mylib",
    url = "someURL/somefile.rpm"
)

and in your example.BUILD, reference it with @mylib//file

(Source: https://docs.bazel.build/versions/master/repo/http.html#http_file)