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

Missing features in third party dependency #2980

Open
air-spec opened this issue Nov 4, 2024 · 1 comment
Open

Missing features in third party dependency #2980

air-spec opened this issue Nov 4, 2024 · 1 comment

Comments

@air-spec
Copy link

air-spec commented Nov 4, 2024

I've been trying to get familiarized with bazel builds in rust by trying to build https://github.com/kube-rs/controller-rs. However, I'm running into an issue where the kube dependency does not have the right features for k8s_openapi. Not sure what I'm missing, but these are the files I added:

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_rust",
    integrity = "sha256-heIBNyerJvsiq9/+SyrAwnotW2KWFnumPY9uExQPUfk=",
    urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.53.0/rules_rust-v0.53.0.tar.gz"],
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")

rules_rust_dependencies()
rust_register_toolchains(edition = "2021")

MODULE.bazel

bazel_dep(name = "rules_rust", version = "0.53.0")

crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
crate.from_cargo(
    name = "crates",
    cargo_lockfile = "//:Cargo.lock",
    manifests = [
        "//:Cargo.toml",
    ],
)
use_repo(crate, "crates")

BUILD

load("@rules_rust//rust:defs.bzl", "rust_library", "rust_binary")
load("@crates//:defs.bzl", "aliases", "all_crate_deps")

rust_binary(
    name = "crdgen",
    srcs = ["src/crdgen.rs"],
    deps = all_crate_deps(normal = True),
)

rust_library(
    name = "lib",
    srcs = ["src/lib.rs"],
    aliases = aliases(),
    deps = all_crate_deps(normal = True),
    proc_macro_deps = all_crate_deps(proc_macro = True),
    visibility = ["//visibility:public"],
)

rust_binary(
    name = "main",
    srcs = ["src/main.rs"],
    deps = all_crate_deps(normal = True),
)

rust_library(
    name = "controller",
    srcs = ["src/controller.rs"],
    aliases = aliases(),
    deps = all_crate_deps(normal = True),
    proc_macro_deps = all_crate_deps(proc_macro = True),
    visibility = ["//visibility:public"],
)

rust_library(
    name = "fixtures",
    srcs = ["src/fixtures.rs"],
    aliases = aliases(),
    deps = all_crate_deps(normal = True),
    proc_macro_deps = all_crate_deps(proc_macro = True),
    visibility = ["//visibility:public"],
)

rust_library(
    name = "metrics",
    srcs = ["src/metrics.rs"],
    aliases = aliases(),
    deps = all_crate_deps(normal = True),
    proc_macro_deps = all_crate_deps(proc_macro = True),
    visibility = ["//visibility:public"],
)

rust_library(
    name = "telemetry",
    srcs = ["src/telemetry.rs"],
    aliases = aliases(),
    deps = all_crate_deps(normal = True),
    proc_macro_deps = all_crate_deps(proc_macro = True),
    visibility = ["//visibility:public"],
)

When I run bazel build //:main --verbose_failures --sandbox_debug I get:

error[E0433]: failed to resolve: could not find `apimachinery` in `k8s_openapi`
  --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/dynamic.rs:10:18
   |
10 | use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
   |                  ^^^^^^^^^^^^ could not find `apimachinery` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `apiextensions_apiserver` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/crd.rs:3:18
  |
3 | use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions as apiexts;
  |                  ^^^^^^^^^^^^^^^^^^^^^^^ could not find `apiextensions_apiserver` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `api` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/gvk.rs:5:19
  |
5 | use k8s_openapi::{api::core::v1::ObjectReference, apimachinery::pkg::apis::meta::v1::OwnerReference};
  |                   ^^^ could not find `api` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `apimachinery` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/gvk.rs:5:51
  |
5 | use k8s_openapi::{api::core::v1::ObjectReference, apimachinery::pkg::apis::meta::v1::OwnerReference};
  |                                                   ^^^^^^^^^^^^ could not find `apimachinery` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `apimachinery` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/metadata.rs:4:22
  |
4 | pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::{ListMeta, ObjectMeta};
  |                      ^^^^^^^^^^^^ could not find `apimachinery` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `apimachinery` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/labels.rs:3:18
  |
3 | use k8s_openapi::apimachinery::pkg::apis::meta::v1::{LabelSelector, LabelSelectorRequirement};
  |                  ^^^^^^^^^^^^ could not find `apimachinery` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `apimachinery` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/resource.rs:1:22
  |
