Skip to content

Is it a good idea to not depend on cargo? #150

Description

@csmoe

I'm not challenging the core design of rules_rs — I'm just exploring a possible alternative at the implementation level.

Currently, rules_rs reimplements Cargo's feature and dependency resolution logic on its own. In practice, I've run into a few problems with this:

  1. Host and target feature/dependency mixing. Host and target feature dependencies get mixed together, so some host-only dependencies leak into the target's dependencies. This pollution causes certain crates that compile fine under Cargo to fail under rules_rs, because the extra dependencies leave rustc unable to reach a decisive result during trait resolution.
  2. Build script environment variables not set correctly. Some of the environment variables that Cargo sets for build scripts aren't set properly. For example, cc-rs relies on OPT_LEVEL to pass optimization flags to C libraries, but rules_rust only supports 0–3 (see https://github.com/bazelbuild/rules_rust/blob/97e0d25539a1f7aca65625762679fa742ae8d750/rust/toolchain.bzl#L813), whereas opt-level can also be z (and s).

I'm still debugging my project. As far as I know, Cargo's feature and dependency resolution is quite complex, and Cargo itself keeps evolving. So I'm not sure how robust rules_rs's effort to replicate Cargo's behavior really is in the long run.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions