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

Unable to load file '@bazel_version//:def.bzl': file doesn't exist #268

Closed
jonhoo opened this issue Nov 11, 2019 · 4 comments
Closed

Unable to load file '@bazel_version//:def.bzl': file doesn't exist #268

jonhoo opened this issue Nov 11, 2019 · 4 comments

Comments

@jonhoo
Copy link

jonhoo commented Nov 11, 2019

With this WORKSPACE:

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

http_archive(
    name = "io_bazel_rules_rust",
    sha256 = "9f38c5fbf37b0dc445fe54558e14ac000cca0be6907251c6df21ba236acd59a8",
    strip_prefix = "rules_rust-ec436b5ff2ab1ddeba6f27a7a1a5d263812981a6",
    urls = [
        # Master branch as of 2019-11-11
        "https://github.com/bazelbuild/rules_rust/archive/ec436b5ff2ab1ddeba6f27a7a1a5d263812981a6.zip",
    ],
)

http_archive(
    name = "bazel_skylib",
    sha256 = "9a737999532daca978a158f94e77e9af6a6a169709c0cee274f0a4c3359519bd",
    strip_prefix = "bazel-skylib-1.0.0",
    url = "https://github.com/bazelbuild/bazel-skylib/archive/1.0.0.tar.gz",
)

load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")
rust_repositories()

load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
bazel_version(name = "bazel_version")

And bazel version 1.1.0, bazel fetch fails with

ERROR: error loading package 'rust': in /home/jon/.cache/bazel/_bazel_jon/66db7c3492b5fc3fa5db2c66360c215b/external/io_bazel_rules_rust/bindgen/bindgen.bzl: in /home/jon/.cache/bazel/_bazel_jon/66db7c3492b5fc3fa5db2c66360c215b/external/io_bazel_rules_rust/rust/rust.bzl: in /home/jon/.cache/bazel/_bazel_jon/66db7c3492b5fc3fa5db2c66360c215b/external/io_bazel_rules_rust/rust/private/rustdoc_test.bzl: in /home/jon/.cache/bazel/_bazel_jon/66db7c3492b5fc3fa5db2c66360c215b/external/io_bazel_rules_rust/rust/private/rustc.bzl: Unable to load file '@bazel_version//:def.bzl': file doesn't exist

The crux of this appears to be

Unable to load file '@bazel_version//:def.bzl': file doesn't exist
@jonhoo
Copy link
Author

jonhoo commented Nov 11, 2019

Which I believe stems from:

load("@bazel_version//:def.bzl", "BAZEL_VERSION")

@m3rcuriel
Copy link
Contributor

Can you paste more of your failed output here? I'm struggling to reproduce this.

@jonhoo
Copy link
Author

jonhoo commented Nov 21, 2019

Huh, strange, I cannot reproduce it anymore myself either. May have been a transient issue. I'll post more details if I run into it again!

@jonhoo jonhoo closed this as completed Nov 21, 2019
@wchargin
Copy link
Contributor

I’m running into this due to a naming conflict. μpb, a dependency of the
official protobuf/grpc repo, also defines a bazel_version repository
for the same purpose, but theirs has a different structure.

upb’s:

https://github.com/protocolbuffers/upb/blob/c1357afb2e39df671d89eaec49033b5329f36a3e/bazel/repository_defs.bzl#L9-L10

rules_rust’s:

rules_rust/workspace.bzl

Lines 24 to 25 in 9279938

repository_ctx.file("BUILD.bazel", "exports_files(['def.bzl'])")
repository_ctx.file("def.bzl", "BAZEL_VERSION='" + bazel_version + "'")

Thus, we get “file doesn’t exist” because their repository rule runs
first and rules_rust’s is ignored. Checking the directory structure
confirms that there is a bazel_version.bzl and not a def.bzl.

I have a repro that’s as minimal as I can make it (removing any line
breaks the repro), but not as minimal as I’d like. (The proto build
system is… difficult.) Here it is:

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

http_archive(
    name = "io_bazel_rules_closure",
    sha256 = "6a900831c1eb8dbfc9d6879b5820fd614d4ea1db180eb5ff8aedcb75ee747c1f",
    strip_prefix = "rules_closure-db4683a2a1836ac8e265804ca5fa31852395185b",
    urls = [
        "http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/db4683a2a1836ac8e265804ca5fa31852395185b.tar.gz",
        "https://github.com/bazelbuild/rules_closure/archive/db4683a2a1836ac8e265804ca5fa31852395185b.tar.gz",  # 2020-01-15
    ],
)

load("@io_bazel_rules_closure//closure:repositories.bzl", "rules_closure_dependencies")
rules_closure_dependencies(
    omit_bazel_skylib = True,
    omit_com_google_protobuf = True,
    omit_com_google_protobuf_js = True,
)

http_archive(
    name = "org_tensorflow",
    # NOTE: when updating this, MAKE SURE to also update the protobuf_js runtime version
    # in third_party/workspace.bzl to >= the protobuf/protoc version provided by TF.
    sha256 = "2595a5c401521f20a2734c4e5d54120996f8391f00bb62a57267d930bce95350",
    strip_prefix = "tensorflow-2.3.0",
    urls = [
        "http://mirror.tensorflow.org/github.com/tensorflow/tensorflow/archive/v2.3.0.tar.gz",  # 2020-07-23
        "https://github.com/tensorflow/tensorflow/archive/v2.3.0.tar.gz",
    ],
)

load("@org_tensorflow//tensorflow:workspace.bzl", "tf_workspace")
tf_workspace()

load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")

grpc_deps()

load("@upb//bazel:repository_defs.bzl", "bazel_version_repository")

# This next line breaks the build, but without it we can't build protos.
bazel_version_repository(name = "bazel_version")

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

http_archive(
    name = "io_bazel_rules_rust",
    sha256 = "618cba29165b7a893960de7bc48510b0fb182b21a4286e1d3dbacfef89ace906",
    strip_prefix = "rules_rust-5998baf9016eca24fafbad60e15f4125dd1c5f46",
    urls = [
        # Master branch as of 2020-09-24
        "https://github.com/bazelbuild/rules_rust/archive/5998baf9016eca24fafbad60e15f4125dd1c5f46.tar.gz",
    ],
)

load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories()

load("@io_bazel_rules_rust//:workspace.bzl", "rust_workspace")

rust_workspace()
BUILD
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust_test")

package(default_visibility = ["//visibility:private"])

licenses(["notice"])

rust_library(
    name = "mylib",
    srcs = [
        "lib.rs",
    ],
)
.bazelrc
common --experimental_repo_remote_exec
lib.rs

Empty file.

Command line session
$ grep -B1 name BUILD
rust_library(
    name = "mylib",
$ bazel build :mylib
ERROR: Skipping ':mylib': error loading package '': in /HOMEDIR/.cache/bazel/_bazel_wchargin/bf4ce76fb2a3b9593d6023d4a99e07e4/external/io_bazel_rules_rust/rust/rust.bzl: in /HOMEDIR/.cache/bazel/_bazel_wchargin/bf4ce76fb2a3b9593d6023d4a99e07e4/external/io_bazel_rules_rust/rust/private/rustdoc_test.bzl: in /HOMEDIR/.cache/bazel/_bazel_wchargin/bf4ce76fb2a3b9593d6023d4a99e07e4/external/io_bazel_rules_rust/rust/private/rustc.bzl: Unable to load file '@bazel_version//:def.bzl': file doesn't exist
WARNING: Target pattern parsing failed.
ERROR: error loading package '': in /HOMEDIR/.cache/bazel/_bazel_wchargin/bf4ce76fb2a3b9593d6023d4a99e07e4/external/io_bazel_rules_rust/rust/rust.bzl: in /HOMEDIR/.cache/bazel/_bazel_wchargin/bf4ce76fb2a3b9593d6023d4a99e07e4/external/io_bazel_rules_rust/rust/private/rustdoc_test.bzl: in /HOMEDIR/.cache/bazel/_bazel_wchargin/bf4ce76fb2a3b9593d6023d4a99e07e4/external/io_bazel_rules_rust/rust/private/rustc.bzl: Unable to load file '@bazel_version//:def.bzl': file doesn't exist
INFO: Elapsed time: 0.080s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)
$ ls /HOMEDIR/.cache/bazel/_bazel_wchargin/bf4ce76fb2a3b9593d6023d4a99e07e4/external/bazel_version
bazel_version.bzl  BUILD  WORKSPACE
$ cat /HOMEDIR/.cache/bazel/_bazel_wchargin/bf4ce76fb2a3b9593d6023d4a99e07e4/external/bazel_version/bazel_version.bzlbazel_version = "2.1.0"$ 
$ cat /HOMEDIR/.cache/bazel/_bazel_wchargin/bf4ce76fb2a3b9593d6023d4a99e07e4/external/bazel_version/bazel_version.bzl; echo
bazel_version = "2.1.0"
$ sed -i -e '/bazel_version_repository/ s/^/#/' WORKSPACE
$ bazel build :mylib
INFO: Analyzed target //:mylib (26 packages loaded, 186 targets configured).
INFO: Found 1 target...
Target //:mylib up-to-date:
  bazel-bin/libmylib--1103081910.rlib
INFO: Elapsed time: 1.100s, Critical Path: 0.67s
INFO: 5 processes: 5 linux-sandbox.
INFO: Build completed successfully, 9 total actions
$ ls /HOMEDIR/.cache/bazel/_bazel_wchargin/bf4ce76fb2a3b9593d6023d4a99e07e4/external/bazel_version
BUILD  def.bzl  WORKSPACE

Bazel version: bazel info release = release 2.1.0


It looks like upb may have gotten rid of theirs at head, so I’ll see
if we can upgrade on our end, but we’d have to get TensorFlow to
upgrade, too, so it may or may not be trivial. I wonder whether an easy
workaround on our end could be to rename our bazel_version_repository
to something that doesn’t conflict? Like:

