bazelbuild / rules_rust

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

Using locally installed rust toolchain #2275

Open blackgnezdo opened 10 months ago

blackgnezdo commented 10 months ago

I am trying to use rules_rust on OpenBSD which is currently not supported. I read the docs to the point of discovering rust_toolchain which seems to fit the pattern. Sadly my attempt is currently failing with:

$ bazel build --extra_toolchains=//bazel:rust_openbsd :a
...
INFO: Build option --extra_toolchains has changed, discarding analysis cache.
Analyzing: target //:a (0 packages loaded, 0 targets configured)
ERROR: /home/greg/s/rop/bazel/BUILD:3:15: //bazel:rust_openbsd_impl: invalid label '/usr/local/bin/rustdoc' in attribute 'rust_doc' in 'rust_toolchain' rule: invalid target name '/usr/local/bin/rustdoc': target names may not start with '/'
ERROR: /home/greg/s/rop/bazel/BUILD:3:15: //bazel:rust_openbsd_impl: invalid label '/usr/local/bin/rust_std' in attribute 'rust_std' in 'rust_toolchain' rule: invalid target name '/usr/local/bin/rust_std': target names may not start with '/'
ERROR: /home/greg/s/rop/bazel/BUILD:3:15: //bazel:rust_openbsd_impl: invalid label '/usr/local/bin/rustc' in attribute 'rustc' in 'rust_toolchain' rule: invalid target name '/usr/local/bin/rustc': target names may not start with '/'
ERROR: /home/greg/s/rop/bazel/BUILD:3:15: //bazel:rust_openbsd_impl: invalid label '/usr/local/bin/rustc_lib' in attribute 'rustc_lib' in 'rust_toolchain' rule: invalid target name '/usr/local/bin/rustc_lib': target names may not start with '/'
ERROR: /home/greg/s/rop/bazel/BUILD:3:15: //bazel:rust_openbsd_impl: missing value for mandatory attribute 'rust_doc' in 'rust_toolchain' rule
ERROR: /home/greg/s/rop/bazel/BUILD:3:15: //bazel:rust_openbsd_impl: missing value for mandatory attribute 'rust_std' in 'rust_toolchain' rule
ERROR: /home/greg/s/rop/bazel/BUILD:3:15: //bazel:rust_openbsd_impl: missing value for mandatory attribute 'rustc' in 'rust_toolchain' rule
ERROR: /home/greg/s/rop/BUILD:3:12: While resolving toolchains for target //:a: invalid registered toolchain '//bazel:rust_openbsd': Error evaluating '//bazel:rust_openbsd': error loading package 'bazel': Package 'bazel' contains errors
ERROR: Analysis of target '//:a' failed; build aborted: 

The code is available at https://github.com/blackgnezdo/rop.

What's the easiest way to build rust programs with a local toolchain?

If that's not the way to go, how do I extend rules_rust to add support for OpenBSD? I could conceivably host the bundle, or just keep a directory around and reference it with local_repository. What's the recipe for building the toolchain bundles?

UebelAndre commented 10 months ago

Something we could do is add a repository rule that allows you to set local paths to files that get symlinked into an external repository that can then be used in a toolchain. I'd be happy to review a PR for that 😄

blackgnezdo commented 10 months ago

OK, maybe I will feel inspired enough some day.