1 | pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
  |                      ^^^^^^^^^^^^ could not find `apimachinery` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `api` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/resource.rs:3:5
  |
3 |     api::core::v1::ObjectReference,
  |     ^^^ could not find `api` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `apimachinery` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/resource.rs:4:5
  |
4 |     apimachinery::pkg::apis::meta::v1::{ManagedFieldsEntry, OwnerReference, Time},
  |     ^^^^^^^^^^^^ could not find `apimachinery` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `api` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/subresource.rs:9:22
  |
9 | pub use k8s_openapi::api::autoscaling::v1::{Scale, ScaleSpec, ScaleStatus};
  |                      ^^^ could not find `api` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `api` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/util.rs:8:18
  |
8 | use k8s_openapi::api::apps::v1::{DaemonSet, Deployment, ReplicaSet, StatefulSet};
  |                  ^^^ could not find `api` in `k8s_openapi`

error[E0433]: failed to resolve: could not find `apimachinery` in `k8s_openapi`
 --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/error_boundary.rs:5:18
  |
5 | use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
  |                  ^^^^^^^^^^^^ could not find `apimachinery` in `k8s_openapi`

error[E0432]: unresolved imports `super::apiexts::v1::CustomResourceDefinition`, `metadata::ListMeta`, `metadata::ObjectMeta`, `crate::metadata::ListMeta`, `crate::metadata::ObjectMeta`
  --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/lib.rs:32:20
   |
32 | pub use metadata::{ListMeta, ObjectMeta, PartialObjectMeta, PartialObjectMetaExt, TypeMeta};
   |                    ^^^^^^^^  ^^^^^^^^^^
   |
  ::: external/rules_rust~~crate~crates__kube-core-0.96.0/src/crd.rs:7:9
   |
7  |     use super::apiexts::v1::CustomResourceDefinition as Crd;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
  ::: external/rules_rust~~crate~crates__kube-core-0.96.0/src/object.rs:4:16
   |
4  |     metadata::{ListMeta, ObjectMeta, TypeMeta},
   |                ^^^^^^^^  ^^^^^^^^^^

error[E0599]: the method `as_ref` exists for enum `Result<K, InvalidObject>`, but its trait bounds were not satisfied
  --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/error_boundary.rs:82:16
   |
23 | pub struct InvalidObject {
   | ------------------------ doesn't satisfy `InvalidObject: Sized`
...
82 |         self.0.as_ref().map_or_else(|err| &err.metadata, K::meta)
   |                ^^^^^^ method cannot be called on `Result<K, InvalidObject>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `{type error}: Sized`
           which is required by `InvalidObject: Sized`

error[E0599]: the method `as_mut` exists for enum `Result<K, InvalidObject>`, but its trait bounds were not satisfied
  --> external/rules_rust~~crate~crates__kube-core-0.96.0/src/error_boundary.rs:86:16
   |
23 | pub struct InvalidObject {
   | ------------------------ doesn't satisfy `InvalidObject: Sized`
...
86 |         self.0.as_mut().map_or_else(|err| &mut err.metadata, K::meta_mut)
   |                ^^^^^^ method cannot be called on `Result<K, InvalidObject>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `{type error}: Sized`
           which is required by `InvalidObject: Sized`

error: aborting due to 15 previous errors

Some errors have detailed explanations: E0432, E0433, E0599.
For more information about an error, try `rustc --explain E0432`.
Target //:main failed to build

Do I need to add something so that kube uses the right features?

bazel: 7.4.0
rules_rust: 0.53.0

@joell
Copy link

joell commented Dec 23, 2024

I am observing the same error with an application in which I tried to upgrade kube.

kube 0.94.2 and k8s-openapi 0.22 both build fine.

When I upgrade to kube 0.95.0 and k8s-openapi 0.23, even though cargo still builds everything fine, rules_rust fails with the same errors shown in the original issue above.

So rules_rust is failing on something that changed in that project within those ranges. It looks like it may have something to do with how Cargo features are handled, as the errors about k8s_openapi::apimachinery seem to fail to detect the feature-based pub use of a version-specific apimachinery module, e.g.: https://github.com/Arnavion/k8s-openapi/blob/789dfef4c4022d13a09a4d4c97067be7472db160/src/lib.rs#L265-L266

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

2 participants