bazelbuild / stardoc

Stardoc: Starlark Documentation Generator
Apache License 2.0
108 stars 45 forks source link

[Bazel CI] Error: no native function or rule 'py_test' #255

Closed sgowroji closed 1 day ago

sgowroji commented 1 month ago

CI: https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/4198#01928934-6200-4035-af00-d045db026e38

Platform: Windows

Logs:

 ERROR: Traceback (most recent call last):
    File "C:/b/4pbbpba4/external/protobuf+/java/core/BUILD.bazel", line 221, column 15, in <toplevel>
        staleness_test(
    File "C:/b/4pbbpba4/external/protobuf+/upb/cmake/build_defs.bzl", line 49, column 11, in staleness_test
        native.py_test(
Error: no native function or rule 'py_test'
Available attributes: action_listener, alias, available_xcodes, cc_binary, cc_import, cc_libc_top_alias, cc_library, cc_proto_library, cc_shared_library, cc_static_library, cc_test, cc_toolchain, cc_toolchain_alias, cc_toolchain_suite, config_feature_flag, config_setting, constraint_setting, constraint_value, environment, existing_rule, existing_rules, exports_files, extra_action, fdo_prefetch_hints, fdo_profile, filegroup, genquery, genrule, glob, java_binary, java_import, java_library, java_lite_proto_library, java_package_configuration, java_plugin, java_plugins_flag_alias, java_proto_library, java_runtime, java_test, java_toolchain, label_flag, label_setting, legacy_globals, memprof_profile, module_name, module_version, objc_import, objc_library, package, package_group, package_name, package_relative_label, platform, propeller_optimize, proto_lang_toolchain, proto_library, repo_name, repository_name, starlark_doc_extract, subpackages, test_suite, toolchain, toolchain_type, xcode_config, xcode_config_alias, xcode_version
(04:10:35) ERROR: C:/b/4pbbpba4/external/protobuf+/java/core/BUILD.bazel: no such target '@@protobuf+//java/core:toolchain': target 'toolchain' not declared in package 'java/core' defined by C:/b/4pbbpba4/external/protobuf+/java/core/BUILD.bazel
(04:10:35) ERROR: C:/b/4pbbpba4/external/protobuf+/BUILD.bazel:359:6: no such target '@@protobuf+//java/core:toolchain': target 'toolchain' not declared in package 'java/core' defined by C:/b/4pbbpba4/external/protobuf+/java/core/BUILD.bazel and referenced by '@@protobuf+//:java_toolchain'
(04:10:36) ERROR: Analysis of target '//stardoc/proto:stardoc_output_java_proto' failed; build aborted: Analysis failed

Culprit:

Steps:

 git clone https://github.com/bazelbuild/stardoc
git reset 2ac0981b7c35ff46cf66cc92467c37411c7bfacc  --hard
export USE_BAZEL_VERSION=00fdb673ba8276e83f1c821a7f93aab7038377e2 

CC Greenteam @meteorcloudy

brentleyjones commented 1 month ago

https://github.com/protocolbuffers/protobuf/commit/b00dca3665b872f280702283be831bad6607d86c

tetromino commented 1 month ago

This failure is caused by Bazel 8 prereleases pulling in protobuf-27.x or 29.x (and overriding the perfectly good protobuf 21.x that stardoc requests). The newer versions of protobuf are incompatible with Bazel 8 because they try to use native.py_* symbols.

Unfortunately, the fix needs to come from Bazel. Specifically:

And until above is done, Stardoc users are broken on Bazel 8 :/

@Wyverald @comius - correct me if I am wrong on any of these points.

tetromino commented 1 month ago

@comius - note that Bazel's https://github.com/bazelbuild/bazel/blob/master/third_party/protobuf/add_python_loads.patch fixes the protobuf module used by Bazel to build itself, but doesn't fix the protobuf module loaded by external users of Bazel who depend on \@bazel_tools.

For stardoc and anyone who depends on stardoc transitively, the Bazel 8-compatible version of protobuf needs to be in BCR.

tetromino commented 1 day ago

Fixed by #263