using binary from http_file in a toolchain

871 views
Skip to first unread message

mike.p...@bbva.com

unread,
Jun 25, 2018, 4:39:54 PM6/25/18
to bazel-discuss
Hello Folks,

I'm trying to use an http_file to download a binary that i'm using in a toolchain... When I reference the binary via `binary = '@go_swagger_darwin//file:swagger_darwin_amd64'` , bazel will return an error about visibility...

mparsons@Michael's Mac:~/go/src/github.com/bbva-market/bbva$ bazel build //iex:genstack
Loading:
Loading: 0 packages loaded
ERROR: /Users/mparsons/go/src/github.com/bbva-market/bbva/go-swagger/BUILD.bazel:6:1: target '@go_swagger_darwin//file:swagger_darwin_amd64' is not visible from target '//go-swagger:darwin_swagger_impl'. Check the visibility declaration of the former target if you think the dependency is legitimate
ERROR: While resolving toolchains for target //iex:genstack: Analysis of target '//go-swagger:darwin_swagger_impl' failed; build aborted
ERROR: Analysis of target '//iex:genstack' failed; build aborted: Analysis of target '//go-swagger:darwin_swagger_impl' failed; build aborted
INFO: Elapsed time: 0.246s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)
FAILED: Build did NOT complete successfully (1 packages loaded)

If I reference with just @go_swagger_daring//file , I'll get an error about execute permissions. This feels like it should be possible given the permission generated (visibility:public) but i'm missing something obvious. Thanks in advance!

Mike

----

I have something like this in my WORKSPACE:

http_file(
name = "go_swagger_darwin",
executable = True,
urls = ["https://github.com/go-swagger/go-swagger/releases/download/0.14.0/swagger_darwin_amd64"],
sha256 = "01dea89d72ec5f68220a751240ff42def061fec36f26bdb6d398d097be6b2576",
)

register_toolchains(
"//go-swagger:go_swagger_darwin",
)

And toolchain that depends on this file:

def _go_swagger_toolchain_impl(ctx):
toolchain = platform_common.ToolchainInfo(
binary = ctx.attr.binary,
)
return [toolchain]

go_swagger_toolchain = rule(
_go_swagger_toolchain_impl,
attrs = {
'binary': attr.label(
executable = True,
cfg = "host",
allow_single_file = True,
), ## points to the go_swagger binary
}
)


go_swagger_toolchain(
name = 'darwin_swagger_impl',
binary = '@go_swagger_darwin//file:swagger_darwin_amd64',
visibility = ["//visibility:public"],
)

toolchain(
name = 'go_swagger_darwin',
toolchain_type = ':go_swagger_toolchain',
exec_compatible_with = [
'@bazel_tools//platforms:osx',
'@bazel_tools//platforms:x86_64',
],
target_compatible_with = [
'@bazel_tools//platforms:osx',
'@bazel_tools//platforms:x86_64',
],
toolchain = ':darwin_swagger_impl',
visibility = ["//visibility:public"],
)

mike.p...@bbva.com

unread,
Jun 25, 2018, 8:30:10 PM6/25/18
to bazel-discuss

In case this helps anyone... in my custom rule (genstack) where i'm depending on this toolchain... here's the syntax you need to get to the actual files:

toolchain = ctx.toolchains['//go-swagger:go_swagger_toolchain']

to use in a ctx.actions.run pass:
executable = toolchain.binary.files_to_run.executable

In a ctx.actions.run_shell you gotta pass in

tools = [toolchain.binary.files_to_run.executable],
command = "%s" % toolchain.binary.files_to_run.executable.path

And things work great.

Thanks for the rubber duck.

Reply all
Reply to author
Forward
0 new messages