Skip to content

Support extra_target_triples targets from @rules_rust//tools/upstream_wrapper* for bazel_env #3576

@aran

Description

@aran

@kolloch's bazel_env example is great. I tried to use it to use the Bazel-managed rust toolchain for non-Bazel-aware tools that invoke rustc, including a tool that directly invokes rustup and one that runs cargo. It would a big project to port those outside tools to Bazel, but it would still be a nice little win to consolidate on one Rust toolchain, which would avoid issues of syncing rustup and rust-toolchain.toml with the rules_rust configuration.

My wishlist feature request is to somehow support cross-compilation from @rules_rust//tools/upstream_wrapper:rustc, with theextra_target_triples in rust.toolchain taking the place of rustup target add.

In other words:

# MODULE.bazel
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
    edition = "2021",
    extra_target_triples = [
        "aarch64-unknown-linux-gnu",
        "wasm32-unknown-unknown",
        "x86_64-unknown-linux-gnu",
    ],
)
# .../BUILD.bazel
bazel_env(
    name = "bazel_env",
    # TODO: Upgrade when on Bazel 9+
    # toolchains = {
    #     "rust": "@rules_rust//rust/toolchain:current_rust_toolchain",
    # },
    tools = {
        # TODO: Uncomment when on Bazel 9+
        # "cargo": "$(CARGO)",
        # "rustfmt": "$(RUSTFMT)",
        # "rustc": "$(RUSTC)",
        # "rustdoc": "$(RUSTDOC)",
        "cargo": "@rules_rust//tools/upstream_wrapper:cargo",
        "cargo-clippy": "@rules_rust//tools/upstream_wrapper:cargo_clippy",
        "rustc": "@rules_rust//tools/upstream_wrapper:rustc",
        "rustfmt": "@rules_rust//tools/upstream_wrapper:rustfmt",

    },
...

Then:
wasm-pack build ...

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