bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.98k stars 4.03k forks source link

[Bug]: Unknown object using migration tool on rules_rust crate_universe #20453

Open Dig-Doug opened 1 year ago

Dig-Doug commented 1 year ago

What happened?

When trying to use the migration tool, I get an error:

INFO: Executing command: bazel --version
bazel 6.0.0
INFO: Detected original workspace name: examples
INFO: Found existing ./resolved_deps.py file, if it's out of date, please delete it and rerun the script.
Traceback (most recent call last):
  File "/tmp/bazel-central-registry/tools/migrate_to_bzlmod.py", line 510, in <module>
    sys.exit(main())
  File "/tmp/bazel-central-registry/tools/migrate_to_bzlmod.py", line 473, in main
    resolved_deps = load_resolved_deps(argv)
  File "/tmp/bazel-central-registry/tools/migrate_to_bzlmod.py", line 455, in load_resolved_deps
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 879, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1017, in get_code
  File "<frozen importlib._bootstrap_external>", line 947, in source_to_code
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/tmp/rules_rust/examples/crate_universe/./resolved_deps.py", line 255
    "_action_listener": <unknown object com.google.devtools.build.lib.packages.Attribute$LabelListLateBoundDefault>,
                        ^
SyntaxError: invalid syntax

Version

Development (host) and target OS/architectures:

Output of bazel --version:

bazel version
Bazelisk version: development
Build label: 6.0.0
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Dec 19 15:52:35 2022 (1671465155)
Build timestamp: 1671465155
Build timestamp as int: 1671465155

Version of relevant rules from the WORKSPACE or MODULE.bazel file:

Uses crate_universe to resolve rust dependencies.

Language(s) and/or frameworks involved:

rules_rust

How to reproduce

cd /tmp
git clone git@github.com:bazelbuild/rules_rust.git
git clone https://github.com/bazelbuild/bazel-central-registry.git
cd rules_rust/examples/crate_universe
mv WORKSPACE.bazel WORKSPACE
/tmp/bazel-central-registry/tools/migrate_to_bzlmod.py //...:all

Any other information?

grep "<unknown" -A 30 -B 10 -m 1 resolved_deps.py
               "generator": "@cargo_bazel_bootstrap//:cargo-bazel",
               "lockfile": "//cargo_aliases:cargo-bazel-lock.json",
               "manifests": [
                    "//cargo_aliases:Cargo.toml"
               ]
          },
          "repositories": [
               {
                    "rule_class": "@rules_rust//crate_universe/private:crates_repository.bzl%crates_repository",
                    "attributes": {
                         "_action_listener": <unknown object com.google.devtools.build.lib.packages.Attribute$LabelListLateBoundDefault>,
                         "_config_dependencies": [],
                         "_configure": False,
                         "_environ": [
                              "CARGO_BAZEL_GENERATOR_URL",
                              "CARGO_BAZEL_GENERATOR_SHA256",
                              "CARGO_BAZEL_REPIN",
                              "REPIN",
                              "CARGO_BAZEL_ISOLATED"
                         ],
                         "annotations": {
                              "names": [
                                   "[\"0.12.1-dev\",{\"additive_build_file\":null,\"additive_build_file_content\":null,\"build_script_data\":null,\"build_script_data_glob\":null,\"build_script_deps\":null,\"build_script_env\":null,\"build_script_proc_macro_deps\":null,\"build_script_rustc_env\":null,\"build_script_toolchains\":null,\"build_script_tools\":null,\"compile_data\":null,\"compile_data_glob\":null,\"crate_features\":null,\"data\":null,\"data_glob\":null,\"deps\":null,\"gen_build_script\":null,\"patch_args\":null,\"patch_tool\":null,\"patches\":null,\"proc_macro_deps\":null,\"rustc_env\":null,\"rustc_env_files\":null,\"rustc_flags\":null,\"shallow_since\":\"1646516410 -0700\"}]"
                              ]
                         },
                         "applicable_licenses": [],
                         "aspect_hints": [],
                         "cargo_config": None,
                         "cargo_lockfile": "//cargo_aliases:Cargo.Bazel.lock",
                         "compatible_with": [],
                         "deprecation": <unknown object com.google.devtools.build.lib.analysis.BaseRuleClasses$2>,
                         "expect_failure": "",
                         "features": [],
                         "generate_build_scripts": True,
                         "generator": "@cargo_bazel_bootstrap//:cargo-bazel",
                         "generator_function": "",
                         "generator_location": "",
                         "generator_name": "",
                         "generator_sha256s": {},
                         "generator_urls": {},
                         "isolated": True,
meteorcloudy commented 1 year ago

Oh, it looks like Bazel failed to serialize the"_action_listener" attribute of @rules_rust//crate_universe/private:crates_repository.bzl%crates_repository, it should be bug in Bazel, but to work around this, can you remove this line and retry?

Ideally, you should wait for https://github.com/bazelbuild/rules_rust/pull/1528 so that rules_rust properly supports Bzlmod.

mering commented 9 months ago

I also stumbled over this. Commenting out the following three lines as follows allowed me to proceed:

        "repositories": [{
            "rule_class": (
                "@com_grail_bazel_toolchain//toolchain:rules.bzl%llvm"
            ),
            "attributes": {
                # "_action_listener": <unknown object com.google.devtools.build.lib.packages.Attribute$LabelListLateBoundDefault>,
                "_config_dependencies": [],
                "_configure": False,
                "_environ": [],
                "_llvm_release_name": "@com_grail_bazel_toolchain//toolchain/tools:llvm_release_name.py",
                "_os_version_arch": (
                    "@com_grail_bazel_toolchain//toolchain/tools:host_os_key.py"
                ),
                "alternative_llvm_sources": [],
                "applicable_licenses": [],
                "aspect_hints": [],
                "auth_patterns": {},
                "compatible_with": [],
                # "deprecation": <unknown object com.google.devtools.build.lib.analysis.BaseRuleClasses$2>,
                "distribution": (
                    "clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz"
                ),
                "expect_failure": "",
                "features": [],
                "generator_function": "intrinsic_sdks_deps_1",
                "generator_location": None,
                "generator_name": "llvm_toolchain_llvm",
                "llvm_mirror": "",
                "llvm_version": "14.0.0",
                "name": "llvm_toolchain_llvm",
                "netrc": "",
                "restricted_to": [],
                "sha256": {},
                "strip_prefix": {},
                "tags": [],
                # "testonly": <unknown object com.google.devtools.build.lib.analysis.BaseRuleClasses$1>,
                "transitive_configs": [],
                "urls": {},
                "visibility": [],
            },
            "output_tree_hash": "962310da2230832a5a9738560a53e76a660d3a9ec97f55ce331ee0b59ce3cc7a",
        }],
meteorcloudy commented 9 months ago

Oh, this is probably an issue in Bazel, can you please file an issue to the Bazel repo?

/cc @Wyverald @SalmaSamy

meteorcloudy commented 9 months ago

Never mind, I transferred the issue to Bazel repo.

meteorcloudy commented 9 months ago

@SalmaSamy Oh sorry, I misunderstood, this is not from the lockfile, but from the generated file by --experimental_repository_resolved_file. But still, maybe it's worth fixing from Bazel side.

Wyverald commented 9 months ago

The part in question looks like a BUILD rule target instead of a repo rule, which would explain all the weirdness. The problem then is to figure out why we're trying to include this in the resolved workspace file at all...

meteorcloudy commented 9 months ago

OK, maybe a P3...