bazelbuild / rules_rust

Rust rules for Bazel
https://bazelbuild.github.io/rules_rust/
Apache License 2.0
669 stars 432 forks source link

`crate_universe` does not properly handle limited supported platforms #1236

Closed oremj closed 2 years ago

oremj commented 2 years ago

Error: dictionary expression has duplicate key with ahash = "=0.7.6" dependency.

Error

 ✗ CARGO_BAZEL_REPIN=true bazel build //...
ERROR: Traceback (most recent call last):
        File "/private/var/tmp/_bazel_jorem/a467426d3969779b6b4da85835fb4354/external/crates_sandbox__ahash-0.7.6/BUILD.bazel", line 52, column 10, in <toplevel>
                ): [
Error: dictionary expression has duplicate key: ("@rules_rust//rust/platform:x86_64-apple-darwin", "@rules_rust//rust/platform:x86_64-unknown-linux-gnu")
ERROR: /Users/jorem/development/rules_rust_sandbox/duplicate_condition/BUILD.bazel:5:12: no such target '@crates_sandbox__ahash-0.7.6//:ahash': target 'ahash' not declared in package '' defined by /private/var/tmp/_bazel_jorem/a467426d3969779b6b4da85835fb4354/external/crates_sandbox__ahash-0.7.6/BUILD.bazel and referenced by '//duplicate_condition:duplicate_condition'
ERROR: Analysis of target '//duplicate_condition:duplicate_condition' failed; build aborted: Analysis failed
INFO: Elapsed time: 14.040s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (26 packages loaded, 46 targets configured)

Generated build file

###############################################################################
# @generated
# This file is auto-generated by the cargo-bazel tool.
#
# DO NOT MODIFY: Local changes may be replaced in future executions.
###############################################################################

load(
    "@bazel_skylib//lib:selects.bzl", 
    "selects",
)
load(
    "@rules_rust//cargo:defs.bzl",
    "cargo_build_script",
)
load(
    "@rules_rust//rust:defs.bzl",
    "rust_binary",
    "rust_library",
    "rust_proc_macro",
)

# buildifier: disable=bzl-visibility
load("@rules_rust//crate_universe/private:selects.bzl", "select_with_or")

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

# licenses([
#     "TODO",  # MIT OR Apache-2.0
# ])

rust_library(
    name = "ahash",
    deps = [
    ] + select_with_or({
        # cfg(any(target_os = "linux", target_os = "android", target_os = "windows", target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly", target_os = "solaris", target_os = "illumos", target_os = "fuchsia", target_os = "redox", target_os = "cloudabi", target_os = "haiku", target_os = "vxworks", target_os = "emscripten", target_os = "wasi"))
        (
            "@rules_rust//rust/platform:x86_64-apple-darwin",
            "@rules_rust//rust/platform:x86_64-unknown-linux-gnu",
        ): [
            # Target Deps
            "@crates_sandbox__getrandom-0.2.6//:getrandom",

            # Common Deps
            "@crates_sandbox__ahash-0.7.6//:build_script_build",
        ],
        # cfg(not(all(target_arch = "arm", target_os = "none")))
        (
            "@rules_rust//rust/platform:x86_64-apple-darwin",
            "@rules_rust//rust/platform:x86_64-unknown-linux-gnu",
        ): [
            # Target Deps
            "@crates_sandbox__once_cell-1.10.0//:once_cell",

            # Common Deps
            "@crates_sandbox__ahash-0.7.6//:build_script_build",
        ],
        "//conditions:default": [
            "@crates_sandbox__ahash-0.7.6//:build_script_build",
        ],
    }),
    proc_macro_deps = [
    ] + select_with_or({
        "//conditions:default": [
        ],
    }),
    aliases = selects.with_or({
        "//conditions:default": {
        },
    }),
    compile_data = glob(["**"]) + select_with_or({
        "//conditions:default": [
        ],
    }),
    crate_root = "src/lib.rs",
    crate_features = [
        "default",
        "std",
    ],
    data = select_with_or({
        "//conditions:default": [
        ],
    }),
    edition = "2018",
    rustc_env = {
    },
    rustc_env_files = select_with_or({
        "//conditions:default": [
        ],
    }),
    rustc_flags = [
        # In most cases, warnings in 3rd party crates are not interesting as
        # they're out of the control of consumers. The flag here silences 
        # warnings. For more details see: 
        # https://doc.rust-lang.org/rustc/lints/levels.html
        "--cap-lints=allow",
    ] + select_with_or({
        "//conditions:default": [
        ],
    }),
    srcs = glob(
        include = [
            "**/*.rs",
        ],
        exclude = [
        ],
    ),
    version = "0.7.6",
    tags = [
        "cargo-bazel",
        "manual",
        "noclippy",
        "norustfmt",
    ],

)

cargo_build_script(
    # See comment associated with alias. Do not change this name
    name = "ahash_build_script",
    aliases = selects.with_or({
        "//conditions:default": {
        },
    }),
    build_script_env = {
    },
    compile_data = select_with_or({
        "//conditions:default": [
        ],
    }),
    crate_name = "build_script_build",
    crate_root = "build.rs",
    crate_features = [
        "default",
        "std",
    ],
    data = glob(["**"]) + select_with_or({
        "//conditions:default": [
        ],
    }),
    deps = [
    ] + select_with_or({
        "//conditions:default": [
            "@crates_sandbox__version_check-0.9.4//:version_check",
        ],
    }),
    edition = "2018",
    proc_macro_deps = [
    ] + select_with_or({
        "//conditions:default": [
        ],
    }),
    rustc_env = {
    },
    rustc_env_files = select_with_or({
        "//conditions:default": [
        ],
    }),
    rustc_flags = [
        # In most cases, warnings in 3rd party crates are not interesting as
        # they're out of the control of consumers. The flag here silences 
        # warnings. For more details see: 
        # https://doc.rust-lang.org/rustc/lints/levels.html
        "--cap-lints=allow",
    ] + select_with_or({
        "//conditions:default": [
        ],
    }),
    srcs = glob(
        include = [
            "**/*.rs",
        ],
        exclude = [
        ],
    ),
    tools = select_with_or({
        "//conditions:default": [
        ],
    }),
    version = "0.7.6",
    tags = [
        "cargo-bazel",
        "manual",
        "noclippy",
        "norustfmt",
    ],
    visibility = ["//visibility:private"],
)
alias(
    # Because `cargo_build_script` does some invisible target name mutating to
    # determine the package and crate name for a build script, the Bazel
    # target namename of any build script cannot be the Cargo canonical name
    # of `build_script_build` without losing out on having certain Cargo
    # environment variables set.
    name = "build_script_build",
    actual = "ahash_build_script",
    tags = [
        "manual",
    ],
)

Steps to reproduce

git clone https://github.com/oremj/rules_rust_sandbox.git
cd rules_rust_sandbox
CARGO_BAZEL_REPIN=true bazel build //...
UebelAndre commented 2 years ago

Very interesting. The configuration selector logic seems to not be appropriately handling cases where limited platforms are provided. As a workaround, could you try unrestricting the supported platforms?

diff --git a/WORKSPACE b/WORKSPACE
index 4971ae74..27aa329e 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -37,10 +37,6 @@ crates_repository(
     ],
     lockfile = "//:crate.lock",
     generator = "@cargo_bazel_bootstrap//:cargo-bazel",
-    supported_platform_triples = [
-        "x86_64-apple-darwin",
-        "x86_64-unknown-linux-gnu",
-    ],
 )

 load("@crates_sandbox//:defs.bzl", "crate_repositories")
oremj commented 2 years ago

Confirmed that removing supported_platform_triples allows the build to succeed.

UebelAndre commented 2 years ago

Closing this out in favor of https://github.com/bazelbuild/rules_rust/issues/1417 which seems to have more discussions around long term solutions.