diff --git a/docs/BUILD b/docs/BUILD
index 19bb042..cc7002f 100644
--- a/docs/BUILD
+++ b/docs/BUILD
@@ -7,7 +7,7 @@ bzl_library(
     name = "all_deps",
     srcs = [
         "@bazel_tools//tools:bzl_srcs",
-        "@bazel_version//:def.bzl",
+        "@io_bazel_rules_rust_bazel_version//:def.bzl",
     ],
     deps = [
         "@bazel_skylib//lib:versions",
diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl
index c3d5f9b..ea84b2e 100644
--- a/rust/private/rustc.bzl
+++ b/rust/private/rustc.bzl
@@ -23,7 +23,7 @@ load(
     "find_cpp_toolchain",
 )
 load("@bazel_skylib//lib:versions.bzl", "versions")
-load("@bazel_version//:def.bzl", "BAZEL_VERSION")
+load("@io_bazel_rules_rust_bazel_version//:def.bzl", "BAZEL_VERSION")
 
 CrateInfo = provider(
     fields = {
diff --git a/workspace.bzl b/workspace.bzl
index d54ac1e..fe14180 100644
--- a/workspace.bzl
+++ b/workspace.bzl
@@ -29,5 +29,5 @@ def rust_workspace():
 
     bazel_skylib_workspace()
 
-    bazel_version(name = "bazel_version")
+    bazel_version(name = "io_bazel_rules_rust_bazel_version")
 

This patch seems to solve the problem for me, so I’ll submit a PR.

wchargin added a commit to wchargin/rules_rust that referenced this issue Oct 21, 2020
We use a synthetic `bazel_version` repository to make the Bazel version
available in more contexts (see [bazelbuild/bazel#8305][i8305]). But
some other repositories do so, too, with the same repository name and a
different repository structure. In particular, it is not currently
possible to use `rules_rust` and certain versions of `upb` (downstream
of protobuf) in the same repository, due to their definition here:

https://github.com/protocolbuffers/upb/blob/c1357afb2e39df671d89eaec49033b5329f36a3e/bazel/repository_defs.bzl#L7-L10

An easy workaround is to disambiguate the name. It looks much easier to
change `rules_rust` than to change `upb` and update its long chain of
workspace dependencies, hence this patch. :-)

See my comment on bazelbuild#268 for more details and a full repro:
bazelbuild#268 (comment)

[i8305]: bazelbuild/bazel#8305

Test Plan:
Tested by adding the README’s workspace stanza to TensorBoard (at
current master, 8d629954c251). It fails at `rules_rust = 5998baf`,
but succeeds with a `local_repository` that has this patch.

wchargin-branch: disambiguate-bazel-version-repo
wchargin-source: 7d8ca1dd816cca59f4e1099257e6bd3a77475368
wchargin added a commit to wchargin/rules_rust that referenced this issue Oct 21, 2020
We use a synthetic `bazel_version` repository to make the Bazel version
available in more contexts (see [bazelbuild/bazel#8305][i8305]). But
some other repositories do so, too, with the same repository name and a
different repository structure. In particular, it is not currently
possible to use `rules_rust` and certain versions of `upb` (downstream
of protobuf) in the same repository, due to their definition here:

https://github.com/protocolbuffers/upb/blob/c1357afb2e39df671d89eaec49033b5329f36a3e/bazel/repository_defs.bzl#L7-L10

An easy workaround is to disambiguate the name. It looks much easier to
change `rules_rust` than to change `upb` and update its long chain of
workspace dependencies, hence this patch. :-)

See my comment on bazelbuild#268 for more details and a full repro:
bazelbuild#268 (comment)

[i8305]: bazelbuild/bazel#8305

Test Plan:
Tested by adding the README’s workspace stanza to TensorBoard (at
current master, 8d629954c251). It fails at `rules_rust = 5998baf`,
but succeeds with a `local_repository` that has this patch. Also, in
this repo, `git grep @bazel_version` no longer has any matches.

wchargin-branch: disambiguate-bazel-version-repo
wchargin-source: e712603c3a3ebc45364cc2dcc9eca341301b5197
dfreese pushed a commit that referenced this issue Oct 23, 2020
We use a synthetic `bazel_version` repository to make the Bazel version
available in more contexts (see [bazelbuild/bazel#8305][i8305]). But
some other repositories do so, too, with the same repository name and a
different repository structure. In particular, it is not currently
possible to use `rules_rust` and certain versions of `upb` (downstream
of protobuf) in the same repository, due to their definition here:

https://github.com/protocolbuffers/upb/blob/c1357afb2e39df671d89eaec49033b5329f36a3e/bazel/repository_defs.bzl#L7-L10

An easy workaround is to disambiguate the name. It looks much easier to
change `rules_rust` than to change `upb` and update its long chain of
workspace dependencies, hence this patch. :-)

See my comment on #268 for more details and a full repro:
#268 (comment)

[i8305]: bazelbuild/bazel#8305

Test Plan:
Tested by adding the README’s workspace stanza to TensorBoard (at
current master, 8d629954c251). It fails at `rules_rust = 5998baf`,
but succeeds with a `local_repository` that has this patch. Also, in
this repo, `git grep @bazel_version` no longer has any matches.

wchargin-branch: disambiguate-bazel-version-repo
wchargin-source: e712603c3a3ebc45364cc2dcc9eca341301b5197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants