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

Alias mistakenly gets applied to library instead of build.rs #477

Open
maghoff opened this issue Mar 25, 2022 · 1 comment
Open

Alias mistakenly gets applied to library instead of build.rs #477

maghoff opened this issue Mar 25, 2022 · 1 comment

Comments

@maghoff
Copy link

maghoff commented Mar 25, 2022

When pulling in value-bag as a dependency with cargo-raze-0.15.0, an alias from Cargo.toml gets included in the generated rust_library rule, but it should apply to the generated cargo_build_script rule.

The dependency is declared in value-bag's Cargo.toml: https://github.com/sval-rs/value-bag/blob/v1.0.0-alpha.8/Cargo.toml#L100-L102

[build-dependencies.rustc]
version = "0.9"
package = "version_check"

The generated bazel rules:

cargo_build_script(
    name = "value_bag_build_script",
    srcs = glob(["**/*.rs"]),
    build_script_env = {
    },
    crate_features = [
    ],
    crate_root = "build.rs",
    data = glob(["**"]),
    edition = "2018",
    rustc_flags = [
        "--cap-lints=allow",
    ],
    tags = [
        "cargo-raze",
        "manual",
    ],
    version = "1.0.0-alpha.8",
    visibility = ["//visibility:private"],
    deps = [
        "@raze__version_check__0_9_4//:version_check",
    ],
)

rust_library(
    name = "value_bag",
    srcs = glob(["**/*.rs"]),
    aliases = {
        "@raze__version_check__0_9_4//:version_check": "rustc",
    },
    crate_features = [
    ],
    crate_root = "src/lib.rs",
    data = [],
    edition = "2018",
    proc_macro_deps = [
        "@raze__ctor__0_1_22//:ctor",
    ],
    rustc_flags = [
        "--cap-lints=allow",
    ],
    tags = [
        "cargo-raze",
        "crate-name=value-bag",
        "manual",
    ],
    version = "1.0.0-alpha.8",
    # buildifier: leave-alone
    deps = [
        ":value_bag_build_script",
    ],
)

This does not build correctly, as build.rs expects a crate named rustc, which is an alias of version_check. Moving the aliases section from the rust_library rule to the cargo_build_script rule fixes this:

cargo_build_script(
    name = "value_bag_build_script",
    srcs = glob(["**/*.rs"]),
    aliases = {
        "@raze__version_check__0_9_4//:version_check": "rustc",
    },
    build_script_env = {
    },
    crate_features = [
    ],
    crate_root = "build.rs",
    data = glob(["**"]),
    edition = "2018",
    rustc_flags = [
        "--cap-lints=allow",
    ],
    tags = [
        "cargo-raze",
        "manual",
    ],
    version = "1.0.0-alpha.8",
    visibility = ["//visibility:private"],
    deps = [
        "@raze__version_check__0_9_4//:version_check",
    ],
)

rust_library(
    name = "value_bag",
    srcs = glob(["**/*.rs"]),
    crate_features = [
    ],
    crate_root = "src/lib.rs",
    data = [],
    edition = "2018",
    proc_macro_deps = [
        "@raze__ctor__0_1_22//:ctor",
    ],
    rustc_flags = [
        "--cap-lints=allow",
    ],
    tags = [
        "cargo-raze",
        "crate-name=value-bag",
        "manual",
    ],
    version = "1.0.0-alpha.8",
    # buildifier: leave-alone
    deps = [
        ":value_bag_build_script",
    ],
)

Cargo-raze should generate aliases for build-dependencies in the cargo_build_script, but they are currently generated in the rust_library rule.

@dfreese
Copy link
Collaborator

dfreese commented Mar 25, 2022

This makes #475 more clear for me. Thanks. It looks like we'll need to be a little more careful about which aliases get applied where.

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