You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This ruleset is a companion to [rules_rust](https://github.com/bazelbuild/rules_rust) which provides a reimplementation of `crate_universe`. It integrates tightly with Bazel's downloader and the lockfile facts API, allowing automatic,
4
-
extremely fast, incremental resolution without the Bazel-specific Cargo lockfile that `rules_rust` uses.
3
+
`rules_rs` is both a wrapper around [rules_rust](https://github.com/bazelbuild/rules_rust) and an alternative implementation for selected parts of the Rust + Bazel stack.
5
4
6
-
## Installation
5
+
It is designed to:
7
6
7
+
- Reuse stable `rules_rust` functionality, such as the core compilation rules.
8
+
- Provide alternative implementations where there is a benefit to be gained (`crate_universe`-style dependency resolution and toolchain provisioning).
9
+
- Let users migrate incrementally while still reusing selected `rules_rust` components (for example toolchains).
10
+
11
+
## Advantages Over `rules_rust`
12
+
13
+
- Extremely fast (~200ms) incremental dependency resolution via Bazel downloader integration and lockfile facts. Uses your Cargo lockfile directly. No "Cargo workspace splicing", no Bazel-specific Cargo lockfile.
14
+
- Toolchains are more flexible, powerful, and lightweight. We don't register any toolchains by default, but with a 1-line `register_toolchains` call you can have a working setup for the entire cross-product of supported exec and target triples. The support matrix is wider than rules_rust, we support multiple ABIs per OS (-msvc, -gnu, and -gnullvm on Windows, -gnu and -musl on Linux). We bring fully hermetic `-musl`, `-gnullvm`, and OSX linker runtimes thanks to @llvm module, so you can do full cross builds from any host platform to any target platform, including with remote execution. (OSX host, linux remote executor, Windows gnullvm target works seamlessly). See [PR #21](https://github.com/dzbarsky/rules_rs/pull/21) for more details.
15
+
- The patched `rules_rust` extension provides all underlying rules_rust functionality with many fixes applied (Windows linking works now, various rust-analyzer improvements, etc.)
16
+
17
+
# Installation and Configuraiton
18
+
19
+
```bzl
20
+
bazel_dep(name="rules_rs", version="0.0.33")
8
21
```
9
-
bazel_dep(name = "rules_rs", version = "0.0.1")
10
-
```
11
22
12
-
## Usage
13
-
Usage is basically the same as in rules_rust, with a few attributes renamed for clarity.
23
+
## Toolchains
24
+
25
+
Strongly recommended: use `rules_rs` toolchains.
26
+
27
+
You can still use `rules_rust` toolchains when doing a gradual migration, but that should be considered a compatibility on-ramp rather than the default.
# True when using rules_rs experimental toolchains/platforms.
65
+
# False (default) when using rules_rust toolchains/platforms.
66
+
use_experimental_platforms=True,
28
67
)
29
68
30
-
crate.annotation(
31
-
crate = "backtrace",
32
-
gen_build_script = "off",
69
+
use_repo(crate, "crates")
70
+
```
71
+
72
+
`crate.spec` and vendoring mode are currently unsupported.
73
+
74
+
### Exec vs target triple caveats
75
+
76
+
- Windows: the default Windows **exec** toolchain is MSVC-flavored. The upstream `gnullvm` toolchain dynamically links `libunwind`, which may not exist on a stock Windows machine.
77
+
- If you target `*-pc-windows-gnullvm`, resolve both triples in dependency resolution (`crate.from_cargo`): one MSVC triple for exec/build-script/proc-macro work and one `gnullvm` triple for target artifacts.
78
+
- Linux: similarly, when targeting `*-unknown-linux-musl`, also include the corresponding `*-unknown-linux-gnu` triple for exec. Proc macros and build scripts run in exec configuration, and Linux exec toolchains are GNU. This is required because the current `@toolchains_llvm_bootstrapped` flow cannot produce musl-flavored proc-macro `.so` artifacts for exec.
79
+
80
+
Example `platform_triples` values:
81
+
82
+
```bzl
83
+
# Windows gnullvm target with MSVC exec.
84
+
platform_triples = [
85
+
"x86_64-pc-windows-msvc", # exec
86
+
"x86_64-pc-windows-gnullvm", # target
87
+
]
88
+
89
+
# Linux musl target with GNU exec.
90
+
platform_triples = [
91
+
"x86_64-unknown-linux-gnu", # exec
92
+
"x86_64-unknown-linux-musl", # target
93
+
]
94
+
```
95
+
96
+
# TODO(zbarsky): Should we issue warnings if you configure the triples in an unexpected way?
97
+
98
+
## Import `rules_rust` from `rules_rs`
99
+
100
+
`rules_rs` exports a `rules_rust` module extension you can use to provision the pinned `rules_rust` repo:
The core compilation rules (`rust_library`, `rust_binary`, `rust_test`, `rust_proc_macro`, `rust_static_library`, and `rust_dynamic_library`) can be loaded directly from `@rules_rs//rs:*.bzl` but clippy integration, protobuf, etc come from rules_rust for now.
108
+
Using this extension is STRONGLY ENCOURAGED because it carries fixes that improve Windows behavior, rust-analyzer integration, and related compatibility work.
109
+
In addition, when using the `rules_rs` toolchains, loading the compilation rules from `@rules_rs` directly and using the extension is REQUIRED for toolchain resolution to work correctly, at least until https://github.com/bazelbuild/rules_rust/pull/3857 is accepted by rules_rust maintainers. See the Migration section for more info.
110
+
111
+
## Platform Configuration
112
+
113
+
For reliable toolchain resolution, ABI choices should be explicit on every platform participating in your build, including the host platform.
114
+
115
+
Linux and Windows each have ABI variants that affect toolchain matching (gnu/musl on Linux, msvc/gnu/gnullvm on Windows). Implicit/default platforms lacking these constraints will result in toolchain resolution errors, as no toolchains will match.
116
+
117
+
At minimum, set an explicit `--host_platform` that adds your ABI constraint on top of `@platforms//host`:
`crate.spec` and vendoring mode are currently unsupported.
148
+
Set host ABI constraints to match your exec toolchain choice; handle target ABI differences via target platforms and `platform_triples`.
39
149
40
-
# Public API
150
+
For remote execution platforms, you can inherit from a triple-based platform published in `@rules_rs//rs/experimental/platforms` and then layer exec properties:
A sample migration script is provided at `scripts/rewrite_rules_rust_loads.sh`. It rewrites common `@rules_rust` Rust loads to `@rules_rs//rs:*` wrappers and then formats with `buildifier`.
0 commit comments