Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to using select() in WORKSPACE #11655

Closed
c0mm4nd opened this issue Jun 28, 2020 · 4 comments
Closed

Failed to using select() in WORKSPACE #11655

c0mm4nd opened this issue Jun 28, 2020 · 4 comments
Labels
team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged

Comments

@c0mm4nd
Copy link

c0mm4nd commented Jun 28, 2020

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

@aiuto aiuto added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels Jun 30, 2020
@gregestren gregestren added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Aug 13, 2020
@meteorcloudy
Copy link
Member

The recommended way to do this is defining all platform-specific deps in your WORKSPACE file

http_archive(
    name = "github_wasmtime_macos",
    url = ["<macos artifact url>"],
    build_file = "@//:wasmtime.BUILD"
)

http_archive(
    name = "github_wasmtime_windows",
    url = ["<windows artifact url>"],
    build_file = "@//:wasmtime.BUILD"
)

http_archive(
    name = "github_wasmtime_linux",
    url = ["<linux artifact url>"],
    build_file = "@//:wasmtime.BUILD"
)

Then in your BUILD file, you can use select statement to depend on the one you need.

my_binary(
    name = "bin",
    srcs = [...],
    deps = select({
        "//platform:darwin": "@github_wasmtime_macos:lib",
        "//platform:linux_amd64": "@github_wasmtime_linux:lib",
        "//platform:windows_amd64": "@github_wasmtime_windows":lib,
    }),
)

When you're running the build, non-necessary dependencies for your platform won't be downloaded.

@philwo philwo closed this as completed Dec 8, 2020
@davido
Copy link
Contributor

davido commented Dec 20, 2020

When you're running the build, non-necessary dependencies for your platform won't be downloaded.

Is this statement also accurate for bazel test command?

In gerrit, when running bazel test foo on Linux I regularly see, that JDKs artifacts for Mac OS X and Windows are fetched.

@philwo philwo reopened this Jan 5, 2021
@philwo
Copy link
Member

philwo commented Jan 5, 2021

@davido That sounds like a bug. Could you open a new issue with simple repro steps (I guess "first git clone this and then bazel test that" should be enough) so we can have a look?

@philwo philwo closed this as completed Jan 5, 2021
@davido
Copy link
Contributor

davido commented Jan 6, 2021

@davido That sounds like a bug. Could you open a new issue with simple repro steps (I guess "first git clone this and then bazel test that" should be enough) so we can have a look?

Done.

@philwo philwo removed the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged
Projects
None yet
Development

No branches or pull requests

6 participants