Skip to content

Failed to using select() in WORKSPACE #11655

@c0mm4nd

Description

@c0mm4nd

Description of the problem / feature request:

I wanna use select to download current platform's binary.

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

http_archive(
    name = "github_wasmtime",
    url = select({
        "@io_bazel_rules_go//go/platform:darwin": "https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasmtime-dev-x86_64-macos-c-api.tar.xz",
        "@io_bazel_rules_go//go/platform:linux_amd64": "https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasmtime-dev-x86_64-linux-c-api.tar.xz",
        "@io_bazel_rules_go//go/platform:windows_amd64": "https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasmtime-dev-x86_64-mingw-c-api.zip",
    }),
    build_file = "@//:wasmtime.BUILD"
)

But failed

[ubuntu@ubuntu-inspiron5547 wasmtime-go]$ bazel build //...
INFO: Repository github_wasmtime instantiated at:
  no stack (--record_rule_instantiation_callstack not enabled)
Repository rule http_archive defined at:
  /home/ubuntu/.cache/bazel/_bazel_ubuntu/5fc43581db7e6df5f96aad547794ed35/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
ERROR: An error occurred during the fetch of repository 'github_wasmtime':
   got value of type 'select' for attribute 'url' of http_archive rule 'github_wasmtime'; select may not be used in repository rules
ERROR: /home/ubuntu/wasmtime-go/BUILD.bazel:31:11: //:go_default_library depends on @github_wasmtime//:wasmtime in repository @github_wasmtime which failed to fetch. no such package '@github_wasmtime//': got value of type 'select' for attribute 'url' of http_archive rule 'github_wasmtime'; select may not be used in repository rules
ERROR: Analysis of target '//:go_default_library' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.078s
INFO: 0 processes.

I have tried "@platforms//os:linux" and get failed again.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

http_archive's url and urls rejects the select(), though from the print I can see it get the correct url.

What operating system are you running Bazel on?

DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=20.0.3
DISTRIB_CODENAME=Lysia
DISTRIB_DESCRIPTION="Manjaro Linux"
bazel version
Build label: 3.2.0- (@non-git)
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu May 28 16:25:37 2020 (1590683137)
Build timestamp: 1590683137
Build timestamp as int: 1590683137

What's the output of bazel info release?

bazel info release
release 3.2.0- (@non-git)

If bazel info release returns "development version" or "(@Non-Git)", tell us how you built Bazel.

$ yay -Ss bazel
community/bazel 3.2.0-1 (66.4 MiB 103.1 MiB) (Installed)
    Correct, reproducible, and fast builds for everyone

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

Why ask this?

git remote get-url origin ; git rev-parse master ; git rev-parse HEADhttps://github.com/bytecodealliance/wasmtime-go
master
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
1b3b5415795b2eb83ee2ef0158ba6584894b6298

master has been renamed to main

Have you found anything relevant by searching the web?

Nothing useful so I have to ask here.

The only related is that cannot use select within bind, but I think it is not a same situation

Any other information, logs, or outputs that you want to share?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    team-ExternalDepsExternal dependency handling, remote repositiories, WORKSPACE file.untriaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions