{"id":47680381,"url":"https://github.com/hermeticbuild/rules_rs","last_synced_at":"2026-06-16T02:01:47.420Z","repository":{"id":313372646,"uuid":"1051096710","full_name":"hermeticbuild/rules_rs","owner":"hermeticbuild","description":"Next-gen Rust Bazel rules which provide a blazing-fast ergonomic `crate_universe` reimplementation, first-class Windows support, optimized toolchains, and more.","archived":false,"fork":false,"pushed_at":"2026-06-08T19:20:47.000Z","size":4307,"stargazers_count":70,"open_issues_count":26,"forks_count":26,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-08T20:05:45.747Z","etag":null,"topics":["bazel","cross-compilation","hermetic","rust"],"latest_commit_sha":null,"homepage":"","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hermeticbuild.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-05T12:43:28.000Z","updated_at":"2026-06-08T18:03:01.000Z","dependencies_parsed_at":"2026-02-28T20:07:53.571Z","dependency_job_id":null,"html_url":"https://github.com/hermeticbuild/rules_rs","commit_stats":null,"previous_names":["dzbarsky/rules_rs","hermeticbuild/rules_rs"],"tags_count":86,"template":false,"template_full_name":"bazel-contrib/rules-template","purl":"pkg:github/hermeticbuild/rules_rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hermeticbuild%2Frules_rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hermeticbuild%2Frules_rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hermeticbuild%2Frules_rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hermeticbuild%2Frules_rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hermeticbuild","download_url":"https://codeload.github.com/hermeticbuild/rules_rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hermeticbuild%2Frules_rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34387472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel","cross-compilation","hermetic","rust"],"created_at":"2026-04-02T13:57:36.914Z","updated_at":"2026-06-16T02:01:47.414Z","avatar_url":"https://github.com/hermeticbuild.png","language":"Starlark","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Overview\n\n`rules_rs` is a Rust + Bazel ruleset built on top of [rules_rust](https://github.com/bazelbuild/rules_rust).\nIt provides a redistribution of the core compilation rules from `rules_rust`, augmenting them with optimized toolchains, crates.from_cargo integration, and other codepaths.\n\n## Why `rules_rs`\n\n- Fast incremental dependency resolution via Bazel downloader integration and lockfile facts. It uses your Cargo lockfile directly, with no Cargo workspace splicing and no Bazel-specific Cargo lockfile.\n- Hermetic Rust toolchains covering a wide target matrix, including Linux GNU/musl and Windows MSVC/GNU/GNULVM ABI variants.\n- Cross builds from any supported host to any supported target through the `@llvm` toolchain, including remote execution use cases.\n- A patched `rules_rust` repository with compatibility fixes for Windows linking, rust-analyzer integration, and related workflows.\n\n# Installation And Configuration\n\nAdd `rules_rs` to `MODULE.bazel`:\n\n```bzl\nbazel_dep(name = \"rules_rs\", version = \"0.0.33\")\n```\n\n## Paved Path\n\nThis is the default setup for new users. It provisions the patched `rules_rust`, registers `rules_rs` Rust toolchains, sets explicit host platforms, and resolves Cargo dependencies against `rules_rs` platforms.\n\n### `MODULE.bazel`\n\n```bzl\nbazel_dep(name = \"rules_rs\", version = \"0.0.61\")\nbazel_dep(name = \"llvm\", version = \"0.7.7\")\nbazel_dep(name = \"platforms\", version = \"1.1.0\")\n\ntoolchains = use_extension(\"@rules_rs//rs/toolchains:module_extension.bzl\", \"toolchains\")\ntoolchains.toolchain(\n    edition = \"2024\",\n    version = \"1.92.0\",\n)\nuse_repo(toolchains, \"default_rust_toolchains\")\n\n# This extension is optional but can help keep existing `@rules_rust` references working.\nrules_rust = use_extension(\"@rules_rs//rs:rules_rust.bzl\", \"rules_rust\")\nuse_repo(rules_rust, \"rules_rust\")\n\nregister_toolchains(\n    \"@default_rust_toolchains//:all\",\n    \"@llvm//toolchain:all\",\n)\n\ncrate = use_extension(\"@rules_rs//rs:extensions.bzl\", \"crate\")\ncrate.from_cargo(\n    name = \"crates\",\n    cargo_lock = \"//:Cargo.lock\",\n    cargo_toml = \"//:Cargo.toml\",\n    platform_triples = [\n        \"aarch64-apple-darwin\",\n        \"aarch64-pc-windows-msvc\",\n        \"aarch64-unknown-linux-gnu\",\n        \"x86_64-apple-darwin\",\n        \"x86_64-pc-windows-msvc\",\n        \"x86_64-unknown-linux-gnu\",\n    ],\n)\nuse_repo(crate, \"crates\")\n```\n\n`platform_triples` should include every exec and target triple that can participate in the build. For the common case, include the host triples you use locally and in CI plus the target triples you build for.\n\n### `.bazelrc`\n\nLinux hosts work with Bazel's default host platform. If you also build on Windows,\nset an explicit host platform there so Rust toolchain resolution can choose the\nright ABI.\n\n```bazelrc\ncommon --enable_platform_specific_config\ncommon:windows --host_platform=//platforms:local_windows_msvc\n```\n\n### `platforms/BUILD.bazel`\n\n```bzl\nplatform(\n    name = \"local_windows_msvc\",\n    parents = [\"@platforms//host\"],\n    constraint_values = [\n        \"@llvm//constraints/windows/abi:msvc\",\n    ],\n)\n```\n\nmacOS does not need an additional ABI constraint for the default host case.\n\n### `BUILD.bazel`\n\nPrefer the `rules_rs` wrappers for Rust targets:\n\n```bzl\nload(\"@crates//:defs.bzl\", \"aliases\", \"all_crate_deps\")\nload(\"@rules_rs//rs:rust_binary.bzl\", \"rust_binary\")\nload(\"@rules_rs//rs:rust_library.bzl\", \"rust_library\")\n\nrust_library(\n    name = \"lib\",\n    srcs = [\"src/lib.rs\"],\n    aliases = aliases(),\n    deps = all_crate_deps(normal = True),\n)\n\nrust_binary(\n    name = \"app\",\n    srcs = [\"src/main.rs\"],\n    deps = [\":lib\"],\n)\n```\n\n## rust-analyzer\n\nThe rust-analyzer generator can be invoked like so:\n\n```bash\nbazel run @rules_rs//tools/rust_analyzer:gen_rust_project -- --help\n```\n\nSee the upstream `rules_rust` rust-analyzer docs for editor setup details:\nhttps://bazelbuild.github.io/rules_rust/rust_analyzer.html#vscode\n\n## Advanced Options\n\n\u003cdetails\u003e\n\u003csummary\u003eUse legacy rules_rust toolchains or platforms\u003c/summary\u003e\n\nYou can keep an existing `rules_rust` toolchain setup during migration. In that mode, configure toolchains from `@rules_rust` and tell `crate.from_cargo(...)` to render selects against legacy `rules_rust` platform labels.\n\n```bzl\nrules_rust = use_extension(\"@rules_rs//rs:rules_rust.bzl\", \"rules_rust\")\nuse_repo(rules_rust, \"rules_rust\")\n\nrust = use_extension(\"@rules_rust//rust:extensions.bzl\", \"rust\")\nrust.toolchain(\n    edition = \"2024\",\n    versions = [\"1.92.0\"],\n)\n\nuse_repo(rust, \"rust_toolchains\")\nregister_toolchains(\"@rust_toolchains//:all\")\n\ncrate = use_extension(\"@rules_rs//rs:extensions.bzl\", \"crate\")\ncrate.from_cargo(\n    name = \"crates\",\n    cargo_lock = \"//:Cargo.lock\",\n    cargo_toml = \"//:Cargo.toml\",\n    platform_triples = [\n        \"x86_64-unknown-linux-gnu\",\n    ],\n    use_legacy_rules_rust_platforms = True,\n)\nuse_repo(crate, \"crates\")\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eCross ABI target details\u003c/summary\u003e\n\nProc macros and build scripts run in the exec configuration, while your library or binary may be built for a different target ABI. Include both exec and target triples when they differ.\n\nWindows GNULVM target with MSVC exec:\n\n```bzl\nplatform_triples = [\n    \"x86_64-pc-windows-msvc\",     # exec\n    \"x86_64-pc-windows-gnullvm\",  # target\n]\n```\n\nLinux musl target with GNU exec:\n\n```bzl\nplatform_triples = [\n    \"x86_64-unknown-linux-gnu\",   # exec\n    \"x86_64-unknown-linux-musl\",  # target\n]\n```\n\nThe default Windows exec toolchain is MSVC-flavored. The upstream GNULVM toolchain dynamically links `libunwind`, which may not exist on a stock Windows machine.\n\nThe Linux exec toolchains are GNU-flavored. When targeting musl, also include the corresponding GNU triple for build scripts and proc macros.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eRemote execution platforms\u003c/summary\u003e\n\nRemote execution platforms can inherit from a triple-based platform published by `rules_rs`, then add execution properties:\n\n```bzl\nplatform(\n    name = \"rbe_linux_amd64_gnu\",\n    parents = [\"@rules_rs//rs/platforms:x86_64-unknown-linux-gnu\"],\n    exec_properties = {\n        \"container-image\": \"docker://ghcr.io/example/rbe-linux-gnu:latest\",\n    },\n)\n```\n\nKeep host ABI constraints aligned with your exec toolchain choice. Model target ABI differences with target platforms and `platform_triples`.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003ePatch or override rules_rust\u003c/summary\u003e\n\n`rules_rs` exports a `rules_rust` module extension that provisions the pinned, patched `rules_rust` repository:\n\n```bzl\nrules_rust = use_extension(\"@rules_rs//rs:rules_rust.bzl\", \"rules_rust\")\n\nrules_rust.patch(\n    patches = [\"//:my_rules_rust_fix.patch\"],\n    strip = 1,\n)\n\nuse_repo(rules_rust, \"rules_rust\")\n```\n\nIf you need to replace the pinned repository completely, use `override_repo`:\n\n```bzl\nbazel_dep(name = \"rules_rs\", version = \"0.0.33\")\nbazel_dep(name = \"rules_rust\", version = \"0.68.1\")\n\narchive_override(\n    module_name = \"rules_rust\",\n    integrity = \"sha256-...\",\n    strip_prefix = \"rules_rust-\u003ccommit\u003e\",\n    urls = [\"https://github.com/my-org/rules_rust/archive/\u003ccommit\u003e.tar.gz\"],\n)\n\nrules_rust_ext = use_extension(\"@rules_rs//rs:rules_rust.bzl\", \"rules_rust\")\noverride_repo(rules_rust_ext, rules_rust = \"rules_rust\")\n```\n\nOverriding with a version that does not include required patches from [hermeticbuild/rules_rust](https://github.com/hermeticbuild/rules_rust) may cause build failures.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eProtobuf with prost\u003c/summary\u003e\n\nLoad prost rules and default toolchains from the reexported `@rules_rust` repository:\n\n```bzl\nload(\"@rules_rust//extensions/prost:defs.bzl\", \"rust_prost_library\")\n```\n\n```bzl\nbazel_dep(name = \"rules_proto\", version = \"7.1.0\")\nbazel_dep(name = \"protobuf\", version = \"34.0.bcr.1\")\n\nregister_toolchains(\n    \"@rules_rust//extensions/prost:default_prost_toolchain\",\n    \"@//path/to/proto_toolchain\",\n)\n```\n\nIf you need different prost, tonic, or plugin versions, define your own `rust_prost_toolchain` from `@rules_rust//extensions/prost:defs.bzl`.\n\n`rules_rs` also exposes a `@rules_rust_prost` compatibility repository to ease migration of existing code:\n\n```bzl\nrules_rust_prost = use_extension(\"//rs:rules_rust_prost.bzl\", \"rules_rust_prost\")\nuse_repo(rules_rust_prost, \"rules_rust_prost\")\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003ePython extensions with PyO3\u003c/summary\u003e\n\nLoad PyO3 rules and default toolchains from the reexported `@rules_rust` repository:\n\n```bzl\nload(\"@rules_rust//extensions/pyo3:defs.bzl\", \"pyo3_extension\")\n```\n\n```bzl\nregister_toolchains(\n    \"@rules_rust//extensions/pyo3/toolchains:toolchain\",\n    \"@rules_rust//extensions/pyo3/toolchains:rust_toolchain\",\n)\n```\n\nIf you need different PyO3 versions or Python discovery behavior, define your own `pyo3_toolchain` or `rust_pyo3_toolchain` from `@rules_rust//extensions/pyo3:defs.bzl`. \n\n`rules_rs` also exposes a `@rules_rust_pyo3` compatibility repository to ease migration of existing cod:\n\n```bzl\nrules_rust_pyo3 = use_extension(\"//rs:rules_rust_pyo3.bzl\", \"rules_rust_pyo3\")\nuse_repo(rules_rust_pyo3, \"rules_rust_pyo3\")\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eDependency resolution caveats\u003c/summary\u003e\n\n`rules_rs` currently supports Cargo lockfile based resolution through `crate.from_cargo(...)`.\n`crate.spec` and vendoring mode are not currently supported.\n\nCargo workspaces sometimes use a self-referencing dev-dependency to enable extra features for tests:\n\n```toml\n[dev-dependencies]\nmycrate = { path = \".\", features = [\"test-utils\"] }\n```\n\n`rules_rs` suppresses the generated self-edge in `aliases()` and `all_crate_deps()` so this pattern does not create a Bazel dependency cycle. The requested features are still part of workspace feature resolution, so they may be enabled on the first-party crate more broadly than Cargo would enable them for a single targeted test command.\n\nIf you need separate normal and test feature variants, model them as separate Bazel targets, with the test-only variant setting extra `crate_features` and `testonly = True`.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eMigration from rules_rust loads\u003c/summary\u003e\n\nIf you import `rules_rust` through the `rules_rs` extension, existing `load(\"@rules_rust//...\")` statements can be kept during migration.\n\nFor long-term hygiene, prefer migrating common Rust rule loads to `@rules_rs//rs:*` wrappers. A helper script is provided:\n\n```bash\n./scripts/rewrite_rules_rust_loads.sh\n```\n\nThe script rewrites common `@rules_rust` Rust loads to `@rules_rs//rs:*` wrappers and then formats with `buildifier`.\n\n\u003c/details\u003e\n\n## Public API\n\nSee https://registry.bazel.build/docs/rules_rs\n\n## Users\n\n- [OpenAI Codex](https://github.com/openai/codex)\n- [Aspect CLI](https://github.com/aspect-build/aspect-cli)\n- [Astradot](https://astradot.com)\n- [Datadog Agent](https://github.com/DataDog/datadog-agent)\n- [ZML](https://github.com/zml/zml/tree/zml/v2)\n- [rules_py](https://github.com/aspect-build/rules_py)\n- [JetBrains](https://github.com/JetBrains/intellij-community), used in closed sources of [JetBrains Air](https://air.dev/)\n- [Perplexity](https://perplexity.ai)\n- [formatjs](https://github.com/formatjs/formatjs)\n- [Trace Machina Nativelink](https://github.com/TraceMachina/nativelink)\n- [Selenium](https://github.com/SeleniumHQ/selenium)\n- [Etsy](https://www.etsy.com/)\n\n## Telemetry And Privacy Policy\n\nThis ruleset collects limited usage data via [`tools_telemetry`](https://github.com/aspect-build/tools_telemetry), which is reported to Aspect Build Inc and governed by their [privacy policy](https://www.aspect.build/privacy-policy).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhermeticbuild%2Frules_rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhermeticbuild%2Frules_rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhermeticbuild%2Frules_rs/lists"}