Creating a binary target from a downloaded binary?

808 views
Skip to first unread message

Kamal Marhubi

unread,
Nov 30, 2015, 2:57:27 PM11/30/15
to bazel-discuss
Is there a way to make a binary target out of a binary blob? Here are the options I've come up with:
- use a genrule(executable = 1, cmd = "cp $< $@") to rename it and make it an executable according to Bazel
- use a genrule to rename it to .sh, and use that as srcs for an sh_binary rule

The file is coming from a .tgz that contains just a single executable, so http_file(executble = 1) isn't quite applicable as it needs extraction. This results in me making it a new_http_archive and using one of the tricks above.

I'm sure there's a better way to do this, but I think I'm missing it.

Thanks,

-Kamal

Kristina Chodorow

unread,
Nov 30, 2015, 3:11:17 PM11/30/15
to Kamal Marhubi, bazel-discuss
I think either of those sound fine, the first one sounds a little more straightforward.  

There isn't a built-in way to chmod an input.  I guess if you needed to do it a lot you could make a skylark macro for it.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAK-ZPenHPE-DofDUaz-deC68sONw4qquNmG%3DNOF4e5tLqLvY%2BQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Brian Silverman

unread,
Nov 30, 2015, 3:14:57 PM11/30/15
to Kristina Chodorow, Kamal Marhubi, bazel-discuss
Does the file actually need to be chmod'ed? If it's from a .tgz, it probably already has the correct permissions. In that case, a filegroup or exports_files would be simpler.

AFAIK Bazel doesn't keep track of whether files are executable or not; those executable attributes for genrule and http_file basically just force a chmod.

Also, the skylark macro is going to be hard until #429 is fixed.

Kamal Marhubi

unread,
Nov 30, 2015, 11:08:48 PM11/30/15
to Brian Silverman, Kristina Chodorow, bazel-discuss
On Mon, Nov 30, 2015 at 3:15 PM Brian Silverman <bsilve...@gmail.com> wrote:
Does the file actually need to be chmod'ed? If it's from a .tgz, it probably already has the correct permissions. In that case, a filegroup or exports_files would be simpler.

AFAIK Bazel doesn't keep track of whether files are executable or not; those executable attributes for genrule and http_file basically just force a chmod.

It's got executable permission, but bazel run won't work, complaining that it's not executable. This seems to get checked by the run command:

https://github.com/bazelbuild/bazel/blob/9e091ddef4dbbd97a2bff75948c474fe4127e541/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java#L497-L500

Anyway, for my current use case of coyping it into a docker_build, exports_files will work fine so thanks for the tip! I haven't checked if I'd be able to execute it in a genrule or in a Skylark rule.

-Kamal
Reply all
Reply to author
Forward
0 new messages