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

Unable to specify rust version in crate_universe bzlmod #3286

Open
UebelAndre opened this issue Feb 22, 2025 · 0 comments · May be fixed by #3293
Open

Unable to specify rust version in crate_universe bzlmod #3286

UebelAndre opened this issue Feb 22, 2025 · 0 comments · May be fixed by #3293

Comments

@UebelAndre
Copy link
Collaborator

It's currently not possible to define a custom version of Rust for crate universe extensions

RUST_VERSION = "1.84.0"

rust_host_tools = use_extension("@rules_rust//rust:extensions.bzl", "rust_host_tools")
rust_host_tools.host_tools(
    name = "my_rust_host_tools",
    version = RUST_VERSION,
)
use_repo(
    rust_host_tools,
    "my_rust_host_tools",
)

crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")

crate.from_cargo(
    name = "crate_index",
    manifests = ["//:Cargo.toml"],
    cargo_lockfile = "//:Cargo.lock",
    lockfile = "//:cargo-bazel-lock.json",
    host_tools_repo = "my_rust_host_tools",
    supported_platform_triples = [
        "aarch64-apple-darwin",
        "aarch64-unknown-linux-gnu",
        "x86_64-pc-windows-msvc",
        "x86_64-unknown-linux-gnu",
    ],
)

use_repo(
    crate,
    "crate_index",
)

This will fail with the following error

ERROR: /private/var/tmp/_bazel_user/b8286dc79fef4b6257e32e451f5cae57/external/rules_rust+/crate_universe/extensions.bzl:833:37: Traceback (most recent call last):
	File "/private/var/tmp/_bazel_user/b8286dc79fef4b6257e32e451f5cae57/external/rules_rust+/crate_universe/extensions.bzl", line 949, column 59, in _crate_impl
		cargo_path, rustc_path = _get_host_cargo_rustc(module_ctx, host_triple, cfg.host_tools_repo)
	File "/private/var/tmp/_bazel_user/b8286dc79fef4b6257e32e451f5cae57/external/rules_rust+/crate_universe/extensions.bzl", line 833, column 37, in _get_host_cargo_rustc
		cargo_path = str(module_ctx.path(Label("@{}//:bin/cargo{}".format(host_tools_repo, binary_ext))))
Error in path: Unable to load package for @@[unknown repo 'my_rust_host_tools' requested from @@rules_rust+ (did you mean 'rust_host_tools'?)]//:bin/cargo: The repository '@@[unknown repo 'my_rust_host_tools' requested from @@rules_rust+ (did you mean 'rust_host_tools'?)]' could not be resolved: No repository visible as '@my_rust_host_tools' from repository '@@rules_rust+'
ERROR: error evaluating module extension @@rules_rust+//crate_universe:extensions.bzl%crate

It's important that consumers of crate_universe are able to easily describe the version of rust their generation is based off of. Ideally there would be a rust_version attribute on from_cargo and from_specs but I don't know if this is the most performant path. Suggestions welcomed!

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

Successfully merging a pull request may close this issue.

1 participant