Setting up Abseil as an external dependency in bazel

2,093 views
Skip to first unread message

Edvard Fagerholm

unread,
Feb 13, 2018, 2:43:01 AM2/13/18
to Abseil.io
Hi,

I'm trying to figure out how to use abseil with bazel as an external dependency without having to download it onto my machine (since this requires giving an absolute path to the source, which is ugly...). To test this out, I basically checked out the git repo, made a tarball out of it and uploaded it onto a server. After doing this, I added the following into my blaze WORKSPACE file:

http_archive(
    name = "com_google_absl",
    sha256 = "a085fb163b5996fdbe9145d79f1a57908ae3341a57052679956073655d050a18",
    urls = ["http://hans.math.upenn.edu/~edvardf/abseil-cpp.tar.gz"]
)

I added a BUILD dep for a test binary:

cc_binary(
    name = "server_main",
    srcs = [ "main.cc" ],
    deps = [
    "@com_google_absl//absl/strings",
    ],
)

Doing "bazel build :server_main", I see the following error:

ERROR: /Users/efagerho/git/tfserver/server/BUILD:19:1: no such package '@com_google_absl//absl/strings': BUILD file not found on package path and referenced by '//server:server_main'
ERROR: Analysis of target '//server:server_main' failed; build aborted: no such package '@com_google_absl//absl/strings': BUILD file not found on package path
INFO: Elapsed time: 0.133s
FAILED: Build did NOT complete successfully (0 packages loaded)

If I untar abseil-cpp.tar.gz, I see that there's not file named "BUILD" in the folder, but there is a file named "BUILD.bazel". Not sure if this is the problem or if there's something else going on? It would also help if the project created official snapshots of the library as tarballs and put them on github, so this would work out-of-the-box.

Best,
Edvard

Derek Mauro

unread,
Feb 13, 2018, 9:16:15 AM2/13/18
to Edvard Fagerholm, Abseil.io
Hi Edvard,

I believe the problem you are having is related to the structure of your tarball.  The root of your tarball consists of one directory, "abseil-cpp".  Bazel doesn't expect that, it expects the root of your tarball to be the root of the project.  Simply adding a strip_prefix to your http_archive rule should fix that.  Something like this:

http_archive(
    name = "com_google_absl",
    sha256 = "yoursha256",
    strip_prefix = "abseil-cpp",
)

--

By cloning the git repo and then making a tarball you are making your life hard for yourself.  Github already serves zip files for commits. This works out of the box:

http_archive(
    name = "com_google_absl",
    sha256 = "26d3f00c2749899529e5741bf6c07f59a87a96999ffcf72590bc221e565b6720",
    strip_prefix = "abseil-cpp-4791df7d1ac966e6c7abdeffafa5030d718500df",
)

--

However, I find this method annoying since I have to download the archive anyway to compute the sha256. The method I prefer (which Bazel doesn't recommend: https://docs.bazel.build/versions/master/be/workspace.html#git_repository) is to use a git_repository rule:

load('@bazel_tools//tools/build_defs/repo:git.bzl', 'git_repository')
git_repository(
    name = "com_google_absl",
    commit = "4791df7d1ac966e6c7abdeffafa5030d718500df",
)

--

Hope this helps,
Derek


--
You received this message because you are subscribed to the Google Groups "Abseil.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to abseil-io+unsubscribe@googlegroups.com.
To post to this group, send email to abse...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/abseil-io/12ed5224-5129-48b2-b46d-878fb4d60ccb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Edvard Fagerholm

unread,
Feb 13, 2018, 9:40:32 AM2/13/18
to Derek Mauro, Abseil.io
Hi Derek,

Hadn't notice that you cat get the zip files directly out of github, since it's a pretty rare use case (for me at least). I wanted to avoid the git_repository approach precisely because of the lack of a sha256 hash. Anyway, it works now. Thanks.

ps. Something that annoys me as a Xoogler are the Status objects in Google's external code. Is there any effort to get util::Status into Abseil and to consolidate the Status object in gRPC and TensorFlow into one thing? My understanding is that these are separate precisely because Abseil didnd't exist when these were released to the public.

Best,
Edvard

Derek Mauro

unread,
Feb 13, 2018, 9:53:27 AM2/13/18
to Edvard Fagerholm, Abseil.io
On Tue, Feb 13, 2018 at 9:40 AM, Edvard Fagerholm <edvard.f...@gmail.com> wrote:
ps. Something that annoys me as a Xoogler are the Status objects in Google's external code. Is there any effort to get util::Status into Abseil and to consolidate the Status object in gRPC and TensorFlow into one thing? My understanding is that these are separate precisely because Abseil didnd't exist when these were released to the public.

It's on our roadmap, but because of the disparate features in the forks, the unforking is complicated and is going to take a while.
Reply all
Reply to author
Forward
0 new messages