blob: d10db023eb4c7036fae04f55ed7cbdc6edfa3f26 [file] [log] [blame] [edit]
<!DOCTYPE HTML>
<html lang="en" class="light sidebar-visible" dir="ltr">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>rules_rust</title>
<meta name="robots" content="noindex">
<!-- Custom HTML head -->
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" href="favicon.svg">
<link rel="shortcut icon" href="favicon.png">
<link rel="stylesheet" href="css/variables.css">
<link rel="stylesheet" href="css/general.css">
<link rel="stylesheet" href="css/chrome.css">
<link rel="stylesheet" href="css/print.css" media="print">
<!-- Fonts -->
<link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="fonts/fonts.css">
<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" href="highlight.css">
<link rel="stylesheet" href="tomorrow-night.css">
<link rel="stylesheet" href="ayu-highlight.css">
<!-- Custom theme stylesheets -->
<!-- Provide site root to javascript -->
<script>
var path_to_root = "";
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
</script>
<!-- Start loading toc.js asap -->
<script src="toc.js"></script>
</head>
<body>
<div id="body-container">
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
var theme = localStorage.getItem('mdbook-theme');
var sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script>
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
const html = document.documentElement;
html.classList.remove('light')
html.classList.add(theme);
html.classList.add("js");
</script>
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
<!-- Hide / unhide sidebar before it is displayed -->
<script>
var sidebar = null;
var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
}
sidebar_toggle.checked = sidebar === 'visible';
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<!-- populated by js -->
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="toc.html"></iframe>
</noscript>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
<div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">rules_rust</h1>
<div class="right-buttons">
<a href="print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
<a href="https://github.com/bazelbuild/rules_rust" title="Git repository" aria-label="Git repository">
<i id="git-repository-button" class="fa fa-github"></i>
</a>
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
<script>
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<h1 id="rules-rust"><a class="header" href="#rules-rust">Rules Rust</a></h1>
<p>This repository provides rules for building <a href="http://www.rust-lang.org/">Rust</a> projects with <a href="https://bazel.build/">Bazel</a>.</p>
<!-- TODO: Render generated docs on the github pages site again, https://bazelbuild.github.io/rules_rust/ -->
<p><a name="setup"></a></p>
<h2 id="setup"><a class="header" href="#setup">Setup</a></h2>
<p>The rules are released, and releases can be found on <a href="https://github.com/bazelbuild/rules_rust/releases">the GitHub Releases page</a>. We recommend using the latest release from that page.</p>
<h3 id="bzlmod"><a class="header" href="#bzlmod">Bzlmod</a></h3>
<p>Note that rules_rust bzlmod support is still a work in progress. Most features should work, but bugs are more likely. This is not a desired end-state - please report (or better yet, help fix!) bugs you run into.</p>
<p>To use <code>rules_rust</code> in a project using bzlmod, add the following to your <code>MODULE.bazel</code> file:</p>
<pre><code class="language-python">bazel_dep(name = "rules_rust", version = "0.48.0")
</code></pre>
<p>Don't forget to substitute in your desired release's version number.</p>
<h3 id="workspace"><a class="header" href="#workspace">WORKSPACE</a></h3>
<p>To use <code>rules_rust</code> in a project using a WORKSPACE file, add the following to your <code>WORKSPACE</code> file to add the external repositories for the Rust toolchain:</p>
<pre><code class="language-python">load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# To find additional information on this release or newer ones visit:
# https://github.com/bazelbuild/rules_rust/releases
http_archive(
name = "rules_rust",
integrity = "sha256-Weev1uz2QztBlDA88JX6A1N72SucD1V8lBsaliM0TTg=",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.48.0/rules_rust-v0.48.0.tar.gz"],
)
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
rules_rust_dependencies()
rust_register_toolchains()
</code></pre>
<p>Don't forget to substitute in your desired release's version number and integrity hash.</p>
<h2 id="specifying-rust-version"><a class="header" href="#specifying-rust-version">Specifying Rust version</a></h2>
<p>To build with a particular version of the Rust compiler, pass that version to <a href="flatten.html#rust_register_toolchains"><code>rust_register_toolchains</code></a>:</p>
<pre><code class="language-python">rust_register_toolchains(
edition = "2021",
versions = [
"1.79.0"
],
)
</code></pre>
<p>As well as an exact version, <code>versions</code> can accept <code>nightly/{iso_date}</code> and <code>beta/{iso_date}</code> strings for toolchains from different release channels.</p>
<pre><code class="language-python">rust_register_toolchains(
edition = "2021",
versions = [
"nightly/2024-06-13",
],
)
</code></pre>
<p>By default, a <code>stable</code> and <code>nightly</code> toolchain will be registered if no versions are passed to <code>rust_register_toolchains</code>. However,
if only 1 version is passed and it is from the <code>nightly</code> or <code>beta</code> release channels (i.e. <strong>not</strong> <code>stable</code>), then a build setting must
also be set in the project's <code>.bazelrc</code> file.</p>
<pre><code class="language-text">build --@rules_rust//rust/toolchain/channel=nightly
</code></pre>
<p>Failure to do so will result in rules attempting to match a <code>stable</code> toolchain when one was not registered.</p>
<h2 id="supported-bazel-versions"><a class="header" href="#supported-bazel-versions">Supported bazel versions</a></h2>
<p>The oldest version of Bazel the <code>main</code> branch is tested against is <code>7.3.1</code>. Previous versions may still be functional in certain environments, but this is the minimum version we strive to fully support.</p>
<p>We test these rules against the latest rolling releases of Bazel, and aim for compatibility with them, but prioritise stable releases over rolling releases where necessary.</p>
<h2 id="supported-platforms"><a class="header" href="#supported-platforms">Supported platforms</a></h2>
<p>We aim to support Linux and macOS.</p>
<p>We do not have sufficient maintainer expertise to support Windows. Most things probably work, but we have had to disable many tests in CI because we lack the expertise to fix them. We welcome contributions to help improve its support.</p>
<p>Windows support for some features requires <code>--enable_runfiles</code> to be passed to Bazel, we recommend putting it in your bazelrc. See <a href="https://bazel.build/configure/windows">Using Bazel on Windows</a> for more Windows-specific recommendations.</p>
<div style="break-before: page; page-break-before: always;"></div><h1 id="rules"><a class="header" href="#rules">Rules</a></h1>
<ul>
<li><a href="defs.html">defs</a>: standard rust rules for building and testing libraries and binaries.</li>
<li><a href="rust_doc.html">rustdoc</a>: rules for generating and testing rust documentation.</li>
<li><a href="rust_clippy.html">clippy</a>: rules for running <a href="https://github.com/rust-lang/rust-clippy#readme">clippy</a>.</li>
<li><a href="rust_fmt.html">rustfmt</a>: rules for running <a href="https://github.com/rust-lang/rustfmt#readme">rustfmt</a>.</li>
<li><a href="cargo.html">cargo</a>: Rules dedicated to Cargo compatibility. ie: <a href="https://doc.rust-lang.org/cargo/reference/build-scripts.html"><code>build.rs</code> scripts</a>.</li>
<li><a href="external_crates.html">crate_universe</a>: Rules for generating Bazel targets for external crate dependencies.</li>
</ul>
<h2 id="experimental-rules"><a class="header" href="#experimental-rules">Experimental rules</a></h2>
<ul>
<li><a href="rust_analyzer.html">rust_analyzer</a>: rules for generating <code>rust-project.json</code> files for <a href="https://rust-analyzer.github.io/">rust-analyzer</a></li>
</ul>
<h2 id="3rd-party-rules"><a class="header" href="#3rd-party-rules">3rd party rules</a></h2>
<ul>
<li><a href="rust_bindgen.html">rust_bindgen</a>: rules for generating C++ bindings.</li>
<li><a href="rust_proto.html">rust_proto</a>: rules for generating <a href="https://developers.google.com/protocol-buffers">protobuf</a> and <a href="https://grpc.io">gRPC</a> stubs.</li>
<li><a href="rust_wasm_bindgen.html">rust_wasm_bindgen</a>: rules for generating <a href="https://www.rust-lang.org/what/wasm">WebAssembly</a> bindings.</li>
</ul>
<h2 id="full-api"><a class="header" href="#full-api">Full API</a></h2>
<p>You can also browse the <a href="flatten.html">full API in one page</a>.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="rust"><a class="header" href="#rust">Rust</a></h1>
<ul>
<li><a href="rust.html#rust_binary">rust_binary</a></li>
<li><a href="rust.html#rust_library">rust_library</a></li>
<li><a href="rust.html#rust_library_group">rust_library_group</a></li>
<li><a href="rust.html#rust_static_library">rust_static_library</a></li>
<li><a href="rust.html#rust_shared_library">rust_shared_library</a></li>
<li><a href="rust.html#rust_proc_macro">rust_proc_macro</a></li>
<li><a href="rust.html#rust_test">rust_test</a></li>
<li><a href="rust.html#rust_test_suite">rust_test_suite</a></li>
<li><a href="rust.html#error_format">error_format</a></li>
<li><a href="rust.html#extra_rustc_flag">extra_rustc_flag</a></li>
<li><a href="rust.html#extra_rustc_flags">extra_rustc_flags</a></li>
<li><a href="rust.html#capture_clippy_output">capture_clippy_output</a></li>
</ul>
<p><a id="capture_clippy_output"></a></p>
<h2 id="capture_clippy_output"><a class="header" href="#capture_clippy_output">capture_clippy_output</a></h2>
<pre>
capture_clippy_output(<a href="rust.html#capture_clippy_output-name">name</a>)
</pre>
<p>Control whether to print clippy output or store it to a file, using the configured error_format.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="capture_clippy_output-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="error_format"></a></p>
<h2 id="error_format"><a class="header" href="#error_format">error_format</a></h2>
<pre>
error_format(<a href="rust.html#error_format-name">name</a>)
</pre>
<p>Change the <a href="https://doc.rust-lang.org/rustc/command-line-arguments.html#option-error-format">--error-format</a> flag from the command line with <code>--@rules_rust//:error_format</code>. See rustc documentation for valid values.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="error_format-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="extra_rustc_flag"></a></p>
<h2 id="extra_rustc_flag"><a class="header" href="#extra_rustc_flag">extra_rustc_flag</a></h2>
<pre>
extra_rustc_flag(<a href="rust.html#extra_rustc_flag-name">name</a>)
</pre>
<p>Add additional rustc_flag from the command line with <code>--@rules_rust//:extra_rustc_flag</code>. Multiple uses are accumulated and appended after the extra_rustc_flags.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="extra_rustc_flag-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="extra_rustc_flags"></a></p>
<h2 id="extra_rustc_flags"><a class="header" href="#extra_rustc_flags">extra_rustc_flags</a></h2>
<pre>
extra_rustc_flags(<a href="rust.html#extra_rustc_flags-name">name</a>)
</pre>
<p>Add additional rustc_flags from the command line with <code>--@rules_rust//:extra_rustc_flags</code>. This flag should only be used for flags that need to be applied across the entire build. For options that apply to individual crates, use the rustc_flags attribute on the individual crate's rule instead. NOTE: These flags not applied to the exec configuration (proc-macros, cargo_build_script, etc); use <code>--@rules_rust//:extra_exec_rustc_flags</code> to apply flags to the exec configuration.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="extra_rustc_flags-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rust_binary"></a></p>
<h2 id="rust_binary"><a class="header" href="#rust_binary">rust_binary</a></h2>
<pre>
rust_binary(<a href="rust.html#rust_binary-name">name</a>, <a href="rust.html#rust_binary-deps">deps</a>, <a href="rust.html#rust_binary-srcs">srcs</a>, <a href="rust.html#rust_binary-data">data</a>, <a href="rust.html#rust_binary-aliases">aliases</a>, <a href="rust.html#rust_binary-alwayslink">alwayslink</a>, <a href="rust.html#rust_binary-binary_name">binary_name</a>, <a href="rust.html#rust_binary-compile_data">compile_data</a>, <a href="rust.html#rust_binary-crate_features">crate_features</a>,
<a href="rust.html#rust_binary-crate_name">crate_name</a>, <a href="rust.html#rust_binary-crate_root">crate_root</a>, <a href="rust.html#rust_binary-crate_type">crate_type</a>, <a href="rust.html#rust_binary-edition">edition</a>, <a href="rust.html#rust_binary-env">env</a>, <a href="rust.html#rust_binary-experimental_use_cc_common_link">experimental_use_cc_common_link</a>,
<a href="rust.html#rust_binary-linker_script">linker_script</a>, <a href="rust.html#rust_binary-malloc">malloc</a>, <a href="rust.html#rust_binary-out_binary">out_binary</a>, <a href="rust.html#rust_binary-platform">platform</a>, <a href="rust.html#rust_binary-proc_macro_deps">proc_macro_deps</a>, <a href="rust.html#rust_binary-rustc_env">rustc_env</a>, <a href="rust.html#rust_binary-rustc_env_files">rustc_env_files</a>,
<a href="rust.html#rust_binary-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_binary-stamp">stamp</a>, <a href="rust.html#rust_binary-version">version</a>)
</pre>
<p>Builds a Rust binary crate.</p>
<p>Example:</p>
<p>Suppose you have the following directory structure for a Rust project with a
library crate, <code>hello_lib</code>, and a binary crate, <code>hello_world</code> that uses the
<code>hello_lib</code> library:</p>
<pre><code class="language-output">[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
lib.rs
hello_world/
BUILD
src/
main.rs
</code></pre>
<p><code>hello_lib/src/lib.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct Greeter {
greeting: String,
}
impl Greeter {
pub fn new(greeting: &amp;str) -&gt; Greeter {
Greeter { greeting: greeting.to_string(), }
}
pub fn greet(&amp;self, thing: &amp;str) {
println!("{} {}", &amp;self.greeting, thing);
}
}
<span class="boring">}</span></code></pre></pre>
<p><code>hello_lib/BUILD</code>:</p>
<pre><code class="language-python">package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_library")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
</code></pre>
<p><code>hello_world/src/main.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust">extern crate hello_lib;
fn main() {
let hello = hello_lib::Greeter::new("Hello");
hello.greet("world");
}</code></pre></pre>
<p><code>hello_world/BUILD</code>:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_binary")
rust_binary(
name = "hello_world",
srcs = ["src/main.rs"],
deps = ["//hello_lib"],
)
</code></pre>
<p>Build and run <code>hello_world</code>:</p>
<pre><code>$ bazel run //hello_world
INFO: Found 1 target...
Target //examples/rust/hello_world:hello_world up-to-date:
bazel-bin/examples/rust/hello_world/hello_world
INFO: Elapsed time: 1.308s, Critical Path: 1.22s
INFO: Running command line: bazel-bin/examples/rust/hello_world/hello_world
Hello world
</code></pre>
<p>On Windows, a PDB file containing debugging information is available under
the key <code>pdb_file</code> in <code>OutputGroupInfo</code>. Similarly on macOS, a dSYM folder
is available under the key <code>dsym_folder</code> in <code>OutputGroupInfo</code>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_binary-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-binary_name"></a>binary_name</td><td style="text-align: left">Override the resulting binary file name. By default, the binary file will be named using the <code>name</code> attribute on this rule, however sometimes that is not deseriable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-crate_type"></a>crate_type</td><td style="text-align: left">Crate type that will be passed to <code>rustc</code> to be used for building this crate.<br><br>This option is a temporary workaround and should be used only when building for WebAssembly targets (//rust/platform:wasi and //rust/platform:wasm).</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"bin"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-env"></a>env</td><td style="text-align: left">Specifies additional environment variables to set when the target is executed by bazel run. Values are subject to <code>$(rootpath)</code>, <code>$(execpath)</code>, location, and <a href="https://docs.bazel.build/versions/master/be/make-variables.html">"Make variable"</a> substitution.<br><br>Execpath returns absolute path, and in order to be able to construct the absolute path we need to wrap the test binary in a launcher. Using a launcher comes with complications, such as more complicated debugger attachment.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-linker_script"></a>linker_script</td><td style="text-align: left">Link script to forward into linker via rustc options.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-malloc"></a>malloc</td><td style="text-align: left">Override the default dependency on <code>malloc</code>.<br><br>By default, Rust binaries linked with cc_common.link are linked against <code>@bazel_tools//tools/cpp:malloc"</code>, which is an empty library and the resulting binary will use libc's <code>malloc</code>. This label must refer to a <code>cc_library</code> rule.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@bazel_tools//tools/cpp:malloc"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-out_binary"></a>out_binary</td><td style="text-align: left">Force a target, regardless of it's <code>crate_type</code>, to always mark the file as executable. This attribute is only used to support wasm targets but is expected to be removed following a resolution to https://github.com/bazelbuild/rules_rust/issues/771.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the binary to.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_library"></a></p>
<h2 id="rust_library"><a class="header" href="#rust_library">rust_library</a></h2>
<pre>
rust_library(<a href="rust.html#rust_library-name">name</a>, <a href="rust.html#rust_library-deps">deps</a>, <a href="rust.html#rust_library-srcs">srcs</a>, <a href="rust.html#rust_library-data">data</a>, <a href="rust.html#rust_library-aliases">aliases</a>, <a href="rust.html#rust_library-alwayslink">alwayslink</a>, <a href="rust.html#rust_library-compile_data">compile_data</a>, <a href="rust.html#rust_library-crate_features">crate_features</a>, <a href="rust.html#rust_library-crate_name">crate_name</a>,
<a href="rust.html#rust_library-crate_root">crate_root</a>, <a href="rust.html#rust_library-disable_pipelining">disable_pipelining</a>, <a href="rust.html#rust_library-edition">edition</a>, <a href="rust.html#rust_library-proc_macro_deps">proc_macro_deps</a>, <a href="rust.html#rust_library-rustc_env">rustc_env</a>, <a href="rust.html#rust_library-rustc_env_files">rustc_env_files</a>,
<a href="rust.html#rust_library-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_library-stamp">stamp</a>, <a href="rust.html#rust_library-version">version</a>)
</pre>
<p>Builds a Rust library crate.</p>
<p>Example:</p>
<p>Suppose you have the following directory structure for a simple Rust library crate:</p>
<pre><code class="language-output">[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
greeter.rs
lib.rs
</code></pre>
<p><code>hello_lib/src/greeter.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct Greeter {
greeting: String,
}
impl Greeter {
pub fn new(greeting: &amp;str) -&gt; Greeter {
Greeter { greeting: greeting.to_string(), }
}
pub fn greet(&amp;self, thing: &amp;str) {
println!("{} {}", &amp;self.greeting, thing);
}
}
<span class="boring">}</span></code></pre></pre>
<p><code>hello_lib/src/lib.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub mod greeter;
<span class="boring">}</span></code></pre></pre>
<p><code>hello_lib/BUILD</code>:</p>
<pre><code class="language-python">package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_library")
rust_library(
name = "hello_lib",
srcs = [
"src/greeter.rs",
"src/lib.rs",
],
)
</code></pre>
<p>Build the library:</p>
<pre><code class="language-output">$ bazel build //hello_lib
INFO: Found 1 target...
Target //examples/rust/hello_lib:hello_lib up-to-date:
bazel-bin/examples/rust/hello_lib/libhello_lib.rlib
INFO: Elapsed time: 1.245s, Critical Path: 1.01s
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_library-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-disable_pipelining"></a>disable_pipelining</td><td style="text-align: left">Disables pipelining for this rule if it is globally enabled. This will cause this rule to not produce a <code>.rmeta</code> file and all the dependent crates will instead use the <code>.rlib</code> file.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_library_group"></a></p>
<h2 id="rust_library_group"><a class="header" href="#rust_library_group">rust_library_group</a></h2>
<pre>
rust_library_group(<a href="rust.html#rust_library_group-name">name</a>, <a href="rust.html#rust_library_group-deps">deps</a>)
</pre>
<p>Functions as an alias for a set of dependencies.</p>
<p>Specifically, the following are equivalent:</p>
<pre><code class="language-starlark">rust_library_group(
name = "crate_group",
deps = [
":crate1",
":crate2",
],
)
rust_library(
name = "foobar",
deps = [":crate_group"],
...
)
</code></pre>
<p>and</p>
<pre><code class="language-starlark">rust_library(
name = "foobar",
deps = [
":crate1",
":crate2",
],
...
)
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_library_group-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_library_group-deps"></a>deps</td><td style="text-align: left">Other dependencies to forward through this crate group.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_proc_macro"></a></p>
<h2 id="rust_proc_macro"><a class="header" href="#rust_proc_macro">rust_proc_macro</a></h2>
<pre>
rust_proc_macro(<a href="rust.html#rust_proc_macro-name">name</a>, <a href="rust.html#rust_proc_macro-deps">deps</a>, <a href="rust.html#rust_proc_macro-srcs">srcs</a>, <a href="rust.html#rust_proc_macro-data">data</a>, <a href="rust.html#rust_proc_macro-aliases">aliases</a>, <a href="rust.html#rust_proc_macro-alwayslink">alwayslink</a>, <a href="rust.html#rust_proc_macro-compile_data">compile_data</a>, <a href="rust.html#rust_proc_macro-crate_features">crate_features</a>,
<a href="rust.html#rust_proc_macro-crate_name">crate_name</a>, <a href="rust.html#rust_proc_macro-crate_root">crate_root</a>, <a href="rust.html#rust_proc_macro-edition">edition</a>, <a href="rust.html#rust_proc_macro-proc_macro_deps">proc_macro_deps</a>, <a href="rust.html#rust_proc_macro-rustc_env">rustc_env</a>, <a href="rust.html#rust_proc_macro-rustc_env_files">rustc_env_files</a>,
<a href="rust.html#rust_proc_macro-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_proc_macro-stamp">stamp</a>, <a href="rust.html#rust_proc_macro-version">version</a>)
</pre>
<p>Builds a Rust proc-macro crate.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_proc_macro-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_shared_library"></a></p>
<h2 id="rust_shared_library"><a class="header" href="#rust_shared_library">rust_shared_library</a></h2>
<pre>
rust_shared_library(<a href="rust.html#rust_shared_library-name">name</a>, <a href="rust.html#rust_shared_library-deps">deps</a>, <a href="rust.html#rust_shared_library-srcs">srcs</a>, <a href="rust.html#rust_shared_library-data">data</a>, <a href="rust.html#rust_shared_library-aliases">aliases</a>, <a href="rust.html#rust_shared_library-alwayslink">alwayslink</a>, <a href="rust.html#rust_shared_library-compile_data">compile_data</a>, <a href="rust.html#rust_shared_library-crate_features">crate_features</a>,
<a href="rust.html#rust_shared_library-crate_name">crate_name</a>, <a href="rust.html#rust_shared_library-crate_root">crate_root</a>, <a href="rust.html#rust_shared_library-edition">edition</a>, <a href="rust.html#rust_shared_library-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="rust.html#rust_shared_library-malloc">malloc</a>,
<a href="rust.html#rust_shared_library-platform">platform</a>, <a href="rust.html#rust_shared_library-proc_macro_deps">proc_macro_deps</a>, <a href="rust.html#rust_shared_library-rustc_env">rustc_env</a>, <a href="rust.html#rust_shared_library-rustc_env_files">rustc_env_files</a>, <a href="rust.html#rust_shared_library-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_shared_library-stamp">stamp</a>,
<a href="rust.html#rust_shared_library-version">version</a>)
</pre>
<p>Builds a Rust shared library.</p>
<p>This shared library will contain all transitively reachable crates and native objects.
It is meant to be used when producing an artifact that is then consumed by some other build system
(for example to produce a shared library that Python program links against).</p>
<p>This rule provides CcInfo, so it can be used everywhere Bazel expects <code>rules_cc</code>.</p>
<p>When building the whole binary in Bazel, use <code>rust_library</code> instead.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_shared_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-malloc"></a>malloc</td><td style="text-align: left">Override the default dependency on <code>malloc</code>.<br><br>By default, Rust binaries linked with cc_common.link are linked against <code>@bazel_tools//tools/cpp:malloc"</code>, which is an empty library and the resulting binary will use libc's <code>malloc</code>. This label must refer to a <code>cc_library</code> rule.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@bazel_tools//tools/cpp:malloc"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the shared library to.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_static_library"></a></p>
<h2 id="rust_static_library"><a class="header" href="#rust_static_library">rust_static_library</a></h2>
<pre>
rust_static_library(<a href="rust.html#rust_static_library-name">name</a>, <a href="rust.html#rust_static_library-deps">deps</a>, <a href="rust.html#rust_static_library-srcs">srcs</a>, <a href="rust.html#rust_static_library-data">data</a>, <a href="rust.html#rust_static_library-aliases">aliases</a>, <a href="rust.html#rust_static_library-alwayslink">alwayslink</a>, <a href="rust.html#rust_static_library-compile_data">compile_data</a>, <a href="rust.html#rust_static_library-crate_features">crate_features</a>,
<a href="rust.html#rust_static_library-crate_name">crate_name</a>, <a href="rust.html#rust_static_library-crate_root">crate_root</a>, <a href="rust.html#rust_static_library-edition">edition</a>, <a href="rust.html#rust_static_library-platform">platform</a>, <a href="rust.html#rust_static_library-proc_macro_deps">proc_macro_deps</a>, <a href="rust.html#rust_static_library-rustc_env">rustc_env</a>,
<a href="rust.html#rust_static_library-rustc_env_files">rustc_env_files</a>, <a href="rust.html#rust_static_library-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_static_library-stamp">stamp</a>, <a href="rust.html#rust_static_library-version">version</a>)
</pre>
<p>Builds a Rust static library.</p>
<p>This static library will contain all transitively reachable crates and native objects.
It is meant to be used when producing an artifact that is then consumed by some other build system
(for example to produce an archive that Python program links against).</p>
<p>This rule provides CcInfo, so it can be used everywhere Bazel expects <code>rules_cc</code>.</p>
<p>When building the whole binary in Bazel, use <code>rust_library</code> instead.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_static_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the static library to.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_test"></a></p>
<h2 id="rust_test"><a class="header" href="#rust_test">rust_test</a></h2>
<pre>
rust_test(<a href="rust.html#rust_test-name">name</a>, <a href="rust.html#rust_test-deps">deps</a>, <a href="rust.html#rust_test-srcs">srcs</a>, <a href="rust.html#rust_test-data">data</a>, <a href="rust.html#rust_test-aliases">aliases</a>, <a href="rust.html#rust_test-alwayslink">alwayslink</a>, <a href="rust.html#rust_test-compile_data">compile_data</a>, <a href="rust.html#rust_test-crate">crate</a>, <a href="rust.html#rust_test-crate_features">crate_features</a>,
<a href="rust.html#rust_test-crate_name">crate_name</a>, <a href="rust.html#rust_test-crate_root">crate_root</a>, <a href="rust.html#rust_test-edition">edition</a>, <a href="rust.html#rust_test-env">env</a>, <a href="rust.html#rust_test-env_inherit">env_inherit</a>, <a href="rust.html#rust_test-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="rust.html#rust_test-malloc">malloc</a>,
<a href="rust.html#rust_test-platform">platform</a>, <a href="rust.html#rust_test-proc_macro_deps">proc_macro_deps</a>, <a href="rust.html#rust_test-rustc_env">rustc_env</a>, <a href="rust.html#rust_test-rustc_env_files">rustc_env_files</a>, <a href="rust.html#rust_test-rustc_flags">rustc_flags</a>, <a href="rust.html#rust_test-stamp">stamp</a>,
<a href="rust.html#rust_test-use_libtest_harness">use_libtest_harness</a>, <a href="rust.html#rust_test-version">version</a>)
</pre>
<p>Builds a Rust test crate.</p>
<p>Examples:</p>
<p>Suppose you have the following directory structure for a Rust library crate with unit test code in the library sources:</p>
<pre><code class="language-output">[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
lib.rs
</code></pre>
<p><code>hello_lib/src/lib.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct Greeter {
greeting: String,
}
impl Greeter {
pub fn new(greeting: &amp;str) -&gt; Greeter {
Greeter { greeting: greeting.to_string(), }
}
pub fn greet(&amp;self, thing: &amp;str) -&gt; String {
format!("{} {}", &amp;self.greeting, thing)
}
}
#[cfg(test)]
mod test {
use super::Greeter;
#[test]
fn test_greeting() {
let hello = Greeter::new("Hi");
assert_eq!("Hi Rust", hello.greet("Rust"));
}
}
<span class="boring">}</span></code></pre></pre>
<p>To build and run the tests, simply add a <code>rust_test</code> rule with no <code>srcs</code>
and only depends on the <code>hello_lib</code> <code>rust_library</code> target via the
<code>crate</code> attribute:</p>
<p><code>hello_lib/BUILD</code>:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_test(
name = "hello_lib_test",
crate = ":hello_lib",
# You may add other deps that are specific to the test configuration
deps = ["//some/dev/dep"],
)
</code></pre>
<p>Run the test with <code>bazel test //hello_lib:hello_lib_test</code>.</p>
<h3 id="example-test-directory"><a class="header" href="#example-test-directory">Example: <code>test</code> directory</a></h3>
<p>Integration tests that live in the <a href="http://doc.rust-lang.org/book/testing.html#the-tests-directory"><code>tests</code> directory</a>, they are essentially built as separate crates. Suppose you have the following directory structure where <code>greeting.rs</code> is an integration test for the <code>hello_lib</code> library crate:</p>
<pre><code class="language-output">[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
lib.rs
tests/
greeting.rs
</code></pre>
<p><code>hello_lib/tests/greeting.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>extern crate hello_lib;
use hello_lib;
#[test]
fn test_greeting() {
let hello = greeter::Greeter::new("Hello");
assert_eq!("Hello world", hello.greeting("world"));
}
<span class="boring">}</span></code></pre></pre>
<p>To build the <code>greeting.rs</code> integration test, simply add a <code>rust_test</code> target
with <code>greeting.rs</code> in <code>srcs</code> and a dependency on the <code>hello_lib</code> target:</p>
<p><code>hello_lib/BUILD</code>:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_test(
name = "greeting_test",
srcs = ["tests/greeting.rs"],
deps = [":hello_lib"],
)
</code></pre>
<p>Run the test with <code>bazel test //hello_lib:greeting_test</code>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_test-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_test-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-crate"></a>crate</td><td style="text-align: left">Target inline tests declared in the given crate<br><br>These tests are typically those that would be held out under <code>#[cfg(test)]</code> declarations.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-env"></a>env</td><td style="text-align: left">Specifies additional environment variables to set when the test is executed by bazel test. Values are subject to <code>$(rootpath)</code>, <code>$(execpath)</code>, location, and <a href="https://docs.bazel.build/versions/master/be/make-variables.html">"Make variable"</a> substitution.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-env_inherit"></a>env_inherit</td><td style="text-align: left">Specifies additional environment variables to inherit from the external environment when the test is executed by bazel test.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-malloc"></a>malloc</td><td style="text-align: left">Override the default dependency on <code>malloc</code>.<br><br>By default, Rust binaries linked with cc_common.link are linked against <code>@bazel_tools//tools/cpp:malloc"</code>, which is an empty library and the resulting binary will use libc's <code>malloc</code>. This label must refer to a <code>cc_library</code> rule.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@bazel_tools//tools/cpp:malloc"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the test to.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-use_libtest_harness"></a>use_libtest_harness</td><td style="text-align: left">Whether to use <code>libtest</code>. For targets using this flag, individual tests can be run by using the <a href="https://docs.bazel.build/versions/4.0.0/command-line-reference.html#flag--test_arg">--test_arg</a> flag. E.g. <code>bazel test //src:rust_test --test_arg=foo::test::test_fn</code>.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_test_suite"></a></p>
<h2 id="rust_test_suite"><a class="header" href="#rust_test_suite">rust_test_suite</a></h2>
<pre>
rust_test_suite(<a href="rust.html#rust_test_suite-name">name</a>, <a href="rust.html#rust_test_suite-srcs">srcs</a>, <a href="rust.html#rust_test_suite-shared_srcs">shared_srcs</a>, <a href="rust.html#rust_test_suite-kwargs">kwargs</a>)
</pre>
<p>A rule for creating a test suite for a set of <code>rust_test</code> targets.</p>
<p>This rule can be used for setting up typical rust <a href="https://doc.rust-lang.org/rust-by-example/testing/integration_testing.html">integration tests</a>. Given the following
directory structure:</p>
<pre><code class="language-text">[crate]/
BUILD.bazel
src/
lib.rs
main.rs
tests/
integrated_test_a.rs
integrated_test_b.rs
integrated_test_c.rs
patterns/
fibonacci_test.rs
helpers/
mod.rs
</code></pre>
<p>The rule can be used to generate <a href="rust.html#rust_test">rust_test</a> targets for each source file under <code>tests</code>
and a <a href="https://docs.bazel.build/versions/master/be/general.html#test_suite">test_suite</a> which encapsulates all tests.</p>
<pre><code class="language-python">load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test_suite")
rust_library(
name = "math_lib",
srcs = ["src/lib.rs"],
)
rust_binary(
name = "math_bin",
srcs = ["src/main.rs"],
)
rust_test_suite(
name = "integrated_tests_suite",
srcs = glob(["tests/**"]),
shared_srcs=glob(["tests/helpers/**"]),
deps = [":math_lib"],
)
</code></pre>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_test_suite-name"></a>name</td><td style="text-align: left">The name of the <code>test_suite</code>.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_test_suite-srcs"></a>srcs</td><td style="text-align: left">All test sources, typically <code>glob(["tests/**/*.rs"])</code>.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_test_suite-shared_srcs"></a>shared_srcs</td><td style="text-align: left">Optional argument for sources shared among tests, typically helper functions.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test_suite-kwargs"></a>kwargs</td><td style="text-align: left">Additional keyword arguments for the underyling <a href="rust.html#rust_test">rust_test</a> targets. The <code>tags</code> argument is also passed to the generated <code>test_suite</code> target.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="rust-doc"><a class="header" href="#rust-doc">Rust Doc</a></h1>
<ul>
<li><a href="rust_doc.html#rust_doc">rust_doc</a></li>
<li><a href="rust_doc.html#rust_doc_test">rust_doc_test</a></li>
</ul>
<p><a id="rust_doc"></a></p>
<h2 id="rust_doc"><a class="header" href="#rust_doc">rust_doc</a></h2>
<pre>
rust_doc(<a href="rust_doc.html#rust_doc-name">name</a>, <a href="rust_doc.html#rust_doc-crate">crate</a>, <a href="rust_doc.html#rust_doc-html_after_content">html_after_content</a>, <a href="rust_doc.html#rust_doc-html_before_content">html_before_content</a>, <a href="rust_doc.html#rust_doc-html_in_header">html_in_header</a>, <a href="rust_doc.html#rust_doc-markdown_css">markdown_css</a>,
<a href="rust_doc.html#rust_doc-rustc_flags">rustc_flags</a>, <a href="rust_doc.html#rust_doc-rustdoc_flags">rustdoc_flags</a>)
</pre>
<p>Generates code documentation.</p>
<p>Example:
Suppose you have the following directory structure for a Rust library crate:</p>
<pre><code>[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
lib.rs
</code></pre>
<p>To build <a href="https://doc.rust-lang.org/book/documentation.html"><code>rustdoc</code></a> documentation for the <code>hello_lib</code> crate, define a <code>rust_doc</code> rule that depends on the the <code>hello_lib</code> <code>rust_library</code> target:</p>
<pre><code class="language-python">package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_doc(
name = "hello_lib_doc",
crate = ":hello_lib",
)
</code></pre>
<p>Running <code>bazel build //hello_lib:hello_lib_doc</code> will build a zip file containing the documentation for the <code>hello_lib</code> library crate generated by <code>rustdoc</code>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_doc-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-crate"></a>crate</td><td style="text-align: left">The label of the target to generate code documentation for.<br><br><code>rust_doc</code> can generate HTML code documentation for the source files of <code>rust_library</code> or <code>rust_binary</code> targets.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-html_after_content"></a>html_after_content</td><td style="text-align: left">File to add in <code>&lt;body&gt;</code>, after content.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-html_before_content"></a>html_before_content</td><td style="text-align: left">File to add in <code>&lt;body&gt;</code>, before content.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-html_in_header"></a>html_in_header</td><td style="text-align: left">File to add to <code>&lt;head&gt;</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-markdown_css"></a>markdown_css</td><td style="text-align: left">CSS files to include via <code>&lt;link&gt;</code> in a rendered Markdown file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-rustc_flags"></a>rustc_flags</td><td style="text-align: left"><strong>Deprecated</strong>: use <code>rustdoc_flags</code> instead</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-rustdoc_flags"></a>rustdoc_flags</td><td style="text-align: left">List of flags passed to <code>rustdoc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_doc_test"></a></p>
<h2 id="rust_doc_test"><a class="header" href="#rust_doc_test">rust_doc_test</a></h2>
<pre>
rust_doc_test(<a href="rust_doc.html#rust_doc_test-name">name</a>, <a href="rust_doc.html#rust_doc_test-deps">deps</a>, <a href="rust_doc.html#rust_doc_test-crate">crate</a>, <a href="rust_doc.html#rust_doc_test-proc_macro_deps">proc_macro_deps</a>)
</pre>
<p>Runs Rust documentation tests.</p>
<p>Example:</p>
<p>Suppose you have the following directory structure for a Rust library crate:</p>
<pre><code class="language-output">[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
lib.rs
</code></pre>
<p>To run <a href="https://doc.rust-lang.org/book/documentation.html#documentation-as-tests">documentation tests</a> for the <code>hello_lib</code> crate, define a <code>rust_doc_test</code> target that depends on the <code>hello_lib</code> <code>rust_library</code> target:</p>
<pre><code class="language-python">package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_doc_test(
name = "hello_lib_doc_test",
crate = ":hello_lib",
)
</code></pre>
<p>Running <code>bazel test //hello_lib:hello_lib_doc_test</code> will run all documentation tests for the <code>hello_lib</code> library crate.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_doc_test-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_doc_test-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc_test-crate"></a>crate</td><td style="text-align: left">The label of the target to generate code documentation for. <code>rust_doc_test</code> can generate HTML code documentation for the source files of <code>rust_library</code> or <code>rust_binary</code> targets.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_doc_test-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="rust-clippy"><a class="header" href="#rust-clippy">Rust Clippy</a></h1>
<ul>
<li><a href="rust_clippy.html#rust_clippy">rust_clippy</a></li>
<li><a href="rust_clippy.html#rust_clippy_aspect">rust_clippy_aspect</a></li>
</ul>
<h2 id="overview"><a class="header" href="#overview">Overview</a></h2>
<p><a href="https://github.com/rust-lang/rust-clippy#readme">Clippy</a> is a tool for catching common mistakes in Rust code and improving it. An
expansive list of lints and the justification can be found in their <a href="https://rust-lang.github.io/rust-clippy/">documentation</a>.</p>
<h3 id="setup-1"><a class="header" href="#setup-1">Setup</a></h3>
<p>Simply add the following to the <code>.bazelrc</code> file in the root of your workspace:</p>
<pre><code class="language-text">build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
build --output_groups=+clippy_checks
</code></pre>
<p>This will enable clippy on all <a href="./defs.html">Rust targets</a>.</p>
<p>Note that targets tagged with <code>no-clippy</code> will not perform clippy checks</p>
<p>To use a local clippy.toml, add the following flag to your <code>.bazelrc</code>. Note that due to
the upstream implementation of clippy, this file must be named either <code>.clippy.toml</code> or
<code>clippy.toml</code>. Using a custom config file requires Rust 1.34.0 or newer.</p>
<pre><code class="language-text">build --@rules_rust//:clippy.toml=//:clippy.toml
</code></pre>
<p><a id="rust_clippy"></a></p>
<h2 id="rust_clippy"><a class="header" href="#rust_clippy">rust_clippy</a></h2>
<pre>
rust_clippy(<a href="rust_clippy.html#rust_clippy-name">name</a>, <a href="rust_clippy.html#rust_clippy-deps">deps</a>)
</pre>
<p>Executes the clippy checker on a specific target.</p>
<p>Similar to <code>rust_clippy_aspect</code>, but allows specifying a list of dependencies within the build system.</p>
<p>For example, given the following example targets:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_test(
name = "greeting_test",
srcs = ["tests/greeting.rs"],
deps = [":hello_lib"],
)
</code></pre>
<p>Rust clippy can be set as a build target with the following:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_clippy")
rust_clippy(
name = "hello_library_clippy",
testonly = True,
deps = [
":hello_lib",
":greeting_test",
],
)
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_clippy-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_clippy-deps"></a>deps</td><td style="text-align: left">Rust targets to run clippy on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_clippy_aspect"></a></p>
<h2 id="rust_clippy_aspect"><a class="header" href="#rust_clippy_aspect">rust_clippy_aspect</a></h2>
<pre>
rust_clippy_aspect(<a href="rust_clippy.html#rust_clippy_aspect-name">name</a>)
</pre>
<p>Executes the clippy checker on specified targets.</p>
<p>This aspect applies to existing rust_library, rust_test, and rust_binary rules.</p>
<p>As an example, if the following is defined in <code>examples/hello_lib/BUILD.bazel</code>:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_test(
name = "greeting_test",
srcs = ["tests/greeting.rs"],
deps = [":hello_lib"],
)
</code></pre>
<p>Then the targets can be analyzed with clippy using the following command:</p>
<pre><code class="language-output">$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks //hello_lib:all
</code></pre>
<p><strong>ASPECT ATTRIBUTES</strong></p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_clippy_aspect-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="rust-fmt"><a class="header" href="#rust-fmt">Rust Fmt</a></h1>
<ul>
<li><a href="rust_fmt.html#rustfmt_aspect">rustfmt_aspect</a></li>
<li><a href="rust_fmt.html#rustfmt_test">rustfmt_test</a></li>
<li><a href="rust_fmt.html#rustfmt_toolchain">rustfmt_toolchain</a></li>
</ul>
<h2 id="overview-1"><a class="header" href="#overview-1">Overview</a></h2>
<p><a href="https://github.com/rust-lang/rustfmt#readme">Rustfmt</a> is a tool for formatting Rust code according to style guidelines.
By default, Rustfmt uses a style which conforms to the <a href="https://github.com/rust-lang-nursery/fmt-rfcs/blob/master/guide/guide.md">Rust style guide</a> that
has been formalized through the <a href="https://github.com/rust-lang-nursery/fmt-rfcs">style RFC process</a>. A complete list of all
configuration options can be found in the <a href="https://rust-lang.github.io/rustfmt/">Rustfmt GitHub Pages</a>.</p>
<h3 id="setup-2"><a class="header" href="#setup-2">Setup</a></h3>
<p>Formatting your Rust targets' source code requires no setup outside of loading <code>rules_rust</code>
in your workspace. Simply run <code>bazel run @rules_rust//:rustfmt</code> to format source code.</p>
<p>In addition to this formatter, a simple check can be performed using the <a href="rust_fmt.html#rustfmt-aspect">rustfmt_aspect</a> aspect by running</p>
<pre><code class="language-text">bazel build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect --output_groups=rustfmt_checks
</code></pre>
<p>Add the following to a <code>.bazelrc</code> file to enable this check during the build phase.</p>
<pre><code class="language-text">build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build --output_groups=+rustfmt_checks
</code></pre>
<p>It's recommended to only enable this aspect in your CI environment so formatting issues do not
impact user's ability to rapidly iterate on changes.</p>
<p>The <code>rustfmt_aspect</code> also uses a <code>--@rules_rust//:rustfmt.toml</code> setting which determines the
<a href="https://rust-lang.github.io/rustfmt/">configuration file</a> used by the formatter (<code>@rules_rust//tools/rustfmt</code>) and the aspect
(<code>rustfmt_aspect</code>). This flag can be added to your <code>.bazelrc</code> file to ensure a consistent config
file is used whenever <code>rustfmt</code> is run:</p>
<pre><code class="language-text">build --@rules_rust//:rustfmt.toml=//:rustfmt.toml
</code></pre>
<h3 id="tips"><a class="header" href="#tips">Tips</a></h3>
<p>Any target which uses Bazel generated sources will cause the <code>@rules_rust//tools/rustfmt</code> tool to fail with
<code>failed to resolve mod `MOD` </code>. To avoid failures, <a href="https://rust-lang.github.io/rustfmt/?version=v1.6.0&amp;search=skip_chil#skip_children"><code>skip_children = true</code></a>
is recommended to be set in the workspace's <code>rustfmt.toml</code> file which allows rustfmt to run on these targets
without failing.</p>
<p><a id="rustfmt_test"></a></p>
<h2 id="rustfmt_test"><a class="header" href="#rustfmt_test">rustfmt_test</a></h2>
<pre>
rustfmt_test(<a href="rust_fmt.html#rustfmt_test-name">name</a>, <a href="rust_fmt.html#rustfmt_test-targets">targets</a>)
</pre>
<p>A test rule for performing <code>rustfmt --check</code> on a set of targets</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rustfmt_test-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rustfmt_test-targets"></a>targets</td><td style="text-align: left">Rust targets to run <code>rustfmt --check</code> on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rustfmt_toolchain"></a></p>
<h2 id="rustfmt_toolchain"><a class="header" href="#rustfmt_toolchain">rustfmt_toolchain</a></h2>
<pre>
rustfmt_toolchain(<a href="rust_fmt.html#rustfmt_toolchain-name">name</a>, <a href="rust_fmt.html#rustfmt_toolchain-rustc">rustc</a>, <a href="rust_fmt.html#rustfmt_toolchain-rustc_lib">rustc_lib</a>, <a href="rust_fmt.html#rustfmt_toolchain-rustfmt">rustfmt</a>)
</pre>
<p>A toolchain for <a href="https://rust-lang.github.io/rustfmt/">rustfmt</a></p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rustfmt_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rustfmt_toolchain-rustc"></a>rustc</td><td style="text-align: left">The location of the <code>rustc</code> binary. Can be a direct source or a filegroup containing one item.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rustfmt_toolchain-rustc_lib"></a>rustc_lib</td><td style="text-align: left">The libraries used by rustc during compilation.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rustfmt_toolchain-rustfmt"></a>rustfmt</td><td style="text-align: left">The location of the <code>rustfmt</code> binary. Can be a direct source or a filegroup containing one item.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rustfmt_aspect"></a></p>
<h2 id="rustfmt_aspect"><a class="header" href="#rustfmt_aspect">rustfmt_aspect</a></h2>
<pre>
rustfmt_aspect(<a href="rust_fmt.html#rustfmt_aspect-name">name</a>)
</pre>
<p>This aspect is used to gather information about a crate for use in rustfmt and perform rustfmt checks</p>
<p>Output Groups:</p>
<ul>
<li><code>rustfmt_checks</code>: Executes <code>rustfmt --check</code> on the specified target.</li>
</ul>
<p>The build setting <code>@rules_rust//:rustfmt.toml</code> is used to control the Rustfmt <a href="https://rust-lang.github.io/rustfmt/">configuration settings</a>
used at runtime.</p>
<p>This aspect is executed on any target which provides the <code>CrateInfo</code> provider. However
users may tag a target with <code>no-rustfmt</code> or <code>no-format</code> to have it skipped. Additionally,
generated source files are also ignored by this aspect.</p>
<p><strong>ASPECT ATTRIBUTES</strong></p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rustfmt_aspect-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="rust-proto"><a class="header" href="#rust-proto">Rust Proto</a></h1>
<ul>
<li><a href="rust_proto.html#rust_prost_library">rust_prost_library</a></li>
<li><a href="rust_proto.html#rust_prost_toolchain">rust_prost_toolchain</a></li>
<li><a href="rust_proto.html#rust_prost_dependencies">rust_prost_dependencies</a></li>
<li><a href="rust_proto.html#rust_prost_transitive_repositories">rust_prost_transitive_repositories</a></li>
<li><a href="rust_proto.html#rust_proto_library">rust_proto_library</a></li>
<li><a href="rust_proto.html#rust_grpc_library">rust_grpc_library</a></li>
<li><a href="rust_proto.html#rust_proto_protobuf_toolchain">rust_proto_protobuf_toolchain</a></li>
<li><a href="rust_proto.html#rust_proto_protobuf_dependencies">rust_proto_protobuf_dependencies</a></li>
<li><a href="rust_proto.html#rust_proto_protobuf_register_toolchains">rust_proto_protobuf_register_toolchains</a></li>
<li><a href="rust_proto.html#rust_proto_protobuf_transitive_repositories">rust_proto_protobuf_transitive_repositories</a></li>
</ul>
<h2 id="overview-2"><a class="header" href="#overview-2">Overview</a></h2>
<p>These build rules are used for building <a href="https://developers.google.com/protocol-buffers/">protobufs</a>/<a href="https://grpc.io">gRPC</a> in <a href="http://www.rust-lang.org/">Rust</a> with Bazel.</p>
<p>There are two rule sets. The first ruleset defines the <code>rust_prost_library</code> which generates Rust code
using the <a href="https://crates.io/crates/prost"><code>prost</code></a> and <a href="https://crates.io/crates/tonic"><code>tonic</code></a> dependencies. The second ruleset defines the <code>rust_proto_library</code> and
<code>rust_grpc_library</code> rules which generate Rust code using the <a href="https://github.com/stepancheg/rust-protobuf/"><code>rust-protobuf</code></a> dependencies.</p>
<p>See the <a href="../examples/proto">protobuf example</a> for a more complete example of use.</p>
<h3 id="prost-setup"><a class="header" href="#prost-setup">Prost Setup</a></h3>
<pre><code class="language-python">load("@rules_rust//proto/prost:repositories.bzl", "rust_prost_dependencies")
rust_prost_dependencies()
load("@rules_rust//proto/prost:transitive_repositories.bzl", "rust_prost_transitive_repositories")
rust_prost_transitive_repositories()
</code></pre>
<p>The <code>prost</code> and <code>tonic</code> rules do not specify a default toolchain in order to avoid mismatched
dependency issues. To setup the <code>prost</code> and <code>tonic</code> toolchain, please see the section
<a href="rust_proto.html#custom-prost-deps">Customizing <code>prost</code> and <code>tonic</code> Dependencies</a>.</p>
<p>For additional information about Bazel toolchains, see <a href="https://docs.bazel.build/versions/master/toolchains.html">here</a>.</p>
<h4 id="customizing-prost-and-tonic-dependencies"><a class="header" href="#customizing-prost-and-tonic-dependencies"><a name="custom-prost-deps">Customizing <code>prost</code> and <code>tonic</code> Dependencies</a></h4>
<p>These rules depend on the <a href="https://crates.io/crates/prost"><code>prost</code></a> and <a href="https://crates.io/crates/tonic"><code>tonic</code></a> dependencies. To setup the necessary toolchain
for these rules, you must define a toolchain with the <a href="https://crates.io/crates/prost"><code>prost</code></a>, <a href="https://crates.io/crates/prost-types"><code>prost-types</code></a>, <a href="https://crates.io/crates/tonic"><code>tonic</code></a>, <a href="https://crates.io/crates/protoc-gen-prost"><code>protoc-gen-prost</code></a>, and <a href="https://crates.io/crates/protoc-gen-tonic"><code>protoc-gen-tonic</code></a> crates as well as the <a href="https://github.com/protocolbuffers/protobuf"><code>protoc</code></a> binary.</p>
<p>To get access to these crates, you can use the <a href="./crate_universe.html">crate_universe</a> repository
rules. For example:</p>
<pre><code class="language-python">load("//crate_universe:defs.bzl", "crate", "crates_repository")
crates_repository(
name = "crates_io",
annotations = {
"protoc-gen-prost": [crate.annotation(
gen_binaries = ["protoc-gen-prost"],
patch_args = [
"-p1",
],
patches = [
# Note: You will need to use this patch until a version greater than `0.2.2` of
# `protoc-gen-prost` is released.
"@rules_rust//proto/prost/private/3rdparty/patches:protoc-gen-prost.patch",
],
)],
"protoc-gen-tonic": [crate.annotation(
gen_binaries = ["protoc-gen-tonic"],
)],
},
cargo_lockfile = "Cargo.Bazel.lock",
mode = "remote",
packages = {
"prost": crate.spec(
version = "0",
),
"prost-types": crate.spec(
version = "0",
),
"protoc-gen-prost": crate.spec(
version = "0",
),
"protoc-gen-tonic": crate.spec(
version = "0",
),
"tonic": crate.spec(
version = "0",
),
},
repository_name = "rules_rust_prost",
tags = ["manual"],
)
</code></pre>
<p>You can then define a toolchain with the <code>rust_prost_toolchain</code> rule which uses the crates
defined above. For example:</p>
<pre><code class="language-python">load("@rules_rust//proto/prost:defs.bzl", "rust_prost_toolchain")
load("@rules_rust//rust:defs.bzl", "rust_library_group")
rust_library_group(
name = "prost_runtime",
deps = [
"@crates_io//:prost",
],
)
rust_library_group(
name = "tonic_runtime",
deps = [
":prost_runtime",
"@crates_io//:tonic",
],
)
rust_prost_toolchain(
name = "prost_toolchain_impl",
prost_plugin = "@crates_io//:protoc-gen-prost__protoc-gen-prost",
prost_runtime = ":prost_runtime",
prost_types = "@crates_io//:prost-types",
proto_compiler = "@com_google_protobuf//:protoc",
tonic_plugin = "@crates_io//:protoc-gen-tonic__protoc-gen-tonic",
tonic_runtime = ":tonic_runtime",
)
toolchain(
name = "prost_toolchain",
toolchain = "prost_toolchain_impl",
toolchain_type = "@rules_rust//proto/prost:toolchain_type",
)
</code></pre>
<p>Lastly, you must register the toolchain in your <code>WORKSPACE</code> file. For example:</p>
<pre><code class="language-python">register_toolchains("//toolchains:prost_toolchain")
</code></pre>
<h2 id="rust-protobuf-setup"><a class="header" href="#rust-protobuf-setup">Rust-Protobuf Setup</a></h2>
<p>To use the Rust proto rules, add the following to your <code>WORKSPACE</code> file to add the
external repositories for the Rust proto toolchain (in addition to the <a href="..">rust rules setup</a>):</p>
<pre><code class="language-python">load("@rules_rust//proto/protobuf:repositories.bzl", "rust_proto_protobuf_dependencies", "rust_proto_protobuf_register_toolchains")
rust_proto_protobuf_dependencies()
rust_proto_protobuf_register_toolchains()
load("@rules_rust//proto/protobuf:transitive_repositories.bzl", "rust_proto_protobuf_transitive_repositories")
rust_proto_protobuf_transitive_repositories()
</code></pre>
<p>This will load the required dependencies for the <a href="https://github.com/stepancheg/rust-protobuf/"><code>rust-protobuf</code></a> rules. It will also
register a default toolchain for the <code>rust_proto_library</code> and <code>rust_grpc_library</code> rules.</p>
<p>To customize the <code>rust_proto_library</code> and <code>rust_grpc_library</code> toolchain, please see the section
<a href="rust_proto.html#custom-proto-deps">Customizing <code>rust-protobuf</code> Dependencies</a>.</p>
<p>For additional information about Bazel toolchains, see <a href="https://docs.bazel.build/versions/master/toolchains.html">here</a>.</p>
<h4 id="customizing-rust-protobuf-dependencies"><a class="header" href="#customizing-rust-protobuf-dependencies"><a name="custom-proto-deps">Customizing <code>rust-protobuf</code> Dependencies</a></h4>
<p>These rules depend on the <a href="https://crates.io/crates/protobuf"><code>protobuf</code></a> and
the <a href="https://crates.io/crates/grpc"><code>grpc</code></a> crates in addition to the <a href="https://github.com/google/protobuf">protobuf
compiler</a>. To obtain these crates,
<code>rust_proto_repositories</code> imports the given crates using BUILD files generated with
<a href="./crate_universe.html">crate_universe</a>.</p>
<p>If you want to either change the protobuf and gRPC rust compilers, or to
simply use <a href="./crate_universe.html">crate_universe</a> in a more
complex scenario (with more dependencies), you must redefine those
dependencies.</p>
<p>To do this, once you've imported the needed dependencies (see our
<a href="https://github.com/bazelbuild/rules_rust/blob/main/proto/protobuf/3rdparty/BUILD.bazel">@rules_rust//proto/protobuf/3rdparty/BUILD.bazel</a>
file to see the default dependencies), you need to create your own toolchain.
To do so you can create a BUILD file with your toolchain definition, for example:</p>
<pre><code class="language-python">load("@rules_rust//proto:toolchain.bzl", "rust_proto_toolchain")
rust_proto_toolchain(
name = "proto-toolchain-impl",
# Path to the protobuf compiler.
protoc = "@com_google_protobuf//:protoc",
# Protobuf compiler plugin to generate rust gRPC stubs.
grpc_plugin = "//3rdparty/crates:cargo_bin_protoc_gen_rust_grpc",
# Protobuf compiler plugin to generate rust protobuf stubs.
proto_plugin = "//3rdparty/crates:cargo_bin_protoc_gen_rust",
)
toolchain(
name = "proto-toolchain",
toolchain = ":proto-toolchain-impl",
toolchain_type = "@rules_rust//proto/protobuf:toolchain_type",
)
</code></pre>
<p>Now that you have your own toolchain, you need to register it by
inserting the following statement in your <code>WORKSPACE</code> file:</p>
<pre><code class="language-python">register_toolchains("//my/toolchains:proto-toolchain")
</code></pre>
<p>Finally, you might want to set the <code>rust_deps</code> attribute in
<code>rust_proto_library</code> and <code>rust_grpc_library</code> to change the compile-time
dependencies:</p>
<pre><code class="language-python">rust_proto_library(
...
rust_deps = ["//3rdparty/crates:protobuf"],
...
)
rust_grpc_library(
...
rust_deps = [
"//3rdparty/crates:protobuf",
"//3rdparty/crates:grpc",
"//3rdparty/crates:tls_api",
"//3rdparty/crates:tls_api_stub",
],
...
)
</code></pre>
<p><strong>Note</strong>: Ideally, we would inject those dependencies from the toolchain,
but due to <a href="https://github.com/bazelbuild/bazel/issues/6889">bazelbuild/bazel#6889</a>
all dependencies added via the toolchain ends-up being in the wrong
configuration.</p>
<hr />
<hr />
<p><a id="rust_grpc_library"></a></p>
<h2 id="rust_grpc_library"><a class="header" href="#rust_grpc_library">rust_grpc_library</a></h2>
<pre>
rust_grpc_library(<a href="rust_proto.html#rust_grpc_library-name">name</a>, <a href="rust_proto.html#rust_grpc_library-deps">deps</a>, <a href="rust_proto.html#rust_grpc_library-crate_name">crate_name</a>, <a href="rust_proto.html#rust_grpc_library-rust_deps">rust_deps</a>, <a href="rust_proto.html#rust_grpc_library-rustc_flags">rustc_flags</a>)
</pre>
<p>Builds a Rust library crate from a set of <code>proto_library</code>s suitable for gRPC.</p>
<p>Example:</p>
<pre><code class="language-python">load("@rules_rust//proto/protobuf:defs.bzl", "rust_grpc_library")
proto_library(
name = "my_proto",
srcs = ["my.proto"]
)
rust_grpc_library(
name = "rust",
deps = [":my_proto"],
)
rust_binary(
name = "my_service",
srcs = ["my_service.rs"],
deps = [":rust"],
)
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_grpc_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_grpc_library-deps"></a>deps</td><td style="text-align: left">List of proto_library dependencies that will be built. One crate for each proto_library will be created with the corresponding gRPC stubs.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_grpc_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_grpc_library-rust_deps"></a>rust_deps</td><td style="text-align: left">The crates the generated library depends on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_grpc_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_prost_toolchain"></a></p>
<h2 id="rust_prost_toolchain"><a class="header" href="#rust_prost_toolchain">rust_prost_toolchain</a></h2>
<pre>
rust_prost_toolchain(<a href="rust_proto.html#rust_prost_toolchain-name">name</a>, <a href="rust_proto.html#rust_prost_toolchain-include_transitive_deps">include_transitive_deps</a>, <a href="rust_proto.html#rust_prost_toolchain-prost_opts">prost_opts</a>, <a href="rust_proto.html#rust_prost_toolchain-prost_plugin">prost_plugin</a>, <a href="rust_proto.html#rust_prost_toolchain-prost_plugin_flag">prost_plugin_flag</a>,
<a href="rust_proto.html#rust_prost_toolchain-prost_runtime">prost_runtime</a>, <a href="rust_proto.html#rust_prost_toolchain-prost_types">prost_types</a>, <a href="rust_proto.html#rust_prost_toolchain-proto_compiler">proto_compiler</a>, <a href="rust_proto.html#rust_prost_toolchain-tonic_opts">tonic_opts</a>, <a href="rust_proto.html#rust_prost_toolchain-tonic_plugin">tonic_plugin</a>,
<a href="rust_proto.html#rust_prost_toolchain-tonic_plugin_flag">tonic_plugin_flag</a>, <a href="rust_proto.html#rust_prost_toolchain-tonic_runtime">tonic_runtime</a>)
</pre>
<p>Rust Prost toolchain rule.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-include_transitive_deps"></a>include_transitive_deps</td><td style="text-align: left">Whether to include transitive dependencies. If set to True, all transitive dependencies will directly accessible by the dependent crate.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_opts"></a>prost_opts</td><td style="text-align: left">Additional options to add to Prost.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_plugin"></a>prost_plugin</td><td style="text-align: left">Additional plugins to add to Prost.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_plugin_flag"></a>prost_plugin_flag</td><td style="text-align: left">Prost plugin flag format. (e.g. <code>--plugin=protoc-gen-prost=%s</code>)</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"--plugin=protoc-gen-prost=%s"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_runtime"></a>prost_runtime</td><td style="text-align: left">The Prost runtime crates to use.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_types"></a>prost_types</td><td style="text-align: left">The Prost types crates to use.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-proto_compiler"></a>proto_compiler</td><td style="text-align: left">The protoc compiler to use. Note that this attribute is deprecated - prefer to use --incompatible_enable_proto_toolchain_resolution.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_opts"></a>tonic_opts</td><td style="text-align: left">Additional options to add to Tonic.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_plugin"></a>tonic_plugin</td><td style="text-align: left">Additional plugins to add to Tonic.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_plugin_flag"></a>tonic_plugin_flag</td><td style="text-align: left">Tonic plugin flag format. (e.g. <code>--plugin=protoc-gen-tonic=%s</code>))</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"--plugin=protoc-gen-tonic=%s"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_runtime"></a>tonic_runtime</td><td style="text-align: left">The Tonic runtime crates to use.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_proto_library"></a></p>
<h2 id="rust_proto_library"><a class="header" href="#rust_proto_library">rust_proto_library</a></h2>
<pre>
rust_proto_library(<a href="rust_proto.html#rust_proto_library-name">name</a>, <a href="rust_proto.html#rust_proto_library-deps">deps</a>, <a href="rust_proto.html#rust_proto_library-crate_name">crate_name</a>, <a href="rust_proto.html#rust_proto_library-rust_deps">rust_deps</a>, <a href="rust_proto.html#rust_proto_library-rustc_flags">rustc_flags</a>)
</pre>
<p>Builds a Rust library crate from a set of <code>proto_library</code>s.</p>
<p>Example:</p>
<pre><code class="language-python">load("@rules_rust//proto/protobuf:defs.bzl", "rust_proto_library")
proto_library(
name = "my_proto",
srcs = ["my.proto"]
)
rust_proto_library(
name = "rust",
deps = [":my_proto"],
)
rust_binary(
name = "my_proto_binary",
srcs = ["my_proto_binary.rs"],
deps = [":rust"],
)
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_proto_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_proto_library-deps"></a>deps</td><td style="text-align: left">List of proto_library dependencies that will be built. One crate for each proto_library will be created with the corresponding stubs.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_proto_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proto_library-rust_deps"></a>rust_deps</td><td style="text-align: left">The crates the generated library depends on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proto_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_prost_dependencies"></a></p>
<h2 id="rust_prost_dependencies"><a class="header" href="#rust_prost_dependencies">rust_prost_dependencies</a></h2>
<pre>
rust_prost_dependencies(<a href="rust_proto.html#rust_prost_dependencies-bzlmod">bzlmod</a>)
</pre>
<p>Declares repositories needed for prost.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_prost_dependencies-bzlmod"></a>bzlmod</td><td style="text-align: left">Whether bzlmod is enabled.</td><td style="text-align: left"><code>False</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories
defined by this macro.</p>
<p><a id="rust_prost_library"></a></p>
<h2 id="rust_prost_library"><a class="header" href="#rust_prost_library">rust_prost_library</a></h2>
<pre>
rust_prost_library(<a href="rust_proto.html#rust_prost_library-name">name</a>, <a href="rust_proto.html#rust_prost_library-kwargs">kwargs</a>)
</pre>
<p>A rule for generating a Rust library using Prost.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_prost_library-name"></a>name</td><td style="text-align: left">The name of the target.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_prost_library-kwargs"></a>kwargs</td><td style="text-align: left">Additional keyword arguments for the underlying <code>rust_prost_library</code> rule.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><a id="rust_prost_transitive_repositories"></a></p>
<h2 id="rust_prost_transitive_repositories"><a class="header" href="#rust_prost_transitive_repositories">rust_prost_transitive_repositories</a></h2>
<pre>
rust_prost_transitive_repositories()
</pre>
<p>Load transitive dependencies of the <code>@rules_rust//proto/protobuf</code> rules.</p>
<p>This macro should be called immediately after the <code>rust_protobuf_dependencies</code> macro.</p>
<p><a id="rust_proto_protobuf_dependencies"></a></p>
<h2 id="rust_proto_protobuf_dependencies"><a class="header" href="#rust_proto_protobuf_dependencies">rust_proto_protobuf_dependencies</a></h2>
<pre>
rust_proto_protobuf_dependencies(<a href="rust_proto.html#rust_proto_protobuf_dependencies-bzlmod">bzlmod</a>)
</pre>
<p>Sets up dependencies for rules_rust's proto support.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_proto_protobuf_dependencies-bzlmod"></a>bzlmod</td><td style="text-align: left">Whether this function is being called from a bzlmod context rather than a workspace context.</td><td style="text-align: left"><code>False</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>A list of structs containing information about root module deps to report to bzlmod's extension_metadata.</p>
<p><a id="rust_proto_protobuf_register_toolchains"></a></p>
<h2 id="rust_proto_protobuf_register_toolchains"><a class="header" href="#rust_proto_protobuf_register_toolchains">rust_proto_protobuf_register_toolchains</a></h2>
<pre>
rust_proto_protobuf_register_toolchains(<a href="rust_proto.html#rust_proto_protobuf_register_toolchains-register_toolchains">register_toolchains</a>)
</pre>
<p>Register toolchains for proto compilation.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_proto_protobuf_register_toolchains-register_toolchains"></a>register_toolchains</td><td style="text-align: left"><p align="center"> - </p></td><td style="text-align: left"><code>True</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_proto_protobuf_transitive_repositories"></a></p>
<h2 id="rust_proto_protobuf_transitive_repositories"><a class="header" href="#rust_proto_protobuf_transitive_repositories">rust_proto_protobuf_transitive_repositories</a></h2>
<pre>
rust_proto_protobuf_transitive_repositories()
</pre>
<p>Load transitive dependencies of the <code>@rules_rust//proto/protobuf</code> rules.</p>
<p>This macro should be called immediately after the <code>rust_protobuf_dependencies</code> macro.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="rust-bindgen"><a class="header" href="#rust-bindgen">Rust Bindgen</a></h1>
<ul>
<li><a href="rust_bindgen.html#rust_bindgen_library">rust_bindgen_library</a></li>
<li><a href="rust_bindgen.html#rust_bindgen">rust_bindgen</a></li>
<li><a href="rust_bindgen.html#rust_bindgen_toolchain">rust_bindgen_toolchain</a></li>
<li><a href="rust_bindgen.html#rust_bindgen_dependencies">rust_bindgen_dependencies</a></li>
<li><a href="rust_bindgen.html#rust_bindgen_register_toolchains">rust_bindgen_register_toolchains</a></li>
</ul>
<h2 id="overview-3"><a class="header" href="#overview-3">Overview</a></h2>
<p>These rules are for using <a href="https://github.com/rust-lang/rust-bindgen">Bindgen</a> to generate <a href="http://www.rust-lang.org/">Rust</a> bindings to C (and some C++) libraries.</p>
<p>See the <a href="https://github.com/bazelbuild/rules_rust/tree/main/examples/bindgen/BUILD.bazel">bindgen example</a> for a more complete example of use.</p>
<h3 id="setup-3"><a class="header" href="#setup-3">Setup</a></h3>
<p>To use the Rust bindgen rules, add the following to your <code>WORKSPACE</code> file to add the
external repositories for the Rust bindgen toolchain (in addition to the <a href="https://bazelbuild.github.io/rules_rust/#setup">rust rules setup</a>):</p>
<pre><code class="language-python">load("@rules_rust//bindgen:repositories.bzl", "rust_bindgen_dependencies", "rust_bindgen_register_toolchains")
rust_bindgen_dependencies()
rust_bindgen_register_toolchains()
load("@rules_rust//bindgen:transitive_repositories.bzl", "rust_bindgen_transitive_dependencies")
rust_bindgen_transitive_dependencies()
</code></pre>
<p>Bindgen aims to be as hermetic as possible so will end up building <code>libclang</code> from <a href="https://github.com/llvm/llvm-project">llvm-project</a> from
source. If this is found to be undesirable then no Bindgen related calls should be added to your WORKSPACE and instead
users should define their own repositories using something akin to <a href="https://bazelbuild.github.io/rules_rust/crate_universe.html">crate_universe</a> and define their own
toolchains following the instructions for <a href="rust_bindgen.html#rust_bindgen_toolchain">rust_bindgen_toolchain</a>.</p>
<hr />
<hr />
<p><a id="rust_bindgen"></a></p>
<h2 id="rust_bindgen"><a class="header" href="#rust_bindgen">rust_bindgen</a></h2>
<pre>
rust_bindgen(<a href="rust_bindgen.html#rust_bindgen-name">name</a>, <a href="rust_bindgen.html#rust_bindgen-bindgen_flags">bindgen_flags</a>, <a href="rust_bindgen.html#rust_bindgen-cc_lib">cc_lib</a>, <a href="rust_bindgen.html#rust_bindgen-clang_flags">clang_flags</a>, <a href="rust_bindgen.html#rust_bindgen-header">header</a>, <a href="rust_bindgen.html#rust_bindgen-merge_cc_lib_objects_into_rlib">merge_cc_lib_objects_into_rlib</a>,
<a href="rust_bindgen.html#rust_bindgen-wrap_static_fns">wrap_static_fns</a>)
</pre>
<p>Generates a rust source file from a cc_library and a header.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_bindgen-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-bindgen_flags"></a>bindgen_flags</td><td style="text-align: left">Flags to pass directly to the bindgen executable. See https://rust-lang.github.io/rust-bindgen/ for details.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-cc_lib"></a>cc_lib</td><td style="text-align: left">The cc_library that contains the <code>.h</code> file. This is used to find the transitive includes.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-clang_flags"></a>clang_flags</td><td style="text-align: left">Flags to pass directly to the clang executable.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-header"></a>header</td><td style="text-align: left">The <code>.h</code> file to generate bindings for.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-merge_cc_lib_objects_into_rlib"></a>merge_cc_lib_objects_into_rlib</td><td style="text-align: left">When True, objects from <code>cc_lib</code> will be copied into the <code>rlib</code> archive produced by the rust_library that depends on this <code>rust_bindgen</code> rule (using <code>BuildInfo</code> provider)</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-wrap_static_fns"></a>wrap_static_fns</td><td style="text-align: left">Whether to create a separate .c file for static fns. Requires nightly toolchain, and a header that actually needs this feature (otherwise bindgen won't generate the file and Bazel complains).</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_bindgen_toolchain"></a></p>
<h2 id="rust_bindgen_toolchain"><a class="header" href="#rust_bindgen_toolchain">rust_bindgen_toolchain</a></h2>
<pre>
rust_bindgen_toolchain(<a href="rust_bindgen.html#rust_bindgen_toolchain-name">name</a>, <a href="rust_bindgen.html#rust_bindgen_toolchain-bindgen">bindgen</a>, <a href="rust_bindgen.html#rust_bindgen_toolchain-clang">clang</a>, <a href="rust_bindgen.html#rust_bindgen_toolchain-default_rustfmt">default_rustfmt</a>, <a href="rust_bindgen.html#rust_bindgen_toolchain-libclang">libclang</a>, <a href="rust_bindgen.html#rust_bindgen_toolchain-libstdcxx">libstdcxx</a>)
</pre>
<p>The tools required for the <code>rust_bindgen</code> rule.</p>
<p>This rule depends on the <a href="https://crates.io/crates/bindgen"><code>bindgen</code></a> binary crate, and it
in turn depends on both a clang binary and the clang library. To obtain these dependencies,
<code>rust_bindgen_dependencies</code> imports bindgen and its dependencies.</p>
<pre><code class="language-python">load("@rules_rust//bindgen:defs.bzl", "rust_bindgen_toolchain")
rust_bindgen_toolchain(
name = "bindgen_toolchain_impl",
bindgen = "//my/rust:bindgen",
clang = "//my/clang:clang",
libclang = "//my/clang:libclang.so",
libstdcxx = "//my/cpp:libstdc++",
)
toolchain(
name = "bindgen_toolchain",
toolchain = "bindgen_toolchain_impl",
toolchain_type = "@rules_rust//bindgen:toolchain_type",
)
</code></pre>
<p>This toolchain will then need to be registered in the current <code>WORKSPACE</code>.
For additional information, see the <a href="https://docs.bazel.build/versions/master/toolchains.html">Bazel toolchains documentation</a>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-bindgen"></a>bindgen</td><td style="text-align: left">The label of a <code>bindgen</code> executable.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-clang"></a>clang</td><td style="text-align: left">The label of a <code>clang</code> executable.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-default_rustfmt"></a>default_rustfmt</td><td style="text-align: left">If set, <code>rust_bindgen</code> targets will always format generated sources with <code>rustfmt</code>.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-libclang"></a>libclang</td><td style="text-align: left">A cc_library that provides bindgen's runtime dependency on libclang.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-libstdcxx"></a>libstdcxx</td><td style="text-align: left">A cc_library that satisfies libclang's libstdc++ dependency. This is used to make the execution of clang hermetic. If None, system libraries will be used instead.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_bindgen_dependencies"></a></p>
<h2 id="rust_bindgen_dependencies"><a class="header" href="#rust_bindgen_dependencies">rust_bindgen_dependencies</a></h2>
<pre>
rust_bindgen_dependencies()
</pre>
<p>Declare dependencies needed for bindgen.</p>
<p><strong>RETURNS</strong></p>
<p>list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories
defined by this macro.</p>
<p><a id="rust_bindgen_library"></a></p>
<h2 id="rust_bindgen_library"><a class="header" href="#rust_bindgen_library">rust_bindgen_library</a></h2>
<pre>
rust_bindgen_library(<a href="rust_bindgen.html#rust_bindgen_library-name">name</a>, <a href="rust_bindgen.html#rust_bindgen_library-header">header</a>, <a href="rust_bindgen.html#rust_bindgen_library-cc_lib">cc_lib</a>, <a href="rust_bindgen.html#rust_bindgen_library-bindgen_flags">bindgen_flags</a>, <a href="rust_bindgen.html#rust_bindgen_library-bindgen_features">bindgen_features</a>, <a href="rust_bindgen.html#rust_bindgen_library-clang_flags">clang_flags</a>,
<a href="rust_bindgen.html#rust_bindgen_library-wrap_static_fns">wrap_static_fns</a>, <a href="rust_bindgen.html#rust_bindgen_library-kwargs">kwargs</a>)
</pre>
<p>Generates a rust source file for <code>header</code>, and builds a rust_library.</p>
<p>Arguments are the same as <code>rust_bindgen</code>, and <code>kwargs</code> are passed directly to rust_library.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_bindgen_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-header"></a>header</td><td style="text-align: left">The label of the .h file to generate bindings for.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-cc_lib"></a>cc_lib</td><td style="text-align: left">The label of the cc_library that contains the .h file. This is used to find the transitive includes.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-bindgen_flags"></a>bindgen_flags</td><td style="text-align: left">Flags to pass directly to the bindgen executable. See https://rust-lang.github.io/rust-bindgen/ for details.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-bindgen_features"></a>bindgen_features</td><td style="text-align: left">The <code>features</code> attribute for the <code>rust_bindgen</code> target.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-clang_flags"></a>clang_flags</td><td style="text-align: left">Flags to pass directly to the clang executable.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-wrap_static_fns"></a>wrap_static_fns</td><td style="text-align: left">Whether to create a separate .c file for static fns. Requires nightly toolchain, and a header that actually needs this feature (otherwise bindgen won't generate the file and Bazel complains",</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-kwargs"></a>kwargs</td><td style="text-align: left">Arguments to forward to the underlying <code>rust_library</code> rule.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><a id="rust_bindgen_register_toolchains"></a></p>
<h2 id="rust_bindgen_register_toolchains"><a class="header" href="#rust_bindgen_register_toolchains">rust_bindgen_register_toolchains</a></h2>
<pre>
rust_bindgen_register_toolchains(<a href="rust_bindgen.html#rust_bindgen_register_toolchains-register_toolchains">register_toolchains</a>)
</pre>
<p>Registers the default toolchains for the <code>rules_rust</code> <a href="https://rust-lang.github.io/rust-bindgen/">bindgen</a> rules.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_bindgen_register_toolchains-register_toolchains"></a>register_toolchains</td><td style="text-align: left">Whether or not to register toolchains.</td><td style="text-align: left"><code>True</code></td></tr>
</tbody></table>
</div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="rust-wasm-bindgen"><a class="header" href="#rust-wasm-bindgen">Rust Wasm Bindgen</a></h1>
<ul>
<li><a href="rust_wasm_bindgen.html#rust_wasm_bindgen_dependencies">rust_wasm_bindgen_dependencies</a></li>
<li><a href="rust_wasm_bindgen.html#rust_wasm_bindgen_register_toolchains">rust_wasm_bindgen_register_toolchains</a></li>
<li><a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain">rust_wasm_bindgen_toolchain</a></li>
<li><a href="rust_wasm_bindgen.html#rust_wasm_bindgen">rust_wasm_bindgen</a></li>
<li><a href="rust_wasm_bindgen.html#RustWasmBindgenInfo">RustWasmBindgenInfo</a></li>
</ul>
<h2 id="overview-4"><a class="header" href="#overview-4">Overview</a></h2>
<p>Bazel rules for generating wasm modules for Javascript using <a href="https://github.com/rustwasm/wasm-bindgen">wasm-bindgen</a>.</p>
<h2 id="setup-4"><a class="header" href="#setup-4">Setup</a></h2>
<p>To begin using the <code>wasm-bindgen</code> rules, users can load the necessary dependencies
in their workspace by adding the following to their <code>WORKSPACE.bazel</code> file.</p>
<pre><code class="language-python">load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_dependencies", "rust_wasm_bindgen_register_toolchains")
rust_wasm_bindgen_dependencies()
rust_wasm_bindgen_register_toolchains()
</code></pre>
<p>This should enable users to start using the <a href="rust_wasm_bindgen.html#rust_wasm_bindgen">rust_wasm_bindgen</a>
rule. However, it's common to want to control the version of <code>wasm-bindgen</code> in the
workspace instead of relying on the one provided by <code>rules_rust</code>. In this case, users
should avoid calling <code>rust_wasm_bindgen_register_toolchains</code> and instead use the
<a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain">rust_wasm_bindgen_toolchain</a> rule to define their own
toolchains to register in the workspace.</p>
<h3 id="interfacing-with-javascript-rules"><a class="header" href="#interfacing-with-javascript-rules">Interfacing with Javascript rules</a></h3>
<p>While it's recommended for users to mantain their own , in the
<code>@rules_rust//wasm_bindgen</code> package there exists interface sub-packages for various
Javascript Bazel rules. E.g. <code>build_bazel_rules_nodejs</code> or <code>aspect_rules_js</code>. The
rules defined there are a more convenient way to use <code>rust_wasm_bindgen</code> with the
associated javascript rules due to the inclusion of additional providers. Each
directory contains a <code>defs.bzl</code> file that defines the different variants of
<code>rust_wasm_bindgen</code>. (e.g. <code>nodejs_rust_wasm_bindgen</code> for the <code>rules_nodejs</code> submodule).</p>
<p><a id="rust_wasm_bindgen"></a></p>
<h2 id="rust_wasm_bindgen"><a class="header" href="#rust_wasm_bindgen">rust_wasm_bindgen</a></h2>
<pre>
rust_wasm_bindgen(<a href="rust_wasm_bindgen.html#rust_wasm_bindgen-name">name</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen-bindgen_flags">bindgen_flags</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen-target">target</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen-target_arch">target_arch</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen-wasm_file">wasm_file</a>)
</pre>
<p>Generates javascript and typescript bindings for a webassembly module using <a href="https://rustwasm.github.io/docs/wasm-bindgen/">wasm-bindgen</a>.</p>
<p>An example of this rule in use can be seen at <a href="../examples/wasm">@rules_rust//examples/wasm</a></p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen-bindgen_flags"></a>bindgen_flags</td><td style="text-align: left">Flags to pass directly to the bindgen executable. See https://github.com/rustwasm/wasm-bindgen/ for details.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen-target"></a>target</td><td style="text-align: left">The type of output to generate. See https://rustwasm.github.io/wasm-bindgen/reference/deployment.html for details.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"bundler"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen-target_arch"></a>target_arch</td><td style="text-align: left">The target architecture to use for the wasm-bindgen command line option.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"wasm32"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen-wasm_file"></a>wasm_file</td><td style="text-align: left">The <code>.wasm</code> file or crate to generate bindings for.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rust_wasm_bindgen_toolchain"></a></p>
<h2 id="rust_wasm_bindgen_toolchain"><a class="header" href="#rust_wasm_bindgen_toolchain">rust_wasm_bindgen_toolchain</a></h2>
<pre>
rust_wasm_bindgen_toolchain(<a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-name">name</a>, <a href="rust_wasm_bindgen.html#rust_wasm_bindgen_toolchain-bindgen">bindgen</a>)
</pre>
<p>The tools required for the <code>rust_wasm_bindgen</code> rule.</p>
<p>In cases where users want to control or change the version of <code>wasm-bindgen</code> used by <a href="rust_wasm_bindgen.html#rust_wasm_bindgen">rust_wasm_bindgen</a>,
a unique toolchain can be created as in the example below:</p>
<pre><code class="language-python">load("@rules_rust//bindgen:bindgen.bzl", "rust_bindgen_toolchain")
rust_bindgen_toolchain(
bindgen = "//3rdparty/crates:wasm_bindgen_cli__bin",
)
toolchain(
name = "wasm_bindgen_toolchain",
toolchain = "wasm_bindgen_toolchain_impl",
toolchain_type = "@rules_rust//wasm_bindgen:toolchain_type",
)
</code></pre>
<p>Now that you have your own toolchain, you need to register it by
inserting the following statement in your <code>WORKSPACE</code> file:</p>
<pre><code class="language-python">register_toolchains("//my/toolchains:wasm_bindgen_toolchain")
</code></pre>
<p>For additional information, see the <a href="https://docs.bazel.build/versions/master/toolchains.html">Bazel toolchains documentation</a>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-bindgen"></a>bindgen</td><td style="text-align: left">The label of a <code>wasm-bindgen-cli</code> executable.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><a id="RustWasmBindgenInfo"></a></p>
<h2 id="rustwasmbindgeninfo"><a class="header" href="#rustwasmbindgeninfo">RustWasmBindgenInfo</a></h2>
<pre>
RustWasmBindgenInfo(<a href="rust_wasm_bindgen.html#RustWasmBindgenInfo-js">js</a>, <a href="rust_wasm_bindgen.html#RustWasmBindgenInfo-ts">ts</a>, <a href="rust_wasm_bindgen.html#RustWasmBindgenInfo-wasm">wasm</a>)
</pre>
<p>Info about wasm-bindgen outputs.</p>
<p><strong>FIELDS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="RustWasmBindgenInfo-js"></a>js</td><td style="text-align: left">Depset[File]: The Javascript files produced by <code>wasm-bindgen</code>.</td></tr>
<tr><td style="text-align: left"><a id="RustWasmBindgenInfo-ts"></a>ts</td><td style="text-align: left">Depset[File]: The Typescript files produced by <code>wasm-bindgen</code>.</td></tr>
<tr><td style="text-align: left"><a id="RustWasmBindgenInfo-wasm"></a>wasm</td><td style="text-align: left">File: The <code>.wasm</code> file generated by <code>wasm-bindgen</code>.</td></tr>
</tbody></table>
</div>
<p><a id="rust_wasm_bindgen_dependencies"></a></p>
<h2 id="rust_wasm_bindgen_dependencies"><a class="header" href="#rust_wasm_bindgen_dependencies">rust_wasm_bindgen_dependencies</a></h2>
<pre>
rust_wasm_bindgen_dependencies()
</pre>
<p>Declare dependencies needed for the <code>rules_rust</code> <a href="https://github.com/rustwasm/wasm-bindgen">wasm-bindgen</a> rules.</p>
<p><strong>RETURNS</strong></p>
<p>list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories
defined by this macro.</p>
<p><a id="rust_wasm_bindgen_register_toolchains"></a></p>
<h2 id="rust_wasm_bindgen_register_toolchains"><a class="header" href="#rust_wasm_bindgen_register_toolchains">rust_wasm_bindgen_register_toolchains</a></h2>
<pre>
rust_wasm_bindgen_register_toolchains(<a href="rust_wasm_bindgen.html#rust_wasm_bindgen_register_toolchains-register_toolchains">register_toolchains</a>)
</pre>
<p>Registers the default toolchains for the <code>rules_rust</code> <a href="https://github.com/rustwasm/wasm-bindgen">wasm-bindgen</a> rules.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen_register_toolchains-register_toolchains"></a>register_toolchains</td><td style="text-align: left">Whether or not to register toolchains.</td><td style="text-align: left"><code>True</code></td></tr>
</tbody></table>
</div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="cargo"><a class="header" href="#cargo">Cargo</a></h1>
<ul>
<li><a href="cargo.html#cargo_bootstrap_repository">cargo_bootstrap_repository</a></li>
<li><a href="cargo.html#cargo_build_script">cargo_build_script</a></li>
<li><a href="cargo.html#cargo_dep_env">cargo_dep_env</a></li>
<li><a href="cargo.html#cargo_env">cargo_env</a></li>
</ul>
<p><a id="cargo_dep_env"></a></p>
<h2 id="cargo_dep_env"><a class="header" href="#cargo_dep_env">cargo_dep_env</a></h2>
<pre>
cargo_dep_env(<a href="cargo.html#cargo_dep_env-name">name</a>, <a href="cargo.html#cargo_dep_env-src">src</a>, <a href="cargo.html#cargo_dep_env-out_dir">out_dir</a>)
</pre>
<p>A rule for generating variables for dependent <code>cargo_build_script</code>s without a build script. This is useful for using Bazel rules instead of a build script, while also generating configuration information for build scripts which depend on this crate.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="cargo_dep_env-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_dep_env-src"></a>src</td><td style="text-align: left">File containing additional environment variables to set for build scripts of direct dependencies.<br><br>This has the same effect as a <code>cargo_build_script</code> which prints <code>cargo:VAR=VALUE</code> lines, but without requiring a build script.<br><br>This files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_dep_env-out_dir"></a>out_dir</td><td style="text-align: left">Folder containing additional inputs when building all direct dependencies.<br><br>This has the same effect as a <code>cargo_build_script</code> which prints puts files into <code>$OUT_DIR</code>, but without requiring a build script.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><a id="cargo_build_script"></a></p>
<h2 id="cargo_build_script"><a class="header" href="#cargo_build_script">cargo_build_script</a></h2>
<pre>
cargo_build_script(<a href="cargo.html#cargo_build_script-name">name</a>, <a href="cargo.html#cargo_build_script-edition">edition</a>, <a href="cargo.html#cargo_build_script-crate_name">crate_name</a>, <a href="cargo.html#cargo_build_script-crate_root">crate_root</a>, <a href="cargo.html#cargo_build_script-srcs">srcs</a>, <a href="cargo.html#cargo_build_script-crate_features">crate_features</a>, <a href="cargo.html#cargo_build_script-version">version</a>, <a href="cargo.html#cargo_build_script-deps">deps</a>,
<a href="cargo.html#cargo_build_script-link_deps">link_deps</a>, <a href="cargo.html#cargo_build_script-proc_macro_deps">proc_macro_deps</a>, <a href="cargo.html#cargo_build_script-build_script_env">build_script_env</a>, <a href="cargo.html#cargo_build_script-data">data</a>, <a href="cargo.html#cargo_build_script-compile_data">compile_data</a>, <a href="cargo.html#cargo_build_script-tools">tools</a>, <a href="cargo.html#cargo_build_script-links">links</a>,
<a href="cargo.html#cargo_build_script-rundir">rundir</a>, <a href="cargo.html#cargo_build_script-rustc_env">rustc_env</a>, <a href="cargo.html#cargo_build_script-rustc_env_files">rustc_env_files</a>, <a href="cargo.html#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="cargo.html#cargo_build_script-visibility">visibility</a>, <a href="cargo.html#cargo_build_script-tags">tags</a>, <a href="cargo.html#cargo_build_script-aliases">aliases</a>,
<a href="cargo.html#cargo_build_script-pkg_name">pkg_name</a>, <a href="cargo.html#cargo_build_script-kwargs">kwargs</a>)
</pre>
<p>Compile and execute a rust build script to generate build attributes</p>
<p>This rules take the same arguments as rust_binary.</p>
<p>Example:</p>
<p>Suppose you have a crate with a cargo build script <code>build.rs</code>:</p>
<pre><code class="language-output">[workspace]/
hello_lib/
BUILD
build.rs
src/
lib.rs
</code></pre>
<p>Then you want to use the build script in the following:</p>
<p><code>hello_lib/BUILD</code>:</p>
<pre><code class="language-python">package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
# This will run the build script from the root of the workspace, and
# collect the outputs.
cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
# Optional environment variables passed during build.rs compilation
rustc_env = {
"CARGO_PKG_VERSION": "0.1.2",
},
# Optional environment variables passed during build.rs execution.
# Note that as the build script's working directory is not execroot,
# execpath/location will return an absolute path, instead of a relative
# one.
build_script_env = {
"SOME_TOOL_OR_FILE": "$(execpath @tool//:binary)"
},
# Optional data/tool dependencies
data = ["@tool//:binary"],
)
rust_library(
name = "hello_lib",
srcs = [
"src/lib.rs",
],
deps = [":build_script"],
)
</code></pre>
<p>The <code>hello_lib</code> target will be build with the flags and the environment variables declared by the build script in addition to the file generated by it.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="cargo_build_script-name"></a>name</td><td style="text-align: left">The name for the underlying rule. This should be the name of the package being compiled, optionally with a suffix of <code>_bs</code>. Otherwise, you can set the package name via <code>pkg_name</code>.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-edition"></a>edition</td><td style="text-align: left">The rust edition to use for the internal binary crate.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for build script.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to rustc to be used for building this crate.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-srcs"></a>srcs</td><td style="text-align: left">Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-crate_features"></a>crate_features</td><td style="text-align: left">A list of features to enable for the build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-version"></a>version</td><td style="text-align: left">The semantic version (semver) of the crate.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-deps"></a>deps</td><td style="text-align: left">The build-dependencies of the crate.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-link_deps"></a>link_deps</td><td style="text-align: left">The subset of the (normal) dependencies of the crate that have the links attribute and therefore provide environment variables to this build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of rust_proc_macro targets used to build the script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-build_script_env"></a>build_script_env</td><td style="text-align: left">Environment variables for build scripts.</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-data"></a>data</td><td style="text-align: left">Files needed by the build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-compile_data"></a>compile_data</td><td style="text-align: left">Files needed for the compilation of the build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-tools"></a>tools</td><td style="text-align: left">Tools (executables) needed by the build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-links"></a>links</td><td style="text-align: left">Name of the native library this crate links against.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-rundir"></a>rundir</td><td style="text-align: left">A directory to <code>cd</code> to before the cargo_build_script is run. This should be a path relative to the exec root.<br><br>The default behaviour (and the behaviour if rundir is set to the empty string) is to change to the relative path corresponding to the cargo manifest directory, which replicates the normal behaviour of cargo so it is easy to write compatible build scripts.<br><br>If set to <code>.</code>, the cargo build script will run in the exec root.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-rustc_env"></a>rustc_env</td><td style="text-align: left">Environment variables to set in rustc when compiling the build script.</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc when building the build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-visibility"></a>visibility</td><td style="text-align: left">Visibility to apply to the generated build script output.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-tags"></a>tags</td><td style="text-align: left">(list of str, optional): Tags to apply to the generated build script output.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target. These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-pkg_name"></a>pkg_name</td><td style="text-align: left">Override the package name used for the build script. This is useful if the build target name gets too long otherwise.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-kwargs"></a>kwargs</td><td style="text-align: left">Forwards to the underlying <code>rust_binary</code> rule. An exception is the <code>compatible_with</code> attribute, which shouldn't be forwarded to the <code>rust_binary</code>, as the <code>rust_binary</code> is only built and used in <code>exec</code> mode. We propagate the <code>compatible_with</code> attribute to the <code>_build_scirpt_run</code> target.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><a id="cargo_env"></a></p>
<h2 id="cargo_env"><a class="header" href="#cargo_env">cargo_env</a></h2>
<pre>
cargo_env(<a href="cargo.html#cargo_env-env">env</a>)
</pre>
<p>A helper for generating platform specific environment variables</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_common")
load("@rules_rust//cargo:defs.bzl", "cargo_bootstrap_repository", "cargo_env")
cargo_bootstrap_repository(
name = "bootstrapped_bin",
cargo_lockfile = "//:Cargo.lock",
cargo_toml = "//:Cargo.toml",
srcs = ["//:resolver_srcs"],
version = rust_common.default_version,
binary = "my-crate-binary",
env = {
"x86_64-unknown-linux-gnu": cargo_env({
"FOO": "BAR",
}),
},
env_label = {
"aarch64-unknown-linux-musl": cargo_env({
"DOC": "//:README.md",
}),
}
)
</code></pre>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="cargo_env-env"></a>env</td><td style="text-align: left">A map of environment variables</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>str: A json encoded string of the environment variables</p>
<p><a id="cargo_bootstrap_repository"></a></p>
<h2 id="cargo_bootstrap_repository"><a class="header" href="#cargo_bootstrap_repository">cargo_bootstrap_repository</a></h2>
<pre>
cargo_bootstrap_repository(<a href="cargo.html#cargo_bootstrap_repository-name">name</a>, <a href="cargo.html#cargo_bootstrap_repository-srcs">srcs</a>, <a href="cargo.html#cargo_bootstrap_repository-binary">binary</a>, <a href="cargo.html#cargo_bootstrap_repository-build_mode">build_mode</a>, <a href="cargo.html#cargo_bootstrap_repository-cargo_config">cargo_config</a>, <a href="cargo.html#cargo_bootstrap_repository-cargo_lockfile">cargo_lockfile</a>, <a href="cargo.html#cargo_bootstrap_repository-cargo_toml">cargo_toml</a>,
<a href="cargo.html#cargo_bootstrap_repository-env">env</a>, <a href="cargo.html#cargo_bootstrap_repository-env_label">env_label</a>, <a href="cargo.html#cargo_bootstrap_repository-repo_mapping">repo_mapping</a>, <a href="cargo.html#cargo_bootstrap_repository-rust_toolchain_cargo_template">rust_toolchain_cargo_template</a>,
<a href="cargo.html#cargo_bootstrap_repository-rust_toolchain_rustc_template">rust_toolchain_rustc_template</a>, <a href="cargo.html#cargo_bootstrap_repository-timeout">timeout</a>, <a href="cargo.html#cargo_bootstrap_repository-version">version</a>)
</pre>
<p>A rule for bootstrapping a Rust binary using <a href="https://doc.rust-lang.org/cargo/">Cargo</a></p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-name"></a>name</td><td style="text-align: left">A unique name for this repository.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-srcs"></a>srcs</td><td style="text-align: left">Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-binary"></a>binary</td><td style="text-align: left">The binary to build (the <code>--bin</code> parameter for Cargo). If left empty, the repository name will be used.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-build_mode"></a>build_mode</td><td style="text-align: left">The build mode the binary should be built with</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"release"</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-cargo_config"></a>cargo_config</td><td style="text-align: left">The path of the Cargo configuration (<code>Config.toml</code>) file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-cargo_lockfile"></a>cargo_lockfile</td><td style="text-align: left">The lockfile of the crate_universe resolver</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-cargo_toml"></a>cargo_toml</td><td style="text-align: left">The path of the <code>Cargo.toml</code> file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-env"></a>env</td><td style="text-align: left">A mapping of platform triple to a set of environment variables. See <a href="cargo.html#cargo_env">cargo_env</a> for usage details. Additionally, the platform triple <code>*</code> applies to all platforms.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-env_label"></a>env_label</td><td style="text-align: left">A mapping of platform triple to a set of environment variables. This attribute differs from <code>env</code> in that all variables passed here must be fully qualified labels of files. See <a href="cargo.html#cargo_env">cargo_env</a> for usage details. Additionally, the platform triple <code>*</code> applies to all platforms.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-repo_mapping"></a>repo_mapping</td><td style="text-align: left">In <code>WORKSPACE</code> context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>).<br><br>This attribute is <em>not</em> supported in <code>MODULE.bazel</code> context (when invoking a repository rule inside a module extension's implementation function).</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-rust_toolchain_cargo_template"></a>rust_toolchain_cargo_template</td><td style="text-align: left">The template to use for finding the host <code>cargo</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-rust_toolchain_rustc_template"></a>rust_toolchain_rustc_template</td><td style="text-align: left">The template to use for finding the host <code>rustc</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-timeout"></a>timeout</td><td style="text-align: left">Maximum duration of the Cargo build command in seconds</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>600</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-version"></a>version</td><td style="text-align: left">The version of Rust the currently registered toolchain is using. Eg. <code>1.56.0</code>, or <code>nightly/2021-09-08</code></td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"1.82.0"</code></td></tr>
</tbody></table>
</div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="rust-analyzer"><a class="header" href="#rust-analyzer">Rust Analyzer</a></h1>
<ul>
<li><a href="rust_analyzer.html#rust_analyzer_aspect">rust_analyzer_aspect</a></li>
<li><a href="rust_analyzer.html#rust_analyzer_toolchain">rust_analyzer_toolchain</a></li>
</ul>
<h2 id="overview-5"><a class="header" href="#overview-5">Overview</a></h2>
<p>For <a href="https://rust-analyzer.github.io/manual.html#non-cargo-based-projects">non-Cargo projects</a>,
<a href="https://rust-analyzer.github.io/">rust-analyzer</a> depends on a <code>rust-project.json</code> file at the
root of the project that describes its structure. The <code>rust_analyzer</code> rule facilitates generating
such a file.</p>
<h3 id="setup-5"><a class="header" href="#setup-5">Setup</a></h3>
<p>First, ensure <code>rules_rust</code> is setup in your workspace. By default, <code>rust_register_toolchains</code> will
ensure a <a href="rust_analyzer.html#rust_analyzer_toolchain">rust_analyzer_toolchain</a> is registered within the WORKSPACE.</p>
<p>Next, load the dependencies for the <code>rust-project.json</code> generator tool:</p>
<pre><code class="language-python">load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")
rust_analyzer_dependencies()
</code></pre>
<p>Finally, run <code>bazel run @rules_rust//tools/rust_analyzer:gen_rust_project</code>
whenever dependencies change to regenerate the <code>rust-project.json</code> file. It
should be added to <code>.gitignore</code> because it is effectively a build artifact.
Once the <code>rust-project.json</code> has been generated in the project root,
rust-analyzer can pick it up upon restart.</p>
<p>For users who do not use <code>rust_register_toolchains</code> to register toolchains, the following can be added
to their WORKSPACE to register a <code>rust_analyzer_toolchain</code>. Please make sure the Rust version used in
this toolchain matches the version used by the currently registered toolchain or the sources/documentation
will not match what's being compiled with and can lead to confusing results.</p>
<pre><code class="language-python">load("@rules_rust//rust:repositories.bzl", "rust_analyzer_toolchain_repository")
register_toolchains(rust_analyzer_toolchain_repository(
name = "rust_analyzer_toolchain",
# This should match the currently registered toolchain.
version = "1.63.0",
))
</code></pre>
<h4 id="vscode"><a class="header" href="#vscode">VSCode</a></h4>
<p>To set this up using <a href="https://code.visualstudio.com/">VSCode</a>, users should first install the
<a href="https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer">rust_analyzer plugin</a>.
With that in place, the following task can be added to the <code>.vscode/tasks.json</code> file of the workspace
to ensure a <code>rust-project.json</code> file is created and up to date when the editor is opened.</p>
<pre><code class="language-json">{
"version": "2.0.0",
"tasks": [
{
"label": "Generate rust-project.json",
"command": "bazel",
"args": [
"run",
"//tools/rust_analyzer:gen_rust_project"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": "build",
"problemMatcher": [],
"presentation": {
"reveal": "never",
"panel": "dedicated",
},
"runOptions": {
"runOn": "folderOpen"
}
},
]
}
</code></pre>
<h4 id="alternative-vscode-option-prototype"><a class="header" href="#alternative-vscode-option-prototype">Alternative vscode option (prototype)</a></h4>
<p>Add the following to your bazelrc:</p>
<pre><code>build --@rules_rust//:rustc_output_diagnostics=true --output_groups=+rust_lib_rustc_output,+rust_metadata_rustc_output
</code></pre>
<p>Then you can use a prototype <a href="https://marketplace.visualstudio.com/items?itemName=MattStark.bazel-rust-analyzer">rust-analyzer plugin</a> that automatically collects the outputs whenever you recompile.</p>
<p><a id="rust_analyzer_toolchain"></a></p>
<h2 id="rust_analyzer_toolchain"><a class="header" href="#rust_analyzer_toolchain">rust_analyzer_toolchain</a></h2>
<pre>
rust_analyzer_toolchain(<a href="rust_analyzer.html#rust_analyzer_toolchain-name">name</a>, <a href="rust_analyzer.html#rust_analyzer_toolchain-proc_macro_srv">proc_macro_srv</a>, <a href="rust_analyzer.html#rust_analyzer_toolchain-rustc">rustc</a>, <a href="rust_analyzer.html#rust_analyzer_toolchain-rustc_srcs">rustc_srcs</a>)
</pre>
<p>A toolchain for <a href="https://rust-analyzer.github.io/">rust-analyzer</a>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-proc_macro_srv"></a>proc_macro_srv</td><td style="text-align: left">The path to a <code>rust_analyzer_proc_macro_srv</code> binary.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-rustc"></a>rustc</td><td style="text-align: left">The path to a <code>rustc</code> binary.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-rustc_srcs"></a>rustc_srcs</td><td style="text-align: left">The source code of rustc.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rust_analyzer_aspect"></a></p>
<h2 id="rust_analyzer_aspect"><a class="header" href="#rust_analyzer_aspect">rust_analyzer_aspect</a></h2>
<pre>
rust_analyzer_aspect(<a href="rust_analyzer.html#rust_analyzer_aspect-name">name</a>)
</pre>
<p>Annotates rust rules with RustAnalyzerInfo later used to build a rust-project.json</p>
<p><strong>ASPECT ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Type</th></tr></thead><tbody>
<tr><td style="text-align: left">deps</td><td style="text-align: left">String</td></tr>
<tr><td style="text-align: left">proc_macro_deps</td><td style="text-align: left">String</td></tr>
<tr><td style="text-align: left">crate</td><td style="text-align: left">String</td></tr>
<tr><td style="text-align: left">actual</td><td style="text-align: left">String</td></tr>
<tr><td style="text-align: left">proto</td><td style="text-align: left">String</td></tr>
</tbody></table>
</div>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_analyzer_aspect-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div><div style="break-before: page; page-break-before: always;"></div><h1 id="rust-rules"><a class="header" href="#rust-rules">Rust rules</a></h1>
<ul>
<li><a href="flatten.html#CrateInfo">CrateInfo</a></li>
<li><a href="flatten.html#DepInfo">DepInfo</a></li>
<li><a href="flatten.html#RustWasmBindgenInfo">RustWasmBindgenInfo</a></li>
<li><a href="flatten.html#StdLibInfo">StdLibInfo</a></li>
<li><a href="flatten.html#capture_clippy_output">capture_clippy_output</a></li>
<li><a href="flatten.html#cargo_bootstrap_repository">cargo_bootstrap_repository</a></li>
<li><a href="flatten.html#cargo_build_script">cargo_build_script</a></li>
<li><a href="flatten.html#cargo_dep_env">cargo_dep_env</a></li>
<li><a href="flatten.html#cargo_env">cargo_env</a></li>
<li><a href="flatten.html#error_format">error_format</a></li>
<li><a href="flatten.html#extra_rustc_flag">extra_rustc_flag</a></li>
<li><a href="flatten.html#extra_rustc_flags">extra_rustc_flags</a></li>
<li><a href="flatten.html#fail_when_enabled">fail_when_enabled</a></li>
<li><a href="flatten.html#incompatible_flag">incompatible_flag</a></li>
<li><a href="flatten.html#rules_rust_dependencies">rules_rust_dependencies</a></li>
<li><a href="flatten.html#rust_analyzer_aspect">rust_analyzer_aspect</a></li>
<li><a href="flatten.html#rust_analyzer_toolchain">rust_analyzer_toolchain</a></li>
<li><a href="flatten.html#rust_analyzer_toolchain_repository">rust_analyzer_toolchain_repository</a></li>
<li><a href="flatten.html#rust_binary">rust_binary</a></li>
<li><a href="flatten.html#rust_bindgen">rust_bindgen</a></li>
<li><a href="flatten.html#rust_bindgen_dependencies">rust_bindgen_dependencies</a></li>
<li><a href="flatten.html#rust_bindgen_library">rust_bindgen_library</a></li>
<li><a href="flatten.html#rust_bindgen_register_toolchains">rust_bindgen_register_toolchains</a></li>
<li><a href="flatten.html#rust_bindgen_toolchain">rust_bindgen_toolchain</a></li>
<li><a href="flatten.html#rust_clippy">rust_clippy</a></li>
<li><a href="flatten.html#rust_clippy_aspect">rust_clippy_aspect</a></li>
<li><a href="flatten.html#rust_doc">rust_doc</a></li>
<li><a href="flatten.html#rust_doc_test">rust_doc_test</a></li>
<li><a href="flatten.html#rust_grpc_library">rust_grpc_library</a></li>
<li><a href="flatten.html#rust_library">rust_library</a></li>
<li><a href="flatten.html#rust_library_group">rust_library_group</a></li>
<li><a href="flatten.html#rust_proc_macro">rust_proc_macro</a></li>
<li><a href="flatten.html#rust_prost_dependencies">rust_prost_dependencies</a></li>
<li><a href="flatten.html#rust_prost_library">rust_prost_library</a></li>
<li><a href="flatten.html#rust_prost_toolchain">rust_prost_toolchain</a></li>
<li><a href="flatten.html#rust_prost_transitive_repositories">rust_prost_transitive_repositories</a></li>
<li><a href="flatten.html#rust_proto_library">rust_proto_library</a></li>
<li><a href="flatten.html#rust_proto_protobuf_dependencies">rust_proto_protobuf_dependencies</a></li>
<li><a href="flatten.html#rust_proto_protobuf_register_toolchains">rust_proto_protobuf_register_toolchains</a></li>
<li><a href="flatten.html#rust_proto_protobuf_toolchain">rust_proto_protobuf_toolchain</a></li>
<li><a href="flatten.html#rust_proto_protobuf_transitive_repositories">rust_proto_protobuf_transitive_repositories</a></li>
<li><a href="flatten.html#rust_register_toolchains">rust_register_toolchains</a></li>
<li><a href="flatten.html#rust_repositories">rust_repositories</a></li>
<li><a href="flatten.html#rust_repository_set">rust_repository_set</a></li>
<li><a href="flatten.html#rust_shared_library">rust_shared_library</a></li>
<li><a href="flatten.html#rust_static_library">rust_static_library</a></li>
<li><a href="flatten.html#rust_stdlib_filegroup">rust_stdlib_filegroup</a></li>
<li><a href="flatten.html#rust_test">rust_test</a></li>
<li><a href="flatten.html#rust_test_suite">rust_test_suite</a></li>
<li><a href="flatten.html#rust_toolchain">rust_toolchain</a></li>
<li><a href="flatten.html#rust_toolchain_repository">rust_toolchain_repository</a></li>
<li><a href="flatten.html#rust_toolchain_repository_proxy">rust_toolchain_repository_proxy</a></li>
<li><a href="flatten.html#rust_toolchain_tools_repository">rust_toolchain_tools_repository</a></li>
<li><a href="flatten.html#rust_wasm_bindgen">rust_wasm_bindgen</a></li>
<li><a href="flatten.html#rust_wasm_bindgen_dependencies">rust_wasm_bindgen_dependencies</a></li>
<li><a href="flatten.html#rust_wasm_bindgen_register_toolchains">rust_wasm_bindgen_register_toolchains</a></li>
<li><a href="flatten.html#rust_wasm_bindgen_toolchain">rust_wasm_bindgen_toolchain</a></li>
<li><a href="flatten.html#rustfmt_aspect">rustfmt_aspect</a></li>
<li><a href="flatten.html#rustfmt_test">rustfmt_test</a></li>
<li><a href="flatten.html#rustfmt_toolchain">rustfmt_toolchain</a></li>
</ul>
<p><a id="capture_clippy_output"></a></p>
<h2 id="capture_clippy_output-1"><a class="header" href="#capture_clippy_output-1">capture_clippy_output</a></h2>
<pre>
capture_clippy_output(<a href="flatten.html#capture_clippy_output-name">name</a>)
</pre>
<p>Control whether to print clippy output or store it to a file, using the configured error_format.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="capture_clippy_output-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="cargo_dep_env"></a></p>
<h2 id="cargo_dep_env-1"><a class="header" href="#cargo_dep_env-1">cargo_dep_env</a></h2>
<pre>
cargo_dep_env(<a href="flatten.html#cargo_dep_env-name">name</a>, <a href="flatten.html#cargo_dep_env-src">src</a>, <a href="flatten.html#cargo_dep_env-out_dir">out_dir</a>)
</pre>
<p>A rule for generating variables for dependent <code>cargo_build_script</code>s without a build script. This is useful for using Bazel rules instead of a build script, while also generating configuration information for build scripts which depend on this crate.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="cargo_dep_env-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_dep_env-src"></a>src</td><td style="text-align: left">File containing additional environment variables to set for build scripts of direct dependencies.<br><br>This has the same effect as a <code>cargo_build_script</code> which prints <code>cargo:VAR=VALUE</code> lines, but without requiring a build script.<br><br>This files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_dep_env-out_dir"></a>out_dir</td><td style="text-align: left">Folder containing additional inputs when building all direct dependencies.<br><br>This has the same effect as a <code>cargo_build_script</code> which prints puts files into <code>$OUT_DIR</code>, but without requiring a build script.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><a id="error_format"></a></p>
<h2 id="error_format-1"><a class="header" href="#error_format-1">error_format</a></h2>
<pre>
error_format(<a href="flatten.html#error_format-name">name</a>)
</pre>
<p>Change the <a href="https://doc.rust-lang.org/rustc/command-line-arguments.html#option-error-format">--error-format</a> flag from the command line with <code>--@rules_rust//:error_format</code>. See rustc documentation for valid values.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="error_format-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="extra_rustc_flag"></a></p>
<h2 id="extra_rustc_flag-1"><a class="header" href="#extra_rustc_flag-1">extra_rustc_flag</a></h2>
<pre>
extra_rustc_flag(<a href="flatten.html#extra_rustc_flag-name">name</a>)
</pre>
<p>Add additional rustc_flag from the command line with <code>--@rules_rust//:extra_rustc_flag</code>. Multiple uses are accumulated and appended after the extra_rustc_flags.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="extra_rustc_flag-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="extra_rustc_flags"></a></p>
<h2 id="extra_rustc_flags-1"><a class="header" href="#extra_rustc_flags-1">extra_rustc_flags</a></h2>
<pre>
extra_rustc_flags(<a href="flatten.html#extra_rustc_flags-name">name</a>)
</pre>
<p>Add additional rustc_flags from the command line with <code>--@rules_rust//:extra_rustc_flags</code>. This flag should only be used for flags that need to be applied across the entire build. For options that apply to individual crates, use the rustc_flags attribute on the individual crate's rule instead. NOTE: These flags not applied to the exec configuration (proc-macros, cargo_build_script, etc); use <code>--@rules_rust//:extra_exec_rustc_flags</code> to apply flags to the exec configuration.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="extra_rustc_flags-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="incompatible_flag"></a></p>
<h2 id="incompatible_flag"><a class="header" href="#incompatible_flag">incompatible_flag</a></h2>
<pre>
incompatible_flag(<a href="flatten.html#incompatible_flag-name">name</a>, <a href="flatten.html#incompatible_flag-issue">issue</a>)
</pre>
<p>A rule defining an incompatible flag.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="incompatible_flag-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="incompatible_flag-issue"></a>issue</td><td style="text-align: left">The link to the github issue associated with this flag</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rust_analyzer_toolchain"></a></p>
<h2 id="rust_analyzer_toolchain-1"><a class="header" href="#rust_analyzer_toolchain-1">rust_analyzer_toolchain</a></h2>
<pre>
rust_analyzer_toolchain(<a href="flatten.html#rust_analyzer_toolchain-name">name</a>, <a href="flatten.html#rust_analyzer_toolchain-proc_macro_srv">proc_macro_srv</a>, <a href="flatten.html#rust_analyzer_toolchain-rustc">rustc</a>, <a href="flatten.html#rust_analyzer_toolchain-rustc_srcs">rustc_srcs</a>)
</pre>
<p>A toolchain for <a href="https://rust-analyzer.github.io/">rust-analyzer</a>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-proc_macro_srv"></a>proc_macro_srv</td><td style="text-align: left">The path to a <code>rust_analyzer_proc_macro_srv</code> binary.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-rustc"></a>rustc</td><td style="text-align: left">The path to a <code>rustc</code> binary.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain-rustc_srcs"></a>rustc_srcs</td><td style="text-align: left">The source code of rustc.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rust_binary"></a></p>
<h2 id="rust_binary-1"><a class="header" href="#rust_binary-1">rust_binary</a></h2>
<pre>
rust_binary(<a href="flatten.html#rust_binary-name">name</a>, <a href="flatten.html#rust_binary-deps">deps</a>, <a href="flatten.html#rust_binary-srcs">srcs</a>, <a href="flatten.html#rust_binary-data">data</a>, <a href="flatten.html#rust_binary-aliases">aliases</a>, <a href="flatten.html#rust_binary-alwayslink">alwayslink</a>, <a href="flatten.html#rust_binary-binary_name">binary_name</a>, <a href="flatten.html#rust_binary-compile_data">compile_data</a>, <a href="flatten.html#rust_binary-crate_features">crate_features</a>,
<a href="flatten.html#rust_binary-crate_name">crate_name</a>, <a href="flatten.html#rust_binary-crate_root">crate_root</a>, <a href="flatten.html#rust_binary-crate_type">crate_type</a>, <a href="flatten.html#rust_binary-edition">edition</a>, <a href="flatten.html#rust_binary-env">env</a>, <a href="flatten.html#rust_binary-experimental_use_cc_common_link">experimental_use_cc_common_link</a>,
<a href="flatten.html#rust_binary-linker_script">linker_script</a>, <a href="flatten.html#rust_binary-malloc">malloc</a>, <a href="flatten.html#rust_binary-out_binary">out_binary</a>, <a href="flatten.html#rust_binary-platform">platform</a>, <a href="flatten.html#rust_binary-proc_macro_deps">proc_macro_deps</a>, <a href="flatten.html#rust_binary-rustc_env">rustc_env</a>, <a href="flatten.html#rust_binary-rustc_env_files">rustc_env_files</a>,
<a href="flatten.html#rust_binary-rustc_flags">rustc_flags</a>, <a href="flatten.html#rust_binary-stamp">stamp</a>, <a href="flatten.html#rust_binary-version">version</a>)
</pre>
<p>Builds a Rust binary crate.</p>
<p>Example:</p>
<p>Suppose you have the following directory structure for a Rust project with a
library crate, <code>hello_lib</code>, and a binary crate, <code>hello_world</code> that uses the
<code>hello_lib</code> library:</p>
<pre><code class="language-output">[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
lib.rs
hello_world/
BUILD
src/
main.rs
</code></pre>
<p><code>hello_lib/src/lib.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct Greeter {
greeting: String,
}
impl Greeter {
pub fn new(greeting: &amp;str) -&gt; Greeter {
Greeter { greeting: greeting.to_string(), }
}
pub fn greet(&amp;self, thing: &amp;str) {
println!("{} {}", &amp;self.greeting, thing);
}
}
<span class="boring">}</span></code></pre></pre>
<p><code>hello_lib/BUILD</code>:</p>
<pre><code class="language-python">package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_library")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
</code></pre>
<p><code>hello_world/src/main.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust">extern crate hello_lib;
fn main() {
let hello = hello_lib::Greeter::new("Hello");
hello.greet("world");
}</code></pre></pre>
<p><code>hello_world/BUILD</code>:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_binary")
rust_binary(
name = "hello_world",
srcs = ["src/main.rs"],
deps = ["//hello_lib"],
)
</code></pre>
<p>Build and run <code>hello_world</code>:</p>
<pre><code>$ bazel run //hello_world
INFO: Found 1 target...
Target //examples/rust/hello_world:hello_world up-to-date:
bazel-bin/examples/rust/hello_world/hello_world
INFO: Elapsed time: 1.308s, Critical Path: 1.22s
INFO: Running command line: bazel-bin/examples/rust/hello_world/hello_world
Hello world
</code></pre>
<p>On Windows, a PDB file containing debugging information is available under
the key <code>pdb_file</code> in <code>OutputGroupInfo</code>. Similarly on macOS, a dSYM folder
is available under the key <code>dsym_folder</code> in <code>OutputGroupInfo</code>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_binary-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-binary_name"></a>binary_name</td><td style="text-align: left">Override the resulting binary file name. By default, the binary file will be named using the <code>name</code> attribute on this rule, however sometimes that is not deseriable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-crate_type"></a>crate_type</td><td style="text-align: left">Crate type that will be passed to <code>rustc</code> to be used for building this crate.<br><br>This option is a temporary workaround and should be used only when building for WebAssembly targets (//rust/platform:wasi and //rust/platform:wasm).</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"bin"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-env"></a>env</td><td style="text-align: left">Specifies additional environment variables to set when the target is executed by bazel run. Values are subject to <code>$(rootpath)</code>, <code>$(execpath)</code>, location, and <a href="https://docs.bazel.build/versions/master/be/make-variables.html">"Make variable"</a> substitution.<br><br>Execpath returns absolute path, and in order to be able to construct the absolute path we need to wrap the test binary in a launcher. Using a launcher comes with complications, such as more complicated debugger attachment.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-linker_script"></a>linker_script</td><td style="text-align: left">Link script to forward into linker via rustc options.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-malloc"></a>malloc</td><td style="text-align: left">Override the default dependency on <code>malloc</code>.<br><br>By default, Rust binaries linked with cc_common.link are linked against <code>@bazel_tools//tools/cpp:malloc"</code>, which is an empty library and the resulting binary will use libc's <code>malloc</code>. This label must refer to a <code>cc_library</code> rule.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@bazel_tools//tools/cpp:malloc"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-out_binary"></a>out_binary</td><td style="text-align: left">Force a target, regardless of it's <code>crate_type</code>, to always mark the file as executable. This attribute is only used to support wasm targets but is expected to be removed following a resolution to https://github.com/bazelbuild/rules_rust/issues/771.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the binary to.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr>
<tr><td style="text-align: left"><a id="rust_binary-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_bindgen"></a></p>
<h2 id="rust_bindgen-1"><a class="header" href="#rust_bindgen-1">rust_bindgen</a></h2>
<pre>
rust_bindgen(<a href="flatten.html#rust_bindgen-name">name</a>, <a href="flatten.html#rust_bindgen-bindgen_flags">bindgen_flags</a>, <a href="flatten.html#rust_bindgen-cc_lib">cc_lib</a>, <a href="flatten.html#rust_bindgen-clang_flags">clang_flags</a>, <a href="flatten.html#rust_bindgen-header">header</a>, <a href="flatten.html#rust_bindgen-merge_cc_lib_objects_into_rlib">merge_cc_lib_objects_into_rlib</a>,
<a href="flatten.html#rust_bindgen-wrap_static_fns">wrap_static_fns</a>)
</pre>
<p>Generates a rust source file from a cc_library and a header.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_bindgen-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-bindgen_flags"></a>bindgen_flags</td><td style="text-align: left">Flags to pass directly to the bindgen executable. See https://rust-lang.github.io/rust-bindgen/ for details.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-cc_lib"></a>cc_lib</td><td style="text-align: left">The cc_library that contains the <code>.h</code> file. This is used to find the transitive includes.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-clang_flags"></a>clang_flags</td><td style="text-align: left">Flags to pass directly to the clang executable.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-header"></a>header</td><td style="text-align: left">The <code>.h</code> file to generate bindings for.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-merge_cc_lib_objects_into_rlib"></a>merge_cc_lib_objects_into_rlib</td><td style="text-align: left">When True, objects from <code>cc_lib</code> will be copied into the <code>rlib</code> archive produced by the rust_library that depends on this <code>rust_bindgen</code> rule (using <code>BuildInfo</code> provider)</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen-wrap_static_fns"></a>wrap_static_fns</td><td style="text-align: left">Whether to create a separate .c file for static fns. Requires nightly toolchain, and a header that actually needs this feature (otherwise bindgen won't generate the file and Bazel complains).</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_bindgen_toolchain"></a></p>
<h2 id="rust_bindgen_toolchain-1"><a class="header" href="#rust_bindgen_toolchain-1">rust_bindgen_toolchain</a></h2>
<pre>
rust_bindgen_toolchain(<a href="flatten.html#rust_bindgen_toolchain-name">name</a>, <a href="flatten.html#rust_bindgen_toolchain-bindgen">bindgen</a>, <a href="flatten.html#rust_bindgen_toolchain-clang">clang</a>, <a href="flatten.html#rust_bindgen_toolchain-default_rustfmt">default_rustfmt</a>, <a href="flatten.html#rust_bindgen_toolchain-libclang">libclang</a>, <a href="flatten.html#rust_bindgen_toolchain-libstdcxx">libstdcxx</a>)
</pre>
<p>The tools required for the <code>rust_bindgen</code> rule.</p>
<p>This rule depends on the <a href="https://crates.io/crates/bindgen"><code>bindgen</code></a> binary crate, and it
in turn depends on both a clang binary and the clang library. To obtain these dependencies,
<code>rust_bindgen_dependencies</code> imports bindgen and its dependencies.</p>
<pre><code class="language-python">load("@rules_rust//bindgen:defs.bzl", "rust_bindgen_toolchain")
rust_bindgen_toolchain(
name = "bindgen_toolchain_impl",
bindgen = "//my/rust:bindgen",
clang = "//my/clang:clang",
libclang = "//my/clang:libclang.so",
libstdcxx = "//my/cpp:libstdc++",
)
toolchain(
name = "bindgen_toolchain",
toolchain = "bindgen_toolchain_impl",
toolchain_type = "@rules_rust//bindgen:toolchain_type",
)
</code></pre>
<p>This toolchain will then need to be registered in the current <code>WORKSPACE</code>.
For additional information, see the <a href="https://docs.bazel.build/versions/master/toolchains.html">Bazel toolchains documentation</a>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-bindgen"></a>bindgen</td><td style="text-align: left">The label of a <code>bindgen</code> executable.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-clang"></a>clang</td><td style="text-align: left">The label of a <code>clang</code> executable.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-default_rustfmt"></a>default_rustfmt</td><td style="text-align: left">If set, <code>rust_bindgen</code> targets will always format generated sources with <code>rustfmt</code>.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-libclang"></a>libclang</td><td style="text-align: left">A cc_library that provides bindgen's runtime dependency on libclang.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_toolchain-libstdcxx"></a>libstdcxx</td><td style="text-align: left">A cc_library that satisfies libclang's libstdc++ dependency. This is used to make the execution of clang hermetic. If None, system libraries will be used instead.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_clippy"></a></p>
<h2 id="rust_clippy-1"><a class="header" href="#rust_clippy-1">rust_clippy</a></h2>
<pre>
rust_clippy(<a href="flatten.html#rust_clippy-name">name</a>, <a href="flatten.html#rust_clippy-deps">deps</a>)
</pre>
<p>Executes the clippy checker on a specific target.</p>
<p>Similar to <code>rust_clippy_aspect</code>, but allows specifying a list of dependencies within the build system.</p>
<p>For example, given the following example targets:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_test(
name = "greeting_test",
srcs = ["tests/greeting.rs"],
deps = [":hello_lib"],
)
</code></pre>
<p>Rust clippy can be set as a build target with the following:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_clippy")
rust_clippy(
name = "hello_library_clippy",
testonly = True,
deps = [
":hello_lib",
":greeting_test",
],
)
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_clippy-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_clippy-deps"></a>deps</td><td style="text-align: left">Rust targets to run clippy on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_doc"></a></p>
<h2 id="rust_doc-1"><a class="header" href="#rust_doc-1">rust_doc</a></h2>
<pre>
rust_doc(<a href="flatten.html#rust_doc-name">name</a>, <a href="flatten.html#rust_doc-crate">crate</a>, <a href="flatten.html#rust_doc-html_after_content">html_after_content</a>, <a href="flatten.html#rust_doc-html_before_content">html_before_content</a>, <a href="flatten.html#rust_doc-html_in_header">html_in_header</a>, <a href="flatten.html#rust_doc-markdown_css">markdown_css</a>,
<a href="flatten.html#rust_doc-rustc_flags">rustc_flags</a>, <a href="flatten.html#rust_doc-rustdoc_flags">rustdoc_flags</a>)
</pre>
<p>Generates code documentation.</p>
<p>Example:
Suppose you have the following directory structure for a Rust library crate:</p>
<pre><code>[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
lib.rs
</code></pre>
<p>To build <a href="https://doc.rust-lang.org/book/documentation.html"><code>rustdoc</code></a> documentation for the <code>hello_lib</code> crate, define a <code>rust_doc</code> rule that depends on the the <code>hello_lib</code> <code>rust_library</code> target:</p>
<pre><code class="language-python">package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_doc(
name = "hello_lib_doc",
crate = ":hello_lib",
)
</code></pre>
<p>Running <code>bazel build //hello_lib:hello_lib_doc</code> will build a zip file containing the documentation for the <code>hello_lib</code> library crate generated by <code>rustdoc</code>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_doc-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-crate"></a>crate</td><td style="text-align: left">The label of the target to generate code documentation for.<br><br><code>rust_doc</code> can generate HTML code documentation for the source files of <code>rust_library</code> or <code>rust_binary</code> targets.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-html_after_content"></a>html_after_content</td><td style="text-align: left">File to add in <code>&lt;body&gt;</code>, after content.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-html_before_content"></a>html_before_content</td><td style="text-align: left">File to add in <code>&lt;body&gt;</code>, before content.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-html_in_header"></a>html_in_header</td><td style="text-align: left">File to add to <code>&lt;head&gt;</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-markdown_css"></a>markdown_css</td><td style="text-align: left">CSS files to include via <code>&lt;link&gt;</code> in a rendered Markdown file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-rustc_flags"></a>rustc_flags</td><td style="text-align: left"><strong>Deprecated</strong>: use <code>rustdoc_flags</code> instead</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc-rustdoc_flags"></a>rustdoc_flags</td><td style="text-align: left">List of flags passed to <code>rustdoc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_doc_test"></a></p>
<h2 id="rust_doc_test-1"><a class="header" href="#rust_doc_test-1">rust_doc_test</a></h2>
<pre>
rust_doc_test(<a href="flatten.html#rust_doc_test-name">name</a>, <a href="flatten.html#rust_doc_test-deps">deps</a>, <a href="flatten.html#rust_doc_test-crate">crate</a>, <a href="flatten.html#rust_doc_test-proc_macro_deps">proc_macro_deps</a>)
</pre>
<p>Runs Rust documentation tests.</p>
<p>Example:</p>
<p>Suppose you have the following directory structure for a Rust library crate:</p>
<pre><code class="language-output">[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
lib.rs
</code></pre>
<p>To run <a href="https://doc.rust-lang.org/book/documentation.html#documentation-as-tests">documentation tests</a> for the <code>hello_lib</code> crate, define a <code>rust_doc_test</code> target that depends on the <code>hello_lib</code> <code>rust_library</code> target:</p>
<pre><code class="language-python">package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_doc_test")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_doc_test(
name = "hello_lib_doc_test",
crate = ":hello_lib",
)
</code></pre>
<p>Running <code>bazel test //hello_lib:hello_lib_doc_test</code> will run all documentation tests for the <code>hello_lib</code> library crate.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_doc_test-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_doc_test-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_doc_test-crate"></a>crate</td><td style="text-align: left">The label of the target to generate code documentation for. <code>rust_doc_test</code> can generate HTML code documentation for the source files of <code>rust_library</code> or <code>rust_binary</code> targets.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_doc_test-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_grpc_library"></a></p>
<h2 id="rust_grpc_library-1"><a class="header" href="#rust_grpc_library-1">rust_grpc_library</a></h2>
<pre>
rust_grpc_library(<a href="flatten.html#rust_grpc_library-name">name</a>, <a href="flatten.html#rust_grpc_library-deps">deps</a>, <a href="flatten.html#rust_grpc_library-crate_name">crate_name</a>, <a href="flatten.html#rust_grpc_library-rust_deps">rust_deps</a>, <a href="flatten.html#rust_grpc_library-rustc_flags">rustc_flags</a>)
</pre>
<p>Builds a Rust library crate from a set of <code>proto_library</code>s suitable for gRPC.</p>
<p>Example:</p>
<pre><code class="language-python">load("@rules_rust//proto/protobuf:defs.bzl", "rust_grpc_library")
proto_library(
name = "my_proto",
srcs = ["my.proto"]
)
rust_grpc_library(
name = "rust",
deps = [":my_proto"],
)
rust_binary(
name = "my_service",
srcs = ["my_service.rs"],
deps = [":rust"],
)
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_grpc_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_grpc_library-deps"></a>deps</td><td style="text-align: left">List of proto_library dependencies that will be built. One crate for each proto_library will be created with the corresponding gRPC stubs.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_grpc_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_grpc_library-rust_deps"></a>rust_deps</td><td style="text-align: left">The crates the generated library depends on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_grpc_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_library"></a></p>
<h2 id="rust_library-1"><a class="header" href="#rust_library-1">rust_library</a></h2>
<pre>
rust_library(<a href="flatten.html#rust_library-name">name</a>, <a href="flatten.html#rust_library-deps">deps</a>, <a href="flatten.html#rust_library-srcs">srcs</a>, <a href="flatten.html#rust_library-data">data</a>, <a href="flatten.html#rust_library-aliases">aliases</a>, <a href="flatten.html#rust_library-alwayslink">alwayslink</a>, <a href="flatten.html#rust_library-compile_data">compile_data</a>, <a href="flatten.html#rust_library-crate_features">crate_features</a>, <a href="flatten.html#rust_library-crate_name">crate_name</a>,
<a href="flatten.html#rust_library-crate_root">crate_root</a>, <a href="flatten.html#rust_library-disable_pipelining">disable_pipelining</a>, <a href="flatten.html#rust_library-edition">edition</a>, <a href="flatten.html#rust_library-proc_macro_deps">proc_macro_deps</a>, <a href="flatten.html#rust_library-rustc_env">rustc_env</a>, <a href="flatten.html#rust_library-rustc_env_files">rustc_env_files</a>,
<a href="flatten.html#rust_library-rustc_flags">rustc_flags</a>, <a href="flatten.html#rust_library-stamp">stamp</a>, <a href="flatten.html#rust_library-version">version</a>)
</pre>
<p>Builds a Rust library crate.</p>
<p>Example:</p>
<p>Suppose you have the following directory structure for a simple Rust library crate:</p>
<pre><code class="language-output">[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
greeter.rs
lib.rs
</code></pre>
<p><code>hello_lib/src/greeter.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct Greeter {
greeting: String,
}
impl Greeter {
pub fn new(greeting: &amp;str) -&gt; Greeter {
Greeter { greeting: greeting.to_string(), }
}
pub fn greet(&amp;self, thing: &amp;str) {
println!("{} {}", &amp;self.greeting, thing);
}
}
<span class="boring">}</span></code></pre></pre>
<p><code>hello_lib/src/lib.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub mod greeter;
<span class="boring">}</span></code></pre></pre>
<p><code>hello_lib/BUILD</code>:</p>
<pre><code class="language-python">package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_library")
rust_library(
name = "hello_lib",
srcs = [
"src/greeter.rs",
"src/lib.rs",
],
)
</code></pre>
<p>Build the library:</p>
<pre><code class="language-output">$ bazel build //hello_lib
INFO: Found 1 target...
Target //examples/rust/hello_lib:hello_lib up-to-date:
bazel-bin/examples/rust/hello_lib/libhello_lib.rlib
INFO: Elapsed time: 1.245s, Critical Path: 1.01s
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_library-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-disable_pipelining"></a>disable_pipelining</td><td style="text-align: left">Disables pipelining for this rule if it is globally enabled. This will cause this rule to not produce a <code>.rmeta</code> file and all the dependent crates will instead use the <code>.rlib</code> file.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr>
<tr><td style="text-align: left"><a id="rust_library-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_library_group"></a></p>
<h2 id="rust_library_group-1"><a class="header" href="#rust_library_group-1">rust_library_group</a></h2>
<pre>
rust_library_group(<a href="flatten.html#rust_library_group-name">name</a>, <a href="flatten.html#rust_library_group-deps">deps</a>)
</pre>
<p>Functions as an alias for a set of dependencies.</p>
<p>Specifically, the following are equivalent:</p>
<pre><code class="language-starlark">rust_library_group(
name = "crate_group",
deps = [
":crate1",
":crate2",
],
)
rust_library(
name = "foobar",
deps = [":crate_group"],
...
)
</code></pre>
<p>and</p>
<pre><code class="language-starlark">rust_library(
name = "foobar",
deps = [
":crate1",
":crate2",
],
...
)
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_library_group-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_library_group-deps"></a>deps</td><td style="text-align: left">Other dependencies to forward through this crate group.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_proc_macro"></a></p>
<h2 id="rust_proc_macro-1"><a class="header" href="#rust_proc_macro-1">rust_proc_macro</a></h2>
<pre>
rust_proc_macro(<a href="flatten.html#rust_proc_macro-name">name</a>, <a href="flatten.html#rust_proc_macro-deps">deps</a>, <a href="flatten.html#rust_proc_macro-srcs">srcs</a>, <a href="flatten.html#rust_proc_macro-data">data</a>, <a href="flatten.html#rust_proc_macro-aliases">aliases</a>, <a href="flatten.html#rust_proc_macro-alwayslink">alwayslink</a>, <a href="flatten.html#rust_proc_macro-compile_data">compile_data</a>, <a href="flatten.html#rust_proc_macro-crate_features">crate_features</a>,
<a href="flatten.html#rust_proc_macro-crate_name">crate_name</a>, <a href="flatten.html#rust_proc_macro-crate_root">crate_root</a>, <a href="flatten.html#rust_proc_macro-edition">edition</a>, <a href="flatten.html#rust_proc_macro-proc_macro_deps">proc_macro_deps</a>, <a href="flatten.html#rust_proc_macro-rustc_env">rustc_env</a>, <a href="flatten.html#rust_proc_macro-rustc_env_files">rustc_env_files</a>,
<a href="flatten.html#rust_proc_macro-rustc_flags">rustc_flags</a>, <a href="flatten.html#rust_proc_macro-stamp">stamp</a>, <a href="flatten.html#rust_proc_macro-version">version</a>)
</pre>
<p>Builds a Rust proc-macro crate.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_proc_macro-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proc_macro-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_prost_toolchain"></a></p>
<h2 id="rust_prost_toolchain-1"><a class="header" href="#rust_prost_toolchain-1">rust_prost_toolchain</a></h2>
<pre>
rust_prost_toolchain(<a href="flatten.html#rust_prost_toolchain-name">name</a>, <a href="flatten.html#rust_prost_toolchain-include_transitive_deps">include_transitive_deps</a>, <a href="flatten.html#rust_prost_toolchain-prost_opts">prost_opts</a>, <a href="flatten.html#rust_prost_toolchain-prost_plugin">prost_plugin</a>, <a href="flatten.html#rust_prost_toolchain-prost_plugin_flag">prost_plugin_flag</a>,
<a href="flatten.html#rust_prost_toolchain-prost_runtime">prost_runtime</a>, <a href="flatten.html#rust_prost_toolchain-prost_types">prost_types</a>, <a href="flatten.html#rust_prost_toolchain-proto_compiler">proto_compiler</a>, <a href="flatten.html#rust_prost_toolchain-tonic_opts">tonic_opts</a>, <a href="flatten.html#rust_prost_toolchain-tonic_plugin">tonic_plugin</a>,
<a href="flatten.html#rust_prost_toolchain-tonic_plugin_flag">tonic_plugin_flag</a>, <a href="flatten.html#rust_prost_toolchain-tonic_runtime">tonic_runtime</a>)
</pre>
<p>Rust Prost toolchain rule.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-include_transitive_deps"></a>include_transitive_deps</td><td style="text-align: left">Whether to include transitive dependencies. If set to True, all transitive dependencies will directly accessible by the dependent crate.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_opts"></a>prost_opts</td><td style="text-align: left">Additional options to add to Prost.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_plugin"></a>prost_plugin</td><td style="text-align: left">Additional plugins to add to Prost.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_plugin_flag"></a>prost_plugin_flag</td><td style="text-align: left">Prost plugin flag format. (e.g. <code>--plugin=protoc-gen-prost=%s</code>)</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"--plugin=protoc-gen-prost=%s"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_runtime"></a>prost_runtime</td><td style="text-align: left">The Prost runtime crates to use.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-prost_types"></a>prost_types</td><td style="text-align: left">The Prost types crates to use.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-proto_compiler"></a>proto_compiler</td><td style="text-align: left">The protoc compiler to use. Note that this attribute is deprecated - prefer to use --incompatible_enable_proto_toolchain_resolution.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_opts"></a>tonic_opts</td><td style="text-align: left">Additional options to add to Tonic.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_plugin"></a>tonic_plugin</td><td style="text-align: left">Additional plugins to add to Tonic.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_plugin_flag"></a>tonic_plugin_flag</td><td style="text-align: left">Tonic plugin flag format. (e.g. <code>--plugin=protoc-gen-tonic=%s</code>))</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"--plugin=protoc-gen-tonic=%s"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_prost_toolchain-tonic_runtime"></a>tonic_runtime</td><td style="text-align: left">The Tonic runtime crates to use.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_proto_library"></a></p>
<h2 id="rust_proto_library-1"><a class="header" href="#rust_proto_library-1">rust_proto_library</a></h2>
<pre>
rust_proto_library(<a href="flatten.html#rust_proto_library-name">name</a>, <a href="flatten.html#rust_proto_library-deps">deps</a>, <a href="flatten.html#rust_proto_library-crate_name">crate_name</a>, <a href="flatten.html#rust_proto_library-rust_deps">rust_deps</a>, <a href="flatten.html#rust_proto_library-rustc_flags">rustc_flags</a>)
</pre>
<p>Builds a Rust library crate from a set of <code>proto_library</code>s.</p>
<p>Example:</p>
<pre><code class="language-python">load("@rules_rust//proto/protobuf:defs.bzl", "rust_proto_library")
proto_library(
name = "my_proto",
srcs = ["my.proto"]
)
rust_proto_library(
name = "rust",
deps = [":my_proto"],
)
rust_binary(
name = "my_proto_binary",
srcs = ["my_proto_binary.rs"],
deps = [":rust"],
)
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_proto_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_proto_library-deps"></a>deps</td><td style="text-align: left">List of proto_library dependencies that will be built. One crate for each proto_library will be created with the corresponding stubs.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_proto_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proto_library-rust_deps"></a>rust_deps</td><td style="text-align: left">The crates the generated library depends on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_proto_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_shared_library"></a></p>
<h2 id="rust_shared_library-1"><a class="header" href="#rust_shared_library-1">rust_shared_library</a></h2>
<pre>
rust_shared_library(<a href="flatten.html#rust_shared_library-name">name</a>, <a href="flatten.html#rust_shared_library-deps">deps</a>, <a href="flatten.html#rust_shared_library-srcs">srcs</a>, <a href="flatten.html#rust_shared_library-data">data</a>, <a href="flatten.html#rust_shared_library-aliases">aliases</a>, <a href="flatten.html#rust_shared_library-alwayslink">alwayslink</a>, <a href="flatten.html#rust_shared_library-compile_data">compile_data</a>, <a href="flatten.html#rust_shared_library-crate_features">crate_features</a>,
<a href="flatten.html#rust_shared_library-crate_name">crate_name</a>, <a href="flatten.html#rust_shared_library-crate_root">crate_root</a>, <a href="flatten.html#rust_shared_library-edition">edition</a>, <a href="flatten.html#rust_shared_library-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="flatten.html#rust_shared_library-malloc">malloc</a>,
<a href="flatten.html#rust_shared_library-platform">platform</a>, <a href="flatten.html#rust_shared_library-proc_macro_deps">proc_macro_deps</a>, <a href="flatten.html#rust_shared_library-rustc_env">rustc_env</a>, <a href="flatten.html#rust_shared_library-rustc_env_files">rustc_env_files</a>, <a href="flatten.html#rust_shared_library-rustc_flags">rustc_flags</a>, <a href="flatten.html#rust_shared_library-stamp">stamp</a>,
<a href="flatten.html#rust_shared_library-version">version</a>)
</pre>
<p>Builds a Rust shared library.</p>
<p>This shared library will contain all transitively reachable crates and native objects.
It is meant to be used when producing an artifact that is then consumed by some other build system
(for example to produce a shared library that Python program links against).</p>
<p>This rule provides CcInfo, so it can be used everywhere Bazel expects <code>rules_cc</code>.</p>
<p>When building the whole binary in Bazel, use <code>rust_library</code> instead.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_shared_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-malloc"></a>malloc</td><td style="text-align: left">Override the default dependency on <code>malloc</code>.<br><br>By default, Rust binaries linked with cc_common.link are linked against <code>@bazel_tools//tools/cpp:malloc"</code>, which is an empty library and the resulting binary will use libc's <code>malloc</code>. This label must refer to a <code>cc_library</code> rule.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@bazel_tools//tools/cpp:malloc"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the shared library to.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr>
<tr><td style="text-align: left"><a id="rust_shared_library-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_static_library"></a></p>
<h2 id="rust_static_library-1"><a class="header" href="#rust_static_library-1">rust_static_library</a></h2>
<pre>
rust_static_library(<a href="flatten.html#rust_static_library-name">name</a>, <a href="flatten.html#rust_static_library-deps">deps</a>, <a href="flatten.html#rust_static_library-srcs">srcs</a>, <a href="flatten.html#rust_static_library-data">data</a>, <a href="flatten.html#rust_static_library-aliases">aliases</a>, <a href="flatten.html#rust_static_library-alwayslink">alwayslink</a>, <a href="flatten.html#rust_static_library-compile_data">compile_data</a>, <a href="flatten.html#rust_static_library-crate_features">crate_features</a>,
<a href="flatten.html#rust_static_library-crate_name">crate_name</a>, <a href="flatten.html#rust_static_library-crate_root">crate_root</a>, <a href="flatten.html#rust_static_library-edition">edition</a>, <a href="flatten.html#rust_static_library-platform">platform</a>, <a href="flatten.html#rust_static_library-proc_macro_deps">proc_macro_deps</a>, <a href="flatten.html#rust_static_library-rustc_env">rustc_env</a>,
<a href="flatten.html#rust_static_library-rustc_env_files">rustc_env_files</a>, <a href="flatten.html#rust_static_library-rustc_flags">rustc_flags</a>, <a href="flatten.html#rust_static_library-stamp">stamp</a>, <a href="flatten.html#rust_static_library-version">version</a>)
</pre>
<p>Builds a Rust static library.</p>
<p>This static library will contain all transitively reachable crates and native objects.
It is meant to be used when producing an artifact that is then consumed by some other build system
(for example to produce an archive that Python program links against).</p>
<p>This rule provides CcInfo, so it can be used everywhere Bazel expects <code>rules_cc</code>.</p>
<p>When building the whole binary in Bazel, use <code>rust_library</code> instead.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_static_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the static library to.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr>
<tr><td style="text-align: left"><a id="rust_static_library-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_stdlib_filegroup"></a></p>
<h2 id="rust_stdlib_filegroup"><a class="header" href="#rust_stdlib_filegroup">rust_stdlib_filegroup</a></h2>
<pre>
rust_stdlib_filegroup(<a href="flatten.html#rust_stdlib_filegroup-name">name</a>, <a href="flatten.html#rust_stdlib_filegroup-srcs">srcs</a>)
</pre>
<p>A dedicated filegroup-like rule for Rust stdlib artifacts.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_stdlib_filegroup-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_stdlib_filegroup-srcs"></a>srcs</td><td style="text-align: left">The list of targets/files that are components of the rust-stdlib file group</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rust_test"></a></p>
<h2 id="rust_test-1"><a class="header" href="#rust_test-1">rust_test</a></h2>
<pre>
rust_test(<a href="flatten.html#rust_test-name">name</a>, <a href="flatten.html#rust_test-deps">deps</a>, <a href="flatten.html#rust_test-srcs">srcs</a>, <a href="flatten.html#rust_test-data">data</a>, <a href="flatten.html#rust_test-aliases">aliases</a>, <a href="flatten.html#rust_test-alwayslink">alwayslink</a>, <a href="flatten.html#rust_test-compile_data">compile_data</a>, <a href="flatten.html#rust_test-crate">crate</a>, <a href="flatten.html#rust_test-crate_features">crate_features</a>,
<a href="flatten.html#rust_test-crate_name">crate_name</a>, <a href="flatten.html#rust_test-crate_root">crate_root</a>, <a href="flatten.html#rust_test-edition">edition</a>, <a href="flatten.html#rust_test-env">env</a>, <a href="flatten.html#rust_test-env_inherit">env_inherit</a>, <a href="flatten.html#rust_test-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="flatten.html#rust_test-malloc">malloc</a>,
<a href="flatten.html#rust_test-platform">platform</a>, <a href="flatten.html#rust_test-proc_macro_deps">proc_macro_deps</a>, <a href="flatten.html#rust_test-rustc_env">rustc_env</a>, <a href="flatten.html#rust_test-rustc_env_files">rustc_env_files</a>, <a href="flatten.html#rust_test-rustc_flags">rustc_flags</a>, <a href="flatten.html#rust_test-stamp">stamp</a>,
<a href="flatten.html#rust_test-use_libtest_harness">use_libtest_harness</a>, <a href="flatten.html#rust_test-version">version</a>)
</pre>
<p>Builds a Rust test crate.</p>
<p>Examples:</p>
<p>Suppose you have the following directory structure for a Rust library crate with unit test code in the library sources:</p>
<pre><code class="language-output">[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
lib.rs
</code></pre>
<p><code>hello_lib/src/lib.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>pub struct Greeter {
greeting: String,
}
impl Greeter {
pub fn new(greeting: &amp;str) -&gt; Greeter {
Greeter { greeting: greeting.to_string(), }
}
pub fn greet(&amp;self, thing: &amp;str) -&gt; String {
format!("{} {}", &amp;self.greeting, thing)
}
}
#[cfg(test)]
mod test {
use super::Greeter;
#[test]
fn test_greeting() {
let hello = Greeter::new("Hi");
assert_eq!("Hi Rust", hello.greet("Rust"));
}
}
<span class="boring">}</span></code></pre></pre>
<p>To build and run the tests, simply add a <code>rust_test</code> rule with no <code>srcs</code>
and only depends on the <code>hello_lib</code> <code>rust_library</code> target via the
<code>crate</code> attribute:</p>
<p><code>hello_lib/BUILD</code>:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_test(
name = "hello_lib_test",
crate = ":hello_lib",
# You may add other deps that are specific to the test configuration
deps = ["//some/dev/dep"],
)
</code></pre>
<p>Run the test with <code>bazel test //hello_lib:hello_lib_test</code>.</p>
<h3 id="example-test-directory-1"><a class="header" href="#example-test-directory-1">Example: <code>test</code> directory</a></h3>
<p>Integration tests that live in the <a href="http://doc.rust-lang.org/book/testing.html#the-tests-directory"><code>tests</code> directory</a>, they are essentially built as separate crates. Suppose you have the following directory structure where <code>greeting.rs</code> is an integration test for the <code>hello_lib</code> library crate:</p>
<pre><code class="language-output">[workspace]/
WORKSPACE
hello_lib/
BUILD
src/
lib.rs
tests/
greeting.rs
</code></pre>
<p><code>hello_lib/tests/greeting.rs</code>:</p>
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
</span><span class="boring">fn main() {
</span>extern crate hello_lib;
use hello_lib;
#[test]
fn test_greeting() {
let hello = greeter::Greeter::new("Hello");
assert_eq!("Hello world", hello.greeting("world"));
}
<span class="boring">}</span></code></pre></pre>
<p>To build the <code>greeting.rs</code> integration test, simply add a <code>rust_test</code> target
with <code>greeting.rs</code> in <code>srcs</code> and a dependency on the <code>hello_lib</code> target:</p>
<p><code>hello_lib/BUILD</code>:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_test(
name = "greeting_test",
srcs = ["tests/greeting.rs"],
deps = [":hello_lib"],
)
</code></pre>
<p>Run the test with <code>bazel test //hello_lib:greeting_test</code>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_test-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_test-deps"></a>deps</td><td style="text-align: left">List of other libraries to be linked to this library target.<br><br>These can be either other <code>rust_library</code> targets or <code>cc_library</code> targets if linking a native library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-srcs"></a>srcs</td><td style="text-align: left">List of Rust <code>.rs</code> source files used to build the library.<br><br>If <code>srcs</code> contains more than one file, then there must be a file either named <code>lib.rs</code>. Otherwise, <code>crate_root</code> must be set to the source file that is the root of the crate to be passed to rustc to build this crate.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-data"></a>data</td><td style="text-align: left">List of files used by this rule at compile time and runtime.<br><br>If including data at compile time with include_str!() and similar, prefer <code>compile_data</code> over <code>data</code>, to prevent the data also being included in the runfiles.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target<br><br>These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: Label -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-alwayslink"></a>alwayslink</td><td style="text-align: left">If 1, any binary that depends (directly or indirectly) on this library will link in all the object files even if some contain no symbols referenced by the binary.<br><br>This attribute is used by the C++ Starlark API when passing CcInfo providers.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-compile_data"></a>compile_data</td><td style="text-align: left">List of files used by this rule at compile time.<br><br>This attribute can be used to specify any data files that are embedded into the library, such as via the <a href="https://doc.rust-lang.org/std/macro.include_str!.html"><code>include_str!</code></a> macro.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-crate"></a>crate</td><td style="text-align: left">Target inline tests declared in the given crate<br><br>These tests are typically those that would be held out under <code>#[cfg(test)]</code> declarations.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-crate_features"></a>crate_features</td><td style="text-align: left">List of features to enable for this crate.<br><br>Features are defined in the code using the <code>#[cfg(feature = "foo")]</code> configuration option. The features listed here will be passed to <code>rustc</code> with <code>--cfg feature="${feature_name}"</code> flags.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for this target.<br><br>This must be a valid Rust identifier, i.e. it may contain only alphanumeric characters and underscores. Defaults to the target name, with any hyphens replaced by underscores.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to <code>rustc</code> to be used for building this crate.<br><br>If <code>crate_root</code> is not set, then this rule will look for a <code>lib.rs</code> file (or <code>main.rs</code> for rust_binary) or the single file in <code>srcs</code> if <code>srcs</code> contains only one file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-edition"></a>edition</td><td style="text-align: left">The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-env"></a>env</td><td style="text-align: left">Specifies additional environment variables to set when the test is executed by bazel test. Values are subject to <code>$(rootpath)</code>, <code>$(execpath)</code>, location, and <a href="https://docs.bazel.build/versions/master/be/make-variables.html">"Make variable"</a> substitution.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-env_inherit"></a>env_inherit</td><td style="text-align: left">Specifies additional environment variables to inherit from the external environment when the test is executed by bazel test.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Whether to use cc_common.link to link rust binaries. Possible values: [-1, 0, 1]. -1 means use the value of the toolchain.experimental_use_cc_common_link boolean build setting to determine. 0 means do not use cc_common.link (use rustc instead). 1 means use cc_common.link.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>-1</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-malloc"></a>malloc</td><td style="text-align: left">Override the default dependency on <code>malloc</code>.<br><br>By default, Rust binaries linked with cc_common.link are linked against <code>@bazel_tools//tools/cpp:malloc"</code>, which is an empty library and the resulting binary will use libc's <code>malloc</code>. This label must refer to a <code>cc_library</code> rule.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@bazel_tools//tools/cpp:malloc"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-platform"></a>platform</td><td style="text-align: left">Optional platform to transition the test to.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of <code>rust_proc_macro</code> targets used to help build this library target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-rustc_env"></a>rustc_env</td><td style="text-align: left">Dictionary of additional <code>"key": "value"</code> environment variables to set for rustc.<br><br>rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc.<br><br>These files should contain a single variable per line, of format <code>NAME=value</code>, and newlines may be included in a value by ending a line with a trailing back-slash (<code>\\</code>).<br><br>The order that these files will be processed is unspecified, so multiple definitions of a particular variable are discouraged.<br><br>Note that the variables here are subject to <a href="https://docs.bazel.build/versions/main/user-manual.html#workspace_status">workspace status</a> stamping should the <code>stamp</code> attribute be enabled. Stamp variables should be wrapped in brackets in order to be resolved. E.g. <code>NAME={WORKSPACE_STATUS_VARIABLE}</code>.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.<br><br>These strings are subject to Make variable expansion for predefined source/output path variables like <code>$location</code>, <code>$execpath</code>, and <code>$rootpath</code>. This expansion is useful if you wish to pass a generated file of arguments to rustc: <code>@$(location //package:target)</code>.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-stamp"></a>stamp</td><td style="text-align: left">Whether to encode build information into the <code>Rustc</code> action. Possible values:<br><br>- <code>stamp = 1</code>: Always stamp the build information into the <code>Rustc</code> action, even in <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--nostamp</a> builds. This setting should be avoided, since it potentially kills remote caching for the target and any downstream actions that depend on it.<br><br>- <code>stamp = 0</code>: Always replace build information by constant values. This gives good build result caching.<br><br>- <code>stamp = -1</code>: Embedding of build information is controlled by the <a href="https://docs.bazel.build/versions/main/user-manual.html#flag--stamp">--[no]stamp</a> flag.<br><br>Stamped targets are not rebuilt unless their dependencies change.<br><br>For example if a <code>rust_library</code> is stamped, and a <code>rust_binary</code> depends on that library, the stamped library won't be rebuilt when we change sources of the <code>rust_binary</code>. This is different from how <a href="https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library.linkstamp"><code>cc_library.linkstamps</code></a> behaves.</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>0</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-use_libtest_harness"></a>use_libtest_harness</td><td style="text-align: left">Whether to use <code>libtest</code>. For targets using this flag, individual tests can be run by using the <a href="https://docs.bazel.build/versions/4.0.0/command-line-reference.html#flag--test_arg">--test_arg</a> flag. E.g. <code>bazel test //src:rust_test --test_arg=foo::test::test_fn</code>.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test-version"></a>version</td><td style="text-align: left">A version to inject in the cargo environment variable.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"0.0.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_toolchain"></a></p>
<h2 id="rust_toolchain"><a class="header" href="#rust_toolchain">rust_toolchain</a></h2>
<pre>
rust_toolchain(<a href="flatten.html#rust_toolchain-name">name</a>, <a href="flatten.html#rust_toolchain-allocator_library">allocator_library</a>, <a href="flatten.html#rust_toolchain-binary_ext">binary_ext</a>, <a href="flatten.html#rust_toolchain-cargo">cargo</a>, <a href="flatten.html#rust_toolchain-cargo_clippy">cargo_clippy</a>, <a href="flatten.html#rust_toolchain-clippy_driver">clippy_driver</a>, <a href="flatten.html#rust_toolchain-debug_info">debug_info</a>,
<a href="flatten.html#rust_toolchain-default_edition">default_edition</a>, <a href="flatten.html#rust_toolchain-dylib_ext">dylib_ext</a>, <a href="flatten.html#rust_toolchain-env">env</a>, <a href="flatten.html#rust_toolchain-exec_triple">exec_triple</a>, <a href="flatten.html#rust_toolchain-experimental_link_std_dylib">experimental_link_std_dylib</a>,
<a href="flatten.html#rust_toolchain-experimental_use_cc_common_link">experimental_use_cc_common_link</a>, <a href="flatten.html#rust_toolchain-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="flatten.html#rust_toolchain-extra_rustc_flags">extra_rustc_flags</a>,
<a href="flatten.html#rust_toolchain-extra_rustc_flags_for_crate_types">extra_rustc_flags_for_crate_types</a>, <a href="flatten.html#rust_toolchain-global_allocator_library">global_allocator_library</a>, <a href="flatten.html#rust_toolchain-llvm_cov">llvm_cov</a>, <a href="flatten.html#rust_toolchain-llvm_profdata">llvm_profdata</a>,
<a href="flatten.html#rust_toolchain-llvm_tools">llvm_tools</a>, <a href="flatten.html#rust_toolchain-opt_level">opt_level</a>, <a href="flatten.html#rust_toolchain-per_crate_rustc_flags">per_crate_rustc_flags</a>, <a href="flatten.html#rust_toolchain-rust_doc">rust_doc</a>, <a href="flatten.html#rust_toolchain-rust_std">rust_std</a>, <a href="flatten.html#rust_toolchain-rustc">rustc</a>, <a href="flatten.html#rust_toolchain-rustc_lib">rustc_lib</a>,
<a href="flatten.html#rust_toolchain-rustfmt">rustfmt</a>, <a href="flatten.html#rust_toolchain-staticlib_ext">staticlib_ext</a>, <a href="flatten.html#rust_toolchain-stdlib_linkflags">stdlib_linkflags</a>, <a href="flatten.html#rust_toolchain-strip_level">strip_level</a>, <a href="flatten.html#rust_toolchain-target_json">target_json</a>, <a href="flatten.html#rust_toolchain-target_triple">target_triple</a>)
</pre>
<p>Declares a Rust toolchain for use.</p>
<p>This is for declaring a custom toolchain, eg. for configuring a particular version of rust or supporting a new platform.</p>
<p>Example:</p>
<p>Suppose the core rust team has ported the compiler to a new target CPU, called <code>cpuX</code>. This support can be used in Bazel by defining a new toolchain definition and declaration:</p>
<pre><code class="language-python">load('@rules_rust//rust:toolchain.bzl', 'rust_toolchain')
rust_toolchain(
name = "rust_cpuX_impl",
binary_ext = "",
dylib_ext = ".so",
exec_triple = "cpuX-unknown-linux-gnu",
rust_doc = "@rust_cpuX//:rustdoc",
rust_std = "@rust_cpuX//:rust_std",
rustc = "@rust_cpuX//:rustc",
rustc_lib = "@rust_cpuX//:rustc_lib",
staticlib_ext = ".a",
stdlib_linkflags = ["-lpthread", "-ldl"],
target_triple = "cpuX-unknown-linux-gnu",
)
toolchain(
name = "rust_cpuX",
exec_compatible_with = [
"@platforms//cpu:cpuX",
"@platforms//os:linux",
],
target_compatible_with = [
"@platforms//cpu:cpuX",
"@platforms//os:linux",
],
toolchain = ":rust_cpuX_impl",
)
</code></pre>
<p>Then, either add the label of the toolchain rule to <code>register_toolchains</code> in the WORKSPACE, or pass it to the <code>"--extra_toolchains"</code> flag for Bazel, and it will be used.</p>
<p>See <code>@rules_rust//rust:repositories.bzl</code> for examples of defining the <code>@rust_cpuX</code> repository with the actual binaries and libraries.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-allocator_library"></a>allocator_library</td><td style="text-align: left">Target that provides allocator functions when rust_library targets are embedded in a cc_binary.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//ffi/cc/allocator_library"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-binary_ext"></a>binary_ext</td><td style="text-align: left">The extension for binaries created from rustc.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-cargo"></a>cargo</td><td style="text-align: left">The location of the <code>cargo</code> binary. Can be a direct source or a filegroup containing one item.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-cargo_clippy"></a>cargo_clippy</td><td style="text-align: left">The location of the <code>cargo_clippy</code> binary. Can be a direct source or a filegroup containing one item.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-clippy_driver"></a>clippy_driver</td><td style="text-align: left">The location of the <code>clippy-driver</code> binary. Can be a direct source or a filegroup containing one item.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-debug_info"></a>debug_info</td><td style="text-align: left">Rustc debug info levels per opt level</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{"dbg": "2", "fastbuild": "0", "opt": "0"}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-default_edition"></a>default_edition</td><td style="text-align: left">The edition to use for rust_* rules that don't specify an edition. If absent, every rule is required to specify its <code>edition</code> attribute.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-dylib_ext"></a>dylib_ext</td><td style="text-align: left">The extension for dynamic libraries created from rustc.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-env"></a>env</td><td style="text-align: left">Environment variables to set in actions.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-exec_triple"></a>exec_triple</td><td style="text-align: left">The platform triple for the toolchains execution environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-experimental_link_std_dylib"></a>experimental_link_std_dylib</td><td style="text-align: left">Label to a boolean build setting that controls whether whether to link libstd dynamically.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//rust/settings:experimental_link_std_dylib"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-experimental_use_cc_common_link"></a>experimental_use_cc_common_link</td><td style="text-align: left">Label to a boolean build setting that controls whether cc_common.link is used to link rust binaries.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//rust/settings:experimental_use_cc_common_link"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-extra_exec_rustc_flags"></a>extra_exec_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in exec configuration</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-extra_rustc_flags"></a>extra_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in non-exec configuration. Subject to location expansion with respect to the srcs of the <code>rust_std</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-extra_rustc_flags_for_crate_types"></a>extra_rustc_flags_for_crate_types</td><td style="text-align: left">Extra flags to pass to rustc based on crate type</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; List of strings</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions for when a global allocator is present.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//ffi/cc/global_allocator_library"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-llvm_cov"></a>llvm_cov</td><td style="text-align: left">The location of the <code>llvm-cov</code> binary. Can be a direct source or a filegroup containing one item. If None, rust code is not instrumented for coverage.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-llvm_profdata"></a>llvm_profdata</td><td style="text-align: left">The location of the <code>llvm-profdata</code> binary. Can be a direct source or a filegroup containing one item. If <code>llvm_cov</code> is None, this can be None as well and rust code is not instrumented for coverage.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-llvm_tools"></a>llvm_tools</td><td style="text-align: left">LLVM tools that are shipped with the Rust toolchain.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-opt_level"></a>opt_level</td><td style="text-align: left">Rustc optimization levels.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{"dbg": "0", "fastbuild": "0", "opt": "3"}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-per_crate_rustc_flags"></a>per_crate_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in non-exec configuration</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-rust_doc"></a>rust_doc</td><td style="text-align: left">The location of the <code>rustdoc</code> binary. Can be a direct source or a filegroup containing one item.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-rust_std"></a>rust_std</td><td style="text-align: left">The Rust standard library.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-rustc"></a>rustc</td><td style="text-align: left">The location of the <code>rustc</code> binary. Can be a direct source or a filegroup containing one item.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-rustc_lib"></a>rustc_lib</td><td style="text-align: left">The libraries used by rustc during compilation.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-rustfmt"></a>rustfmt</td><td style="text-align: left"><strong>Deprecated</strong>: Instead see <a href="flatten.html#rustfmt_toolchain">rustfmt_toolchain</a></td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-staticlib_ext"></a>staticlib_ext</td><td style="text-align: left">The extension for static libraries created from rustc.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-stdlib_linkflags"></a>stdlib_linkflags</td><td style="text-align: left">Additional linker flags to use when Rust standard library is linked by a C++ linker (rustc will deal with these automatically). Subject to location expansion with respect to the srcs of the <code>rust_std</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-strip_level"></a>strip_level</td><td style="text-align: left">Rustc strip levels. For all potential options, see https://doc.rust-lang.org/rustc/codegen-options/index.html#strip</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{"dbg": "none", "fastbuild": "none", "opt": "debuginfo"}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-target_json"></a>target_json</td><td style="text-align: left">Override the target_triple with a custom target specification. For more details see: https://doc.rust-lang.org/rustc/targets/custom.html</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain-target_triple"></a>target_triple</td><td style="text-align: left">The platform triple for the toolchains target environment. For more details see: https://docs.bazel.build/versions/master/skylark/rules.html#configurations</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_wasm_bindgen"></a></p>
<h2 id="rust_wasm_bindgen-1"><a class="header" href="#rust_wasm_bindgen-1">rust_wasm_bindgen</a></h2>
<pre>
rust_wasm_bindgen(<a href="flatten.html#rust_wasm_bindgen-name">name</a>, <a href="flatten.html#rust_wasm_bindgen-bindgen_flags">bindgen_flags</a>, <a href="flatten.html#rust_wasm_bindgen-target">target</a>, <a href="flatten.html#rust_wasm_bindgen-target_arch">target_arch</a>, <a href="flatten.html#rust_wasm_bindgen-wasm_file">wasm_file</a>)
</pre>
<p>Generates javascript and typescript bindings for a webassembly module using <a href="https://rustwasm.github.io/docs/wasm-bindgen/">wasm-bindgen</a>.</p>
<p>An example of this rule in use can be seen at <a href="../examples/wasm">@rules_rust//examples/wasm</a></p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen-bindgen_flags"></a>bindgen_flags</td><td style="text-align: left">Flags to pass directly to the bindgen executable. See https://github.com/rustwasm/wasm-bindgen/ for details.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen-target"></a>target</td><td style="text-align: left">The type of output to generate. See https://rustwasm.github.io/wasm-bindgen/reference/deployment.html for details.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"bundler"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen-target_arch"></a>target_arch</td><td style="text-align: left">The target architecture to use for the wasm-bindgen command line option.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"wasm32"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen-wasm_file"></a>wasm_file</td><td style="text-align: left">The <code>.wasm</code> file or crate to generate bindings for.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rust_wasm_bindgen_toolchain"></a></p>
<h2 id="rust_wasm_bindgen_toolchain-1"><a class="header" href="#rust_wasm_bindgen_toolchain-1">rust_wasm_bindgen_toolchain</a></h2>
<pre>
rust_wasm_bindgen_toolchain(<a href="flatten.html#rust_wasm_bindgen_toolchain-name">name</a>, <a href="flatten.html#rust_wasm_bindgen_toolchain-bindgen">bindgen</a>)
</pre>
<p>The tools required for the <code>rust_wasm_bindgen</code> rule.</p>
<p>In cases where users want to control or change the version of <code>wasm-bindgen</code> used by <a href="flatten.html#rust_wasm_bindgen">rust_wasm_bindgen</a>,
a unique toolchain can be created as in the example below:</p>
<pre><code class="language-python">load("@rules_rust//bindgen:bindgen.bzl", "rust_bindgen_toolchain")
rust_bindgen_toolchain(
bindgen = "//3rdparty/crates:wasm_bindgen_cli__bin",
)
toolchain(
name = "wasm_bindgen_toolchain",
toolchain = "wasm_bindgen_toolchain_impl",
toolchain_type = "@rules_rust//wasm_bindgen:toolchain_type",
)
</code></pre>
<p>Now that you have your own toolchain, you need to register it by
inserting the following statement in your <code>WORKSPACE</code> file:</p>
<pre><code class="language-python">register_toolchains("//my/toolchains:wasm_bindgen_toolchain")
</code></pre>
<p>For additional information, see the <a href="https://docs.bazel.build/versions/master/toolchains.html">Bazel toolchains documentation</a>.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen_toolchain-bindgen"></a>bindgen</td><td style="text-align: left">The label of a <code>wasm-bindgen-cli</code> executable.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><a id="rustfmt_test"></a></p>
<h2 id="rustfmt_test-1"><a class="header" href="#rustfmt_test-1">rustfmt_test</a></h2>
<pre>
rustfmt_test(<a href="flatten.html#rustfmt_test-name">name</a>, <a href="flatten.html#rustfmt_test-targets">targets</a>)
</pre>
<p>A test rule for performing <code>rustfmt --check</code> on a set of targets</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rustfmt_test-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rustfmt_test-targets"></a>targets</td><td style="text-align: left">Rust targets to run <code>rustfmt --check</code> on.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
</tbody></table>
</div>
<p><a id="rustfmt_toolchain"></a></p>
<h2 id="rustfmt_toolchain-1"><a class="header" href="#rustfmt_toolchain-1">rustfmt_toolchain</a></h2>
<pre>
rustfmt_toolchain(<a href="flatten.html#rustfmt_toolchain-name">name</a>, <a href="flatten.html#rustfmt_toolchain-rustc">rustc</a>, <a href="flatten.html#rustfmt_toolchain-rustc_lib">rustc_lib</a>, <a href="flatten.html#rustfmt_toolchain-rustfmt">rustfmt</a>)
</pre>
<p>A toolchain for <a href="https://rust-lang.github.io/rustfmt/">rustfmt</a></p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rustfmt_toolchain-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rustfmt_toolchain-rustc"></a>rustc</td><td style="text-align: left">The location of the <code>rustc</code> binary. Can be a direct source or a filegroup containing one item.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rustfmt_toolchain-rustc_lib"></a>rustc_lib</td><td style="text-align: left">The libraries used by rustc during compilation.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rustfmt_toolchain-rustfmt"></a>rustfmt</td><td style="text-align: left">The location of the <code>rustfmt</code> binary. Can be a direct source or a filegroup containing one item.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="CrateInfo"></a></p>
<h2 id="crateinfo"><a class="header" href="#crateinfo">CrateInfo</a></h2>
<pre>
CrateInfo(<a href="flatten.html#CrateInfo-aliases">aliases</a>, <a href="flatten.html#CrateInfo-compile_data">compile_data</a>, <a href="flatten.html#CrateInfo-compile_data_targets">compile_data_targets</a>, <a href="flatten.html#CrateInfo-data">data</a>, <a href="flatten.html#CrateInfo-deps">deps</a>, <a href="flatten.html#CrateInfo-edition">edition</a>, <a href="flatten.html#CrateInfo-is_test">is_test</a>, <a href="flatten.html#CrateInfo-metadata">metadata</a>, <a href="flatten.html#CrateInfo-name">name</a>,
<a href="flatten.html#CrateInfo-output">output</a>, <a href="flatten.html#CrateInfo-owner">owner</a>, <a href="flatten.html#CrateInfo-proc_macro_deps">proc_macro_deps</a>, <a href="flatten.html#CrateInfo-root">root</a>, <a href="flatten.html#CrateInfo-rustc_env">rustc_env</a>, <a href="flatten.html#CrateInfo-rustc_env_files">rustc_env_files</a>, <a href="flatten.html#CrateInfo-rustc_output">rustc_output</a>,
<a href="flatten.html#CrateInfo-rustc_rmeta_output">rustc_rmeta_output</a>, <a href="flatten.html#CrateInfo-srcs">srcs</a>, <a href="flatten.html#CrateInfo-std_dylib">std_dylib</a>, <a href="flatten.html#CrateInfo-type">type</a>, <a href="flatten.html#CrateInfo-wrapped_crate_type">wrapped_crate_type</a>)
</pre>
<p>A provider containing general Crate information.</p>
<p><strong>FIELDS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="CrateInfo-aliases"></a>aliases</td><td style="text-align: left">Dict[Label, String]: Renamed and aliased crates</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-compile_data"></a>compile_data</td><td style="text-align: left">depset[File]: Compile data required by this crate.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-compile_data_targets"></a>compile_data_targets</td><td style="text-align: left">depset[Label]: Compile data targets required by this crate.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-data"></a>data</td><td style="text-align: left">depset[File]: Compile data required by crates that use the current crate as a proc-macro.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-deps"></a>deps</td><td style="text-align: left">depset[DepVariantInfo]: This crate's (rust or cc) dependencies' providers.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-edition"></a>edition</td><td style="text-align: left">str: The edition of this crate.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-is_test"></a>is_test</td><td style="text-align: left">bool: If the crate is being compiled in a test context</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-metadata"></a>metadata</td><td style="text-align: left">File: The output from rustc from producing the output file. It is optional.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-name"></a>name</td><td style="text-align: left">str: The name of this crate.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-output"></a>output</td><td style="text-align: left">File: The output File that will be produced, depends on crate type.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-owner"></a>owner</td><td style="text-align: left">Label: The label of the target that produced this CrateInfo</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">depset[DepVariantInfo]: This crate's rust proc_macro dependencies' providers.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-root"></a>root</td><td style="text-align: left">File: The source File entrypoint to this crate, eg. lib.rs</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-rustc_env"></a>rustc_env</td><td style="text-align: left">Dict[String, String]: Additional <code>"key": "value"</code> environment variables to set for rustc.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">[File]: Files containing additional environment variables to set for rustc.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-rustc_output"></a>rustc_output</td><td style="text-align: left">File: The output from rustc from producing the output file. It is optional.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-rustc_rmeta_output"></a>rustc_rmeta_output</td><td style="text-align: left">File: The rmeta file produced for this crate. It is optional.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-srcs"></a>srcs</td><td style="text-align: left">depset[File]: All source Files that are part of the crate.</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-std_dylib"></a>std_dylib</td><td style="text-align: left">File: libstd.so file</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-type"></a>type</td><td style="text-align: left">str: The type of this crate (see <a href="https://doc.rust-lang.org/rustc/command-line-arguments.html#--crate-type-a-list-of-types-of-crates-for-the-compiler-to-emit">rustc --crate-type</a>).</td></tr>
<tr><td style="text-align: left"><a id="CrateInfo-wrapped_crate_type"></a>wrapped_crate_type</td><td style="text-align: left">str, optional: The original crate type for targets generated using a previously defined crate (typically tests using the <code>rust_test::crate</code> attribute)</td></tr>
</tbody></table>
</div>
<p><a id="DepInfo"></a></p>
<h2 id="depinfo"><a class="header" href="#depinfo">DepInfo</a></h2>
<pre>
DepInfo(<a href="flatten.html#DepInfo-dep_env">dep_env</a>, <a href="flatten.html#DepInfo-direct_crates">direct_crates</a>, <a href="flatten.html#DepInfo-link_search_path_files">link_search_path_files</a>, <a href="flatten.html#DepInfo-transitive_build_infos">transitive_build_infos</a>,
<a href="flatten.html#DepInfo-transitive_crate_outputs">transitive_crate_outputs</a>, <a href="flatten.html#DepInfo-transitive_crates">transitive_crates</a>, <a href="flatten.html#DepInfo-transitive_data">transitive_data</a>, <a href="flatten.html#DepInfo-transitive_metadata_outputs">transitive_metadata_outputs</a>,
<a href="flatten.html#DepInfo-transitive_noncrates">transitive_noncrates</a>, <a href="flatten.html#DepInfo-transitive_proc_macro_data">transitive_proc_macro_data</a>)
</pre>
<p>A provider containing information about a Crate's dependencies.</p>
<p><strong>FIELDS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="DepInfo-dep_env"></a>dep_env</td><td style="text-align: left">File: File with environment variables direct dependencies build scripts rely upon.</td></tr>
<tr><td style="text-align: left"><a id="DepInfo-direct_crates"></a>direct_crates</td><td style="text-align: left">depset[AliasableDepInfo]</td></tr>
<tr><td style="text-align: left"><a id="DepInfo-link_search_path_files"></a>link_search_path_files</td><td style="text-align: left">depset[File]: All transitive files containing search paths to pass to the linker</td></tr>
<tr><td style="text-align: left"><a id="DepInfo-transitive_build_infos"></a>transitive_build_infos</td><td style="text-align: left">depset[BuildInfo]</td></tr>
<tr><td style="text-align: left"><a id="DepInfo-transitive_crate_outputs"></a>transitive_crate_outputs</td><td style="text-align: left">depset[File]: All transitive crate outputs.</td></tr>
<tr><td style="text-align: left"><a id="DepInfo-transitive_crates"></a>transitive_crates</td><td style="text-align: left">depset[CrateInfo]</td></tr>
<tr><td style="text-align: left"><a id="DepInfo-transitive_data"></a>transitive_data</td><td style="text-align: left">depset[File]: Data of all transitive non-macro dependencies.</td></tr>
<tr><td style="text-align: left"><a id="DepInfo-transitive_metadata_outputs"></a>transitive_metadata_outputs</td><td style="text-align: left">depset[File]: All transitive metadata dependencies (.rmeta, for crates that provide them) and all transitive object dependencies (.rlib) for crates that don't provide metadata.</td></tr>
<tr><td style="text-align: left"><a id="DepInfo-transitive_noncrates"></a>transitive_noncrates</td><td style="text-align: left">depset[LinkerInput]: All transitive dependencies that aren't crates.</td></tr>
<tr><td style="text-align: left"><a id="DepInfo-transitive_proc_macro_data"></a>transitive_proc_macro_data</td><td style="text-align: left">depset[File]: Data of all transitive proc-macro dependencies, and non-macro dependencies of those macros.</td></tr>
</tbody></table>
</div>
<p><a id="RustWasmBindgenInfo"></a></p>
<h2 id="rustwasmbindgeninfo-1"><a class="header" href="#rustwasmbindgeninfo-1">RustWasmBindgenInfo</a></h2>
<pre>
RustWasmBindgenInfo(<a href="flatten.html#RustWasmBindgenInfo-js">js</a>, <a href="flatten.html#RustWasmBindgenInfo-ts">ts</a>, <a href="flatten.html#RustWasmBindgenInfo-wasm">wasm</a>)
</pre>
<p>Info about wasm-bindgen outputs.</p>
<p><strong>FIELDS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="RustWasmBindgenInfo-js"></a>js</td><td style="text-align: left">Depset[File]: The Javascript files produced by <code>wasm-bindgen</code>.</td></tr>
<tr><td style="text-align: left"><a id="RustWasmBindgenInfo-ts"></a>ts</td><td style="text-align: left">Depset[File]: The Typescript files produced by <code>wasm-bindgen</code>.</td></tr>
<tr><td style="text-align: left"><a id="RustWasmBindgenInfo-wasm"></a>wasm</td><td style="text-align: left">File: The <code>.wasm</code> file generated by <code>wasm-bindgen</code>.</td></tr>
</tbody></table>
</div>
<p><a id="StdLibInfo"></a></p>
<h2 id="stdlibinfo"><a class="header" href="#stdlibinfo">StdLibInfo</a></h2>
<pre>
StdLibInfo(<a href="flatten.html#StdLibInfo-alloc_files">alloc_files</a>, <a href="flatten.html#StdLibInfo-between_alloc_and_core_files">between_alloc_and_core_files</a>, <a href="flatten.html#StdLibInfo-between_core_and_std_files">between_core_and_std_files</a>, <a href="flatten.html#StdLibInfo-core_files">core_files</a>,
<a href="flatten.html#StdLibInfo-dot_a_files">dot_a_files</a>, <a href="flatten.html#StdLibInfo-memchr_files">memchr_files</a>, <a href="flatten.html#StdLibInfo-panic_files">panic_files</a>, <a href="flatten.html#StdLibInfo-self_contained_files">self_contained_files</a>, <a href="flatten.html#StdLibInfo-srcs">srcs</a>, <a href="flatten.html#StdLibInfo-std_dylib">std_dylib</a>, <a href="flatten.html#StdLibInfo-std_files">std_files</a>,
<a href="flatten.html#StdLibInfo-std_rlibs">std_rlibs</a>, <a href="flatten.html#StdLibInfo-test_files">test_files</a>)
</pre>
<p>A collection of files either found within the <code>rust-stdlib</code> artifact or generated based on existing files.</p>
<p><strong>FIELDS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="StdLibInfo-alloc_files"></a>alloc_files</td><td style="text-align: left">List[File]: <code>.a</code> files related to the <code>alloc</code> module.</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-between_alloc_and_core_files"></a>between_alloc_and_core_files</td><td style="text-align: left">List[File]: <code>.a</code> files related to the <code>compiler_builtins</code> module.</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-between_core_and_std_files"></a>between_core_and_std_files</td><td style="text-align: left">List[File]: <code>.a</code> files related to all modules except <code>adler</code>, <code>alloc</code>, <code>compiler_builtins</code>, <code>core</code>, and <code>std</code>.</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-core_files"></a>core_files</td><td style="text-align: left">List[File]: <code>.a</code> files related to the <code>core</code> and <code>adler</code> modules</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-dot_a_files"></a>dot_a_files</td><td style="text-align: left">Depset[File]: Generated <code>.a</code> files</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-memchr_files"></a>memchr_files</td><td style="text-align: left">Depset[File]: <code>.a</code> files associated with the <code>memchr</code> module.</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-panic_files"></a>panic_files</td><td style="text-align: left">Depset[File]: <code>.a</code> files associated with <code>panic_unwind</code> and <code>panic_abort</code>.</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-self_contained_files"></a>self_contained_files</td><td style="text-align: left">List[File]: All <code>.o</code> files from the <code>self-contained</code> directory.</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-srcs"></a>srcs</td><td style="text-align: left">List[Target]: All targets from the original <code>srcs</code> attribute.</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-std_dylib"></a>std_dylib</td><td style="text-align: left">File: libstd.so file</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-std_files"></a>std_files</td><td style="text-align: left">Depset[File]: <code>.a</code> files associated with the <code>std</code> module.</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-std_rlibs"></a>std_rlibs</td><td style="text-align: left">List[File]: All <code>.rlib</code> files</td></tr>
<tr><td style="text-align: left"><a id="StdLibInfo-test_files"></a>test_files</td><td style="text-align: left">Depset[File]: <code>.a</code> files associated with the <code>test</code> module.</td></tr>
</tbody></table>
</div>
<p><a id="cargo_build_script"></a></p>
<h2 id="cargo_build_script-1"><a class="header" href="#cargo_build_script-1">cargo_build_script</a></h2>
<pre>
cargo_build_script(<a href="flatten.html#cargo_build_script-name">name</a>, <a href="flatten.html#cargo_build_script-edition">edition</a>, <a href="flatten.html#cargo_build_script-crate_name">crate_name</a>, <a href="flatten.html#cargo_build_script-crate_root">crate_root</a>, <a href="flatten.html#cargo_build_script-srcs">srcs</a>, <a href="flatten.html#cargo_build_script-crate_features">crate_features</a>, <a href="flatten.html#cargo_build_script-version">version</a>, <a href="flatten.html#cargo_build_script-deps">deps</a>,
<a href="flatten.html#cargo_build_script-link_deps">link_deps</a>, <a href="flatten.html#cargo_build_script-proc_macro_deps">proc_macro_deps</a>, <a href="flatten.html#cargo_build_script-build_script_env">build_script_env</a>, <a href="flatten.html#cargo_build_script-data">data</a>, <a href="flatten.html#cargo_build_script-compile_data">compile_data</a>, <a href="flatten.html#cargo_build_script-tools">tools</a>, <a href="flatten.html#cargo_build_script-links">links</a>,
<a href="flatten.html#cargo_build_script-rundir">rundir</a>, <a href="flatten.html#cargo_build_script-rustc_env">rustc_env</a>, <a href="flatten.html#cargo_build_script-rustc_env_files">rustc_env_files</a>, <a href="flatten.html#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="flatten.html#cargo_build_script-visibility">visibility</a>, <a href="flatten.html#cargo_build_script-tags">tags</a>, <a href="flatten.html#cargo_build_script-aliases">aliases</a>,
<a href="flatten.html#cargo_build_script-pkg_name">pkg_name</a>, <a href="flatten.html#cargo_build_script-kwargs">kwargs</a>)
</pre>
<p>Compile and execute a rust build script to generate build attributes</p>
<p>This rules take the same arguments as rust_binary.</p>
<p>Example:</p>
<p>Suppose you have a crate with a cargo build script <code>build.rs</code>:</p>
<pre><code class="language-output">[workspace]/
hello_lib/
BUILD
build.rs
src/
lib.rs
</code></pre>
<p>Then you want to use the build script in the following:</p>
<p><code>hello_lib/BUILD</code>:</p>
<pre><code class="language-python">package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library")
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
# This will run the build script from the root of the workspace, and
# collect the outputs.
cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
# Optional environment variables passed during build.rs compilation
rustc_env = {
"CARGO_PKG_VERSION": "0.1.2",
},
# Optional environment variables passed during build.rs execution.
# Note that as the build script's working directory is not execroot,
# execpath/location will return an absolute path, instead of a relative
# one.
build_script_env = {
"SOME_TOOL_OR_FILE": "$(execpath @tool//:binary)"
},
# Optional data/tool dependencies
data = ["@tool//:binary"],
)
rust_library(
name = "hello_lib",
srcs = [
"src/lib.rs",
],
deps = [":build_script"],
)
</code></pre>
<p>The <code>hello_lib</code> target will be build with the flags and the environment variables declared by the build script in addition to the file generated by it.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="cargo_build_script-name"></a>name</td><td style="text-align: left">The name for the underlying rule. This should be the name of the package being compiled, optionally with a suffix of <code>_bs</code>. Otherwise, you can set the package name via <code>pkg_name</code>.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-edition"></a>edition</td><td style="text-align: left">The rust edition to use for the internal binary crate.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-crate_name"></a>crate_name</td><td style="text-align: left">Crate name to use for build script.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-crate_root"></a>crate_root</td><td style="text-align: left">The file that will be passed to rustc to be used for building this crate.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-srcs"></a>srcs</td><td style="text-align: left">Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-crate_features"></a>crate_features</td><td style="text-align: left">A list of features to enable for the build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-version"></a>version</td><td style="text-align: left">The semantic version (semver) of the crate.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-deps"></a>deps</td><td style="text-align: left">The build-dependencies of the crate.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-link_deps"></a>link_deps</td><td style="text-align: left">The subset of the (normal) dependencies of the crate that have the links attribute and therefore provide environment variables to this build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">List of rust_proc_macro targets used to build the script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-build_script_env"></a>build_script_env</td><td style="text-align: left">Environment variables for build scripts.</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-data"></a>data</td><td style="text-align: left">Files needed by the build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-compile_data"></a>compile_data</td><td style="text-align: left">Files needed for the compilation of the build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-tools"></a>tools</td><td style="text-align: left">Tools (executables) needed by the build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-links"></a>links</td><td style="text-align: left">Name of the native library this crate links against.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-rundir"></a>rundir</td><td style="text-align: left">A directory to <code>cd</code> to before the cargo_build_script is run. This should be a path relative to the exec root.<br><br>The default behaviour (and the behaviour if rundir is set to the empty string) is to change to the relative path corresponding to the cargo manifest directory, which replicates the normal behaviour of cargo so it is easy to write compatible build scripts.<br><br>If set to <code>.</code>, the cargo build script will run in the exec root.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-rustc_env"></a>rustc_env</td><td style="text-align: left">Environment variables to set in rustc when compiling the build script.</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">Files containing additional environment variables to set for rustc when building the build script.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-rustc_flags"></a>rustc_flags</td><td style="text-align: left">List of compiler flags passed to <code>rustc</code>.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-visibility"></a>visibility</td><td style="text-align: left">Visibility to apply to the generated build script output.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-tags"></a>tags</td><td style="text-align: left">(list of str, optional): Tags to apply to the generated build script output.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-aliases"></a>aliases</td><td style="text-align: left">Remap crates to a new name or moniker for linkage to this target. These are other <code>rust_library</code> targets and will be presented as the new name given.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-pkg_name"></a>pkg_name</td><td style="text-align: left">Override the package name used for the build script. This is useful if the build target name gets too long otherwise.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_build_script-kwargs"></a>kwargs</td><td style="text-align: left">Forwards to the underlying <code>rust_binary</code> rule. An exception is the <code>compatible_with</code> attribute, which shouldn't be forwarded to the <code>rust_binary</code>, as the <code>rust_binary</code> is only built and used in <code>exec</code> mode. We propagate the <code>compatible_with</code> attribute to the <code>_build_scirpt_run</code> target.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><a id="cargo_env"></a></p>
<h2 id="cargo_env-1"><a class="header" href="#cargo_env-1">cargo_env</a></h2>
<pre>
cargo_env(<a href="flatten.html#cargo_env-env">env</a>)
</pre>
<p>A helper for generating platform specific environment variables</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_common")
load("@rules_rust//cargo:defs.bzl", "cargo_bootstrap_repository", "cargo_env")
cargo_bootstrap_repository(
name = "bootstrapped_bin",
cargo_lockfile = "//:Cargo.lock",
cargo_toml = "//:Cargo.toml",
srcs = ["//:resolver_srcs"],
version = rust_common.default_version,
binary = "my-crate-binary",
env = {
"x86_64-unknown-linux-gnu": cargo_env({
"FOO": "BAR",
}),
},
env_label = {
"aarch64-unknown-linux-musl": cargo_env({
"DOC": "//:README.md",
}),
}
)
</code></pre>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="cargo_env-env"></a>env</td><td style="text-align: left">A map of environment variables</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>str: A json encoded string of the environment variables</p>
<p><a id="rules_rust_dependencies"></a></p>
<h2 id="rules_rust_dependencies"><a class="header" href="#rules_rust_dependencies">rules_rust_dependencies</a></h2>
<pre>
rules_rust_dependencies()
</pre>
<p>Dependencies used in the implementation of <code>rules_rust</code>.</p>
<p><a id="rust_analyzer_toolchain_repository"></a></p>
<h2 id="rust_analyzer_toolchain_repository"><a class="header" href="#rust_analyzer_toolchain_repository">rust_analyzer_toolchain_repository</a></h2>
<pre>
rust_analyzer_toolchain_repository(<a href="flatten.html#rust_analyzer_toolchain_repository-name">name</a>, <a href="flatten.html#rust_analyzer_toolchain_repository-version">version</a>, <a href="flatten.html#rust_analyzer_toolchain_repository-exec_compatible_with">exec_compatible_with</a>, <a href="flatten.html#rust_analyzer_toolchain_repository-target_compatible_with">target_compatible_with</a>,
<a href="flatten.html#rust_analyzer_toolchain_repository-sha256s">sha256s</a>, <a href="flatten.html#rust_analyzer_toolchain_repository-urls">urls</a>, <a href="flatten.html#rust_analyzer_toolchain_repository-auth">auth</a>, <a href="flatten.html#rust_analyzer_toolchain_repository-netrc">netrc</a>, <a href="flatten.html#rust_analyzer_toolchain_repository-auth_patterns">auth_patterns</a>)
</pre>
<p>Assemble a remote rust_analyzer_toolchain target based on the given params.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-name"></a>name</td><td style="text-align: left">The name of the toolchain proxy repository contianing the registerable toolchain.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-version"></a>version</td><td style="text-align: left">The version of the tool among "nightly", "beta', or an exact version.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-exec_compatible_with"></a>exec_compatible_with</td><td style="text-align: left">A list of constraints for the execution platform for this toolchain.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-target_compatible_with"></a>target_compatible_with</td><td style="text-align: left">A list of constraints for the target platform for this toolchain.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes. See <a href="flatten.html#rust_register_toolchains">rust_register_toolchains</a> for more details.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-urls"></a>urls</td><td style="text-align: left">A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz']</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-auth"></a>auth</td><td style="text-align: left">Auth object compatible with repository_ctx.download to use when downloading files. See <a href="https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download">repository_ctx.download</a> for more details.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-netrc"></a>netrc</td><td style="text-align: left">.netrc file to use for authentication; mirrors the eponymous attribute from http_archive</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_analyzer_toolchain_repository-auth_patterns"></a>auth_patterns</td><td style="text-align: left">Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>str: The name of a registerable rust_analyzer_toolchain.</p>
<p><a id="rust_bindgen_dependencies"></a></p>
<h2 id="rust_bindgen_dependencies-1"><a class="header" href="#rust_bindgen_dependencies-1">rust_bindgen_dependencies</a></h2>
<pre>
rust_bindgen_dependencies()
</pre>
<p>Declare dependencies needed for bindgen.</p>
<p><strong>RETURNS</strong></p>
<p>list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories
defined by this macro.</p>
<p><a id="rust_bindgen_library"></a></p>
<h2 id="rust_bindgen_library-1"><a class="header" href="#rust_bindgen_library-1">rust_bindgen_library</a></h2>
<pre>
rust_bindgen_library(<a href="flatten.html#rust_bindgen_library-name">name</a>, <a href="flatten.html#rust_bindgen_library-header">header</a>, <a href="flatten.html#rust_bindgen_library-cc_lib">cc_lib</a>, <a href="flatten.html#rust_bindgen_library-bindgen_flags">bindgen_flags</a>, <a href="flatten.html#rust_bindgen_library-bindgen_features">bindgen_features</a>, <a href="flatten.html#rust_bindgen_library-clang_flags">clang_flags</a>,
<a href="flatten.html#rust_bindgen_library-wrap_static_fns">wrap_static_fns</a>, <a href="flatten.html#rust_bindgen_library-kwargs">kwargs</a>)
</pre>
<p>Generates a rust source file for <code>header</code>, and builds a rust_library.</p>
<p>Arguments are the same as <code>rust_bindgen</code>, and <code>kwargs</code> are passed directly to rust_library.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_bindgen_library-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-header"></a>header</td><td style="text-align: left">The label of the .h file to generate bindings for.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-cc_lib"></a>cc_lib</td><td style="text-align: left">The label of the cc_library that contains the .h file. This is used to find the transitive includes.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-bindgen_flags"></a>bindgen_flags</td><td style="text-align: left">Flags to pass directly to the bindgen executable. See https://rust-lang.github.io/rust-bindgen/ for details.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-bindgen_features"></a>bindgen_features</td><td style="text-align: left">The <code>features</code> attribute for the <code>rust_bindgen</code> target.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-clang_flags"></a>clang_flags</td><td style="text-align: left">Flags to pass directly to the clang executable.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-wrap_static_fns"></a>wrap_static_fns</td><td style="text-align: left">Whether to create a separate .c file for static fns. Requires nightly toolchain, and a header that actually needs this feature (otherwise bindgen won't generate the file and Bazel complains",</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_bindgen_library-kwargs"></a>kwargs</td><td style="text-align: left">Arguments to forward to the underlying <code>rust_library</code> rule.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><a id="rust_bindgen_register_toolchains"></a></p>
<h2 id="rust_bindgen_register_toolchains-1"><a class="header" href="#rust_bindgen_register_toolchains-1">rust_bindgen_register_toolchains</a></h2>
<pre>
rust_bindgen_register_toolchains(<a href="flatten.html#rust_bindgen_register_toolchains-register_toolchains">register_toolchains</a>)
</pre>
<p>Registers the default toolchains for the <code>rules_rust</code> <a href="https://rust-lang.github.io/rust-bindgen/">bindgen</a> rules.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_bindgen_register_toolchains-register_toolchains"></a>register_toolchains</td><td style="text-align: left">Whether or not to register toolchains.</td><td style="text-align: left"><code>True</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_prost_dependencies"></a></p>
<h2 id="rust_prost_dependencies-1"><a class="header" href="#rust_prost_dependencies-1">rust_prost_dependencies</a></h2>
<pre>
rust_prost_dependencies(<a href="flatten.html#rust_prost_dependencies-bzlmod">bzlmod</a>)
</pre>
<p>Declares repositories needed for prost.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_prost_dependencies-bzlmod"></a>bzlmod</td><td style="text-align: left">Whether bzlmod is enabled.</td><td style="text-align: left"><code>False</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories
defined by this macro.</p>
<p><a id="rust_prost_library"></a></p>
<h2 id="rust_prost_library-1"><a class="header" href="#rust_prost_library-1">rust_prost_library</a></h2>
<pre>
rust_prost_library(<a href="flatten.html#rust_prost_library-name">name</a>, <a href="flatten.html#rust_prost_library-kwargs">kwargs</a>)
</pre>
<p>A rule for generating a Rust library using Prost.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_prost_library-name"></a>name</td><td style="text-align: left">The name of the target.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_prost_library-kwargs"></a>kwargs</td><td style="text-align: left">Additional keyword arguments for the underlying <code>rust_prost_library</code> rule.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><a id="rust_prost_transitive_repositories"></a></p>
<h2 id="rust_prost_transitive_repositories-1"><a class="header" href="#rust_prost_transitive_repositories-1">rust_prost_transitive_repositories</a></h2>
<pre>
rust_prost_transitive_repositories()
</pre>
<p>Load transitive dependencies of the <code>@rules_rust//proto/protobuf</code> rules.</p>
<p>This macro should be called immediately after the <code>rust_protobuf_dependencies</code> macro.</p>
<p><a id="rust_proto_protobuf_dependencies"></a></p>
<h2 id="rust_proto_protobuf_dependencies-1"><a class="header" href="#rust_proto_protobuf_dependencies-1">rust_proto_protobuf_dependencies</a></h2>
<pre>
rust_proto_protobuf_dependencies(<a href="flatten.html#rust_proto_protobuf_dependencies-bzlmod">bzlmod</a>)
</pre>
<p>Sets up dependencies for rules_rust's proto support.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_proto_protobuf_dependencies-bzlmod"></a>bzlmod</td><td style="text-align: left">Whether this function is being called from a bzlmod context rather than a workspace context.</td><td style="text-align: left"><code>False</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>A list of structs containing information about root module deps to report to bzlmod's extension_metadata.</p>
<p><a id="rust_proto_protobuf_register_toolchains"></a></p>
<h2 id="rust_proto_protobuf_register_toolchains-1"><a class="header" href="#rust_proto_protobuf_register_toolchains-1">rust_proto_protobuf_register_toolchains</a></h2>
<pre>
rust_proto_protobuf_register_toolchains(<a href="flatten.html#rust_proto_protobuf_register_toolchains-register_toolchains">register_toolchains</a>)
</pre>
<p>Register toolchains for proto compilation.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_proto_protobuf_register_toolchains-register_toolchains"></a>register_toolchains</td><td style="text-align: left"><p align="center"> - </p></td><td style="text-align: left"><code>True</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_proto_protobuf_transitive_repositories"></a></p>
<h2 id="rust_proto_protobuf_transitive_repositories-1"><a class="header" href="#rust_proto_protobuf_transitive_repositories-1">rust_proto_protobuf_transitive_repositories</a></h2>
<pre>
rust_proto_protobuf_transitive_repositories()
</pre>
<p>Load transitive dependencies of the <code>@rules_rust//proto/protobuf</code> rules.</p>
<p>This macro should be called immediately after the <code>rust_protobuf_dependencies</code> macro.</p>
<p><a id="rust_register_toolchains"></a></p>
<h2 id="rust_register_toolchains"><a class="header" href="#rust_register_toolchains">rust_register_toolchains</a></h2>
<pre>
rust_register_toolchains(<a href="flatten.html#rust_register_toolchains-dev_components">dev_components</a>, <a href="flatten.html#rust_register_toolchains-edition">edition</a>, <a href="flatten.html#rust_register_toolchains-allocator_library">allocator_library</a>, <a href="flatten.html#rust_register_toolchains-global_allocator_library">global_allocator_library</a>,
<a href="flatten.html#rust_register_toolchains-register_toolchains">register_toolchains</a>, <a href="flatten.html#rust_register_toolchains-rustfmt_version">rustfmt_version</a>, <a href="flatten.html#rust_register_toolchains-rust_analyzer_version">rust_analyzer_version</a>, <a href="flatten.html#rust_register_toolchains-sha256s">sha256s</a>,
<a href="flatten.html#rust_register_toolchains-extra_target_triples">extra_target_triples</a>, <a href="flatten.html#rust_register_toolchains-extra_rustc_flags">extra_rustc_flags</a>, <a href="flatten.html#rust_register_toolchains-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="flatten.html#rust_register_toolchains-urls">urls</a>,
<a href="flatten.html#rust_register_toolchains-versions">versions</a>, <a href="flatten.html#rust_register_toolchains-aliases">aliases</a>)
</pre>
<p>Emits a default set of toolchains for Linux, MacOS, and Freebsd</p>
<p>Skip this macro and call the <code>rust_repository_set</code> macros directly if you need a compiler for other hosts or for additional target triples.</p>
<p>The <code>sha256s</code> attribute represents a dict associating tool subdirectories to sha256 hashes. As an example:</p>
<pre><code class="language-python">{
"rust-1.46.0-x86_64-unknown-linux-gnu": "e3b98bc3440fe92817881933f9564389eccb396f5f431f33d48b979fa2fbdcf5",
"rustfmt-1.4.12-x86_64-unknown-linux-gnu": "1894e76913303d66bf40885a601462844eec15fca9e76a6d13c390d7000d64b0",
"rust-std-1.46.0-x86_64-unknown-linux-gnu": "ac04aef80423f612c0079829b504902de27a6997214eb58ab0765d02f7ec1dbc",
}
</code></pre>
<p>This would match for <code>exec_triple = "x86_64-unknown-linux-gnu"</code>. If not specified, rules_rust pulls from a non-exhaustive list of known checksums..</p>
<p>See <code>load_arbitrary_tool</code> in <code>@rules_rust//rust:repositories.bzl</code> for more details.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_register_toolchains-dev_components"></a>dev_components</td><td style="text-align: left">Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly".</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-edition"></a>edition</td><td style="text-align: left">The rust edition to be used by default (2015, 2018, or 2021). If absent, every target is required to specify its <code>edition</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-allocator_library"></a>allocator_library</td><td style="text-align: left">Target that provides allocator functions when rust_library targets are embedded in a cc_binary.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions when global allocator is used with cc_common.link.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-register_toolchains"></a>register_toolchains</td><td style="text-align: left">If true, repositories will be generated to produce and register <code>rust_toolchain</code> targets.</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-rustfmt_version"></a>rustfmt_version</td><td style="text-align: left">The version of rustfmt. If none is supplied and only a single version in <code>versions</code> is given, then this defaults to that version, otherwise will default to the default nightly version.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-rust_analyzer_version"></a>rust_analyzer_version</td><td style="text-align: left">The version of Rustc to pair with rust-analyzer.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-extra_target_triples"></a>extra_target_triples</td><td style="text-align: left">Additional rust-style targets that rust toolchains should support.</td><td style="text-align: left"><code>["wasm32-unknown-unknown", "wasm32-wasip1"]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-extra_rustc_flags"></a>extra_rustc_flags</td><td style="text-align: left">Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-extra_exec_rustc_flags"></a>extra_exec_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in exec configuration.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-urls"></a>urls</td><td style="text-align: left">A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).</td><td style="text-align: left"><code>["https://static.rust-lang.org/dist/{}.tar.xz"]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-versions"></a>versions</td><td style="text-align: left">A list of toolchain versions to download. This parameter only accepts one versions per channel. E.g. <code>["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]</code>.</td><td style="text-align: left"><code>["1.82.0", "nightly/2024-10-17"]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_register_toolchains-aliases"></a>aliases</td><td style="text-align: left">A mapping of "full" repository name to another name to use instead.</td><td style="text-align: left"><code>{}</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_repositories"></a></p>
<h2 id="rust_repositories"><a class="header" href="#rust_repositories">rust_repositories</a></h2>
<pre>
rust_repositories(<a href="flatten.html#rust_repositories-kwargs">kwargs</a>)
</pre>
<p><strong>Deprecated</strong>: Use <a href="flatten.html#rules_rust_dependencies">rules_rust_dependencies</a> and <a href="flatten.html#rust_register_toolchains">rust_register_toolchains</a> directly.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_repositories-kwargs"></a>kwargs</td><td style="text-align: left">Keyword arguments for the <code>rust_register_toolchains</code> macro.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><a id="rust_repository_set"></a></p>
<h2 id="rust_repository_set"><a class="header" href="#rust_repository_set">rust_repository_set</a></h2>
<pre>
rust_repository_set(<a href="flatten.html#rust_repository_set-name">name</a>, <a href="flatten.html#rust_repository_set-versions">versions</a>, <a href="flatten.html#rust_repository_set-exec_triple">exec_triple</a>, <a href="flatten.html#rust_repository_set-target_settings">target_settings</a>, <a href="flatten.html#rust_repository_set-allocator_library">allocator_library</a>,
<a href="flatten.html#rust_repository_set-global_allocator_library">global_allocator_library</a>, <a href="flatten.html#rust_repository_set-extra_target_triples">extra_target_triples</a>, <a href="flatten.html#rust_repository_set-rustfmt_version">rustfmt_version</a>, <a href="flatten.html#rust_repository_set-edition">edition</a>,
<a href="flatten.html#rust_repository_set-dev_components">dev_components</a>, <a href="flatten.html#rust_repository_set-extra_rustc_flags">extra_rustc_flags</a>, <a href="flatten.html#rust_repository_set-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="flatten.html#rust_repository_set-opt_level">opt_level</a>, <a href="flatten.html#rust_repository_set-sha256s">sha256s</a>,
<a href="flatten.html#rust_repository_set-urls">urls</a>, <a href="flatten.html#rust_repository_set-auth">auth</a>, <a href="flatten.html#rust_repository_set-netrc">netrc</a>, <a href="flatten.html#rust_repository_set-auth_patterns">auth_patterns</a>, <a href="flatten.html#rust_repository_set-register_toolchain">register_toolchain</a>, <a href="flatten.html#rust_repository_set-exec_compatible_with">exec_compatible_with</a>,
<a href="flatten.html#rust_repository_set-default_target_compatible_with">default_target_compatible_with</a>, <a href="flatten.html#rust_repository_set-aliases">aliases</a>)
</pre>
<p>Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_repository_set-name"></a>name</td><td style="text-align: left">The name of the generated repository</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-versions"></a>versions</td><td style="text-align: left">A list of toolchain versions to download. This paramter only accepts one versions per channel. E.g. <code>["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]</code>.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-exec_triple"></a>exec_triple</td><td style="text-align: left">The Rust-style target that this compiler runs on</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-target_settings"></a>target_settings</td><td style="text-align: left">A list of config_settings that must be satisfied by the target configuration in order for this set of toolchains to be selected during toolchain resolution.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-allocator_library"></a>allocator_library</td><td style="text-align: left">Target that provides allocator functions when rust_library targets are embedded in a cc_binary.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions a global allocator is used with cc_common.link.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-extra_target_triples"></a>extra_target_triples</td><td style="text-align: left">Additional rust-style targets that this set of toolchains should support. If a map, values should be (optional) target_compatible_with lists for that particular target triple.</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-rustfmt_version"></a>rustfmt_version</td><td style="text-align: left">The version of rustfmt to be associated with the toolchain.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-edition"></a>edition</td><td style="text-align: left">The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its <code>edition</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-dev_components"></a>dev_components</td><td style="text-align: left">Whether to download the rustc-dev components. Requires version to be "nightly".</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-extra_rustc_flags"></a>extra_rustc_flags</td><td style="text-align: left">Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in exec configuration.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-opt_level"></a>opt_level</td><td style="text-align: left">Dictionary of target triples to optimiztion config.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes. See <a href="flatten.html#rust_register_toolchains">rust_register_toolchains</a> for more details.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-urls"></a>urls</td><td style="text-align: left">A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).</td><td style="text-align: left"><code>["https://static.rust-lang.org/dist/{}.tar.xz"]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-auth"></a>auth</td><td style="text-align: left">Auth object compatible with repository_ctx.download to use when downloading files. See <a href="https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download">repository_ctx.download</a> for more details.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-netrc"></a>netrc</td><td style="text-align: left">.netrc file to use for authentication; mirrors the eponymous attribute from http_archive</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-auth_patterns"></a>auth_patterns</td><td style="text-align: left">Override mapping of hostnames to authorization patterns; mirrors the eponymous attribute from http_archive</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-register_toolchain"></a>register_toolchain</td><td style="text-align: left">If True, the generated <code>rust_toolchain</code> target will become a registered toolchain.</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-exec_compatible_with"></a>exec_compatible_with</td><td style="text-align: left">A list of constraints for the execution platform for this toolchain.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-default_target_compatible_with"></a>default_target_compatible_with</td><td style="text-align: left">A list of constraints for the target platform for this toolchain when the exec platform is the same as the target platform.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_repository_set-aliases"></a>aliases</td><td style="text-align: left">Replacement names to use for toolchains created by this macro.</td><td style="text-align: left"><code>{}</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_test_suite"></a></p>
<h2 id="rust_test_suite-1"><a class="header" href="#rust_test_suite-1">rust_test_suite</a></h2>
<pre>
rust_test_suite(<a href="flatten.html#rust_test_suite-name">name</a>, <a href="flatten.html#rust_test_suite-srcs">srcs</a>, <a href="flatten.html#rust_test_suite-shared_srcs">shared_srcs</a>, <a href="flatten.html#rust_test_suite-kwargs">kwargs</a>)
</pre>
<p>A rule for creating a test suite for a set of <code>rust_test</code> targets.</p>
<p>This rule can be used for setting up typical rust <a href="https://doc.rust-lang.org/rust-by-example/testing/integration_testing.html">integration tests</a>. Given the following
directory structure:</p>
<pre><code class="language-text">[crate]/
BUILD.bazel
src/
lib.rs
main.rs
tests/
integrated_test_a.rs
integrated_test_b.rs
integrated_test_c.rs
patterns/
fibonacci_test.rs
helpers/
mod.rs
</code></pre>
<p>The rule can be used to generate <a href="flatten.html#rust_test">rust_test</a> targets for each source file under <code>tests</code>
and a <a href="https://docs.bazel.build/versions/master/be/general.html#test_suite">test_suite</a> which encapsulates all tests.</p>
<pre><code class="language-python">load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test_suite")
rust_library(
name = "math_lib",
srcs = ["src/lib.rs"],
)
rust_binary(
name = "math_bin",
srcs = ["src/main.rs"],
)
rust_test_suite(
name = "integrated_tests_suite",
srcs = glob(["tests/**"]),
shared_srcs=glob(["tests/helpers/**"]),
deps = [":math_lib"],
)
</code></pre>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_test_suite-name"></a>name</td><td style="text-align: left">The name of the <code>test_suite</code>.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_test_suite-srcs"></a>srcs</td><td style="text-align: left">All test sources, typically <code>glob(["tests/**/*.rs"])</code>.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_test_suite-shared_srcs"></a>shared_srcs</td><td style="text-align: left">Optional argument for sources shared among tests, typically helper functions.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_test_suite-kwargs"></a>kwargs</td><td style="text-align: left">Additional keyword arguments for the underyling <a href="flatten.html#rust_test">rust_test</a> targets. The <code>tags</code> argument is also passed to the generated <code>test_suite</code> target.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><a id="rust_toolchain_repository"></a></p>
<h2 id="rust_toolchain_repository"><a class="header" href="#rust_toolchain_repository">rust_toolchain_repository</a></h2>
<pre>
rust_toolchain_repository(<a href="flatten.html#rust_toolchain_repository-name">name</a>, <a href="flatten.html#rust_toolchain_repository-version">version</a>, <a href="flatten.html#rust_toolchain_repository-exec_triple">exec_triple</a>, <a href="flatten.html#rust_toolchain_repository-target_triple">target_triple</a>, <a href="flatten.html#rust_toolchain_repository-exec_compatible_with">exec_compatible_with</a>,
<a href="flatten.html#rust_toolchain_repository-target_compatible_with">target_compatible_with</a>, <a href="flatten.html#rust_toolchain_repository-target_settings">target_settings</a>, <a href="flatten.html#rust_toolchain_repository-channel">channel</a>, <a href="flatten.html#rust_toolchain_repository-allocator_library">allocator_library</a>,
<a href="flatten.html#rust_toolchain_repository-global_allocator_library">global_allocator_library</a>, <a href="flatten.html#rust_toolchain_repository-rustfmt_version">rustfmt_version</a>, <a href="flatten.html#rust_toolchain_repository-edition">edition</a>, <a href="flatten.html#rust_toolchain_repository-dev_components">dev_components</a>,
<a href="flatten.html#rust_toolchain_repository-extra_rustc_flags">extra_rustc_flags</a>, <a href="flatten.html#rust_toolchain_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="flatten.html#rust_toolchain_repository-opt_level">opt_level</a>, <a href="flatten.html#rust_toolchain_repository-sha256s">sha256s</a>, <a href="flatten.html#rust_toolchain_repository-urls">urls</a>, <a href="flatten.html#rust_toolchain_repository-auth">auth</a>,
<a href="flatten.html#rust_toolchain_repository-netrc">netrc</a>, <a href="flatten.html#rust_toolchain_repository-auth_patterns">auth_patterns</a>)
</pre>
<p>Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-name"></a>name</td><td style="text-align: left">The name of the generated repository</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-version"></a>version</td><td style="text-align: left">The version of the tool among "nightly", "beta", or an exact version.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-exec_triple"></a>exec_triple</td><td style="text-align: left">The Rust-style target that this compiler runs on.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-target_triple"></a>target_triple</td><td style="text-align: left">The Rust-style target to build for.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-exec_compatible_with"></a>exec_compatible_with</td><td style="text-align: left">A list of constraints for the execution platform for this toolchain.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-target_compatible_with"></a>target_compatible_with</td><td style="text-align: left">A list of constraints for the target platform for this toolchain.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-target_settings"></a>target_settings</td><td style="text-align: left">A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution.</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-channel"></a>channel</td><td style="text-align: left">The channel of the Rust toolchain.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-allocator_library"></a>allocator_library</td><td style="text-align: left">Target that provides allocator functions when rust_library targets are embedded in a cc_binary.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions when a global allocator is used with cc_common.link.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-rustfmt_version"></a>rustfmt_version</td><td style="text-align: left">The version of rustfmt to be associated with the toolchain.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-edition"></a>edition</td><td style="text-align: left">The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its <code>edition</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-dev_components"></a>dev_components</td><td style="text-align: left">Whether to download the rustc-dev components. Requires version to be "nightly". Defaults to False.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-extra_rustc_flags"></a>extra_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in non-exec configuration.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in exec configuration.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-opt_level"></a>opt_level</td><td style="text-align: left">Optimization level config for this toolchain.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes. See <a href="flatten.html#rust_register_toolchains">rust_register_toolchains</a> for more details.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-urls"></a>urls</td><td style="text-align: left">A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz']</td><td style="text-align: left"><code>["https://static.rust-lang.org/dist/{}.tar.xz"]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-auth"></a>auth</td><td style="text-align: left">Auth object compatible with repository_ctx.download to use when downloading files. See <a href="https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download">repository_ctx.download</a> for more details.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-netrc"></a>netrc</td><td style="text-align: left">.netrc file to use for authentication; mirrors the eponymous attribute from http_archive</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository-auth_patterns"></a>auth_patterns</td><td style="text-align: left">A list of patterns to match against urls for which the auth object should be used.</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>str: The name of the registerable toolchain created by this rule.</p>
<p><a id="rust_wasm_bindgen_dependencies"></a></p>
<h2 id="rust_wasm_bindgen_dependencies-1"><a class="header" href="#rust_wasm_bindgen_dependencies-1">rust_wasm_bindgen_dependencies</a></h2>
<pre>
rust_wasm_bindgen_dependencies()
</pre>
<p>Declare dependencies needed for the <code>rules_rust</code> <a href="https://github.com/rustwasm/wasm-bindgen">wasm-bindgen</a> rules.</p>
<p><strong>RETURNS</strong></p>
<p>list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories
defined by this macro.</p>
<p><a id="rust_wasm_bindgen_register_toolchains"></a></p>
<h2 id="rust_wasm_bindgen_register_toolchains-1"><a class="header" href="#rust_wasm_bindgen_register_toolchains-1">rust_wasm_bindgen_register_toolchains</a></h2>
<pre>
rust_wasm_bindgen_register_toolchains(<a href="flatten.html#rust_wasm_bindgen_register_toolchains-register_toolchains">register_toolchains</a>)
</pre>
<p>Registers the default toolchains for the <code>rules_rust</code> <a href="https://github.com/rustwasm/wasm-bindgen">wasm-bindgen</a> rules.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_wasm_bindgen_register_toolchains-register_toolchains"></a>register_toolchains</td><td style="text-align: left">Whether or not to register toolchains.</td><td style="text-align: left"><code>True</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_analyzer_aspect"></a></p>
<h2 id="rust_analyzer_aspect-1"><a class="header" href="#rust_analyzer_aspect-1">rust_analyzer_aspect</a></h2>
<pre>
rust_analyzer_aspect(<a href="flatten.html#rust_analyzer_aspect-name">name</a>)
</pre>
<p>Annotates rust rules with RustAnalyzerInfo later used to build a rust-project.json</p>
<p><strong>ASPECT ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Type</th></tr></thead><tbody>
<tr><td style="text-align: left">deps</td><td style="text-align: left">String</td></tr>
<tr><td style="text-align: left">proc_macro_deps</td><td style="text-align: left">String</td></tr>
<tr><td style="text-align: left">crate</td><td style="text-align: left">String</td></tr>
<tr><td style="text-align: left">actual</td><td style="text-align: left">String</td></tr>
<tr><td style="text-align: left">proto</td><td style="text-align: left">String</td></tr>
</tbody></table>
</div>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_analyzer_aspect-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rust_clippy_aspect"></a></p>
<h2 id="rust_clippy_aspect-1"><a class="header" href="#rust_clippy_aspect-1">rust_clippy_aspect</a></h2>
<pre>
rust_clippy_aspect(<a href="flatten.html#rust_clippy_aspect-name">name</a>)
</pre>
<p>Executes the clippy checker on specified targets.</p>
<p>This aspect applies to existing rust_library, rust_test, and rust_binary rules.</p>
<p>As an example, if the following is defined in <code>examples/hello_lib/BUILD.bazel</code>:</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "hello_lib",
srcs = ["src/lib.rs"],
)
rust_test(
name = "greeting_test",
srcs = ["tests/greeting.rs"],
deps = [":hello_lib"],
)
</code></pre>
<p>Then the targets can be analyzed with clippy using the following command:</p>
<pre><code class="language-output">$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks //hello_lib:all
</code></pre>
<p><strong>ASPECT ATTRIBUTES</strong></p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_clippy_aspect-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rustfmt_aspect"></a></p>
<h2 id="rustfmt_aspect-1"><a class="header" href="#rustfmt_aspect-1">rustfmt_aspect</a></h2>
<pre>
rustfmt_aspect(<a href="flatten.html#rustfmt_aspect-name">name</a>)
</pre>
<p>This aspect is used to gather information about a crate for use in rustfmt and perform rustfmt checks</p>
<p>Output Groups:</p>
<ul>
<li><code>rustfmt_checks</code>: Executes <code>rustfmt --check</code> on the specified target.</li>
</ul>
<p>The build setting <code>@rules_rust//:rustfmt.toml</code> is used to control the Rustfmt <a href="https://rust-lang.github.io/rustfmt/">configuration settings</a>
used at runtime.</p>
<p>This aspect is executed on any target which provides the <code>CrateInfo</code> provider. However
users may tag a target with <code>no-rustfmt</code> or <code>no-format</code> to have it skipped. Additionally,
generated source files are also ignored by this aspect.</p>
<p><strong>ASPECT ATTRIBUTES</strong></p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rustfmt_aspect-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="cargo_bootstrap_repository"></a></p>
<h2 id="cargo_bootstrap_repository-1"><a class="header" href="#cargo_bootstrap_repository-1">cargo_bootstrap_repository</a></h2>
<pre>
cargo_bootstrap_repository(<a href="flatten.html#cargo_bootstrap_repository-name">name</a>, <a href="flatten.html#cargo_bootstrap_repository-srcs">srcs</a>, <a href="flatten.html#cargo_bootstrap_repository-binary">binary</a>, <a href="flatten.html#cargo_bootstrap_repository-build_mode">build_mode</a>, <a href="flatten.html#cargo_bootstrap_repository-cargo_config">cargo_config</a>, <a href="flatten.html#cargo_bootstrap_repository-cargo_lockfile">cargo_lockfile</a>, <a href="flatten.html#cargo_bootstrap_repository-cargo_toml">cargo_toml</a>,
<a href="flatten.html#cargo_bootstrap_repository-env">env</a>, <a href="flatten.html#cargo_bootstrap_repository-env_label">env_label</a>, <a href="flatten.html#cargo_bootstrap_repository-repo_mapping">repo_mapping</a>, <a href="flatten.html#cargo_bootstrap_repository-rust_toolchain_cargo_template">rust_toolchain_cargo_template</a>,
<a href="flatten.html#cargo_bootstrap_repository-rust_toolchain_rustc_template">rust_toolchain_rustc_template</a>, <a href="flatten.html#cargo_bootstrap_repository-timeout">timeout</a>, <a href="flatten.html#cargo_bootstrap_repository-version">version</a>)
</pre>
<p>A rule for bootstrapping a Rust binary using <a href="https://doc.rust-lang.org/cargo/">Cargo</a></p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-name"></a>name</td><td style="text-align: left">A unique name for this repository.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-srcs"></a>srcs</td><td style="text-align: left">Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-binary"></a>binary</td><td style="text-align: left">The binary to build (the <code>--bin</code> parameter for Cargo). If left empty, the repository name will be used.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-build_mode"></a>build_mode</td><td style="text-align: left">The build mode the binary should be built with</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"release"</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-cargo_config"></a>cargo_config</td><td style="text-align: left">The path of the Cargo configuration (<code>Config.toml</code>) file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-cargo_lockfile"></a>cargo_lockfile</td><td style="text-align: left">The lockfile of the crate_universe resolver</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-cargo_toml"></a>cargo_toml</td><td style="text-align: left">The path of the <code>Cargo.toml</code> file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-env"></a>env</td><td style="text-align: left">A mapping of platform triple to a set of environment variables. See <a href="flatten.html#cargo_env">cargo_env</a> for usage details. Additionally, the platform triple <code>*</code> applies to all platforms.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-env_label"></a>env_label</td><td style="text-align: left">A mapping of platform triple to a set of environment variables. This attribute differs from <code>env</code> in that all variables passed here must be fully qualified labels of files. See <a href="flatten.html#cargo_env">cargo_env</a> for usage details. Additionally, the platform triple <code>*</code> applies to all platforms.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-repo_mapping"></a>repo_mapping</td><td style="text-align: left">In <code>WORKSPACE</code> context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>).<br><br>This attribute is <em>not</em> supported in <code>MODULE.bazel</code> context (when invoking a repository rule inside a module extension's implementation function).</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-rust_toolchain_cargo_template"></a>rust_toolchain_cargo_template</td><td style="text-align: left">The template to use for finding the host <code>cargo</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-rust_toolchain_rustc_template"></a>rust_toolchain_rustc_template</td><td style="text-align: left">The template to use for finding the host <code>rustc</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-timeout"></a>timeout</td><td style="text-align: left">Maximum duration of the Cargo build command in seconds</td><td style="text-align: left">Integer</td><td style="text-align: left">optional</td><td style="text-align: left"><code>600</code></td></tr>
<tr><td style="text-align: left"><a id="cargo_bootstrap_repository-version"></a>version</td><td style="text-align: left">The version of Rust the currently registered toolchain is using. Eg. <code>1.56.0</code>, or <code>nightly/2021-09-08</code></td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"1.82.0"</code></td></tr>
</tbody></table>
</div>
<p><a id="rust_toolchain_repository_proxy"></a></p>
<h2 id="rust_toolchain_repository_proxy"><a class="header" href="#rust_toolchain_repository_proxy">rust_toolchain_repository_proxy</a></h2>
<pre>
rust_toolchain_repository_proxy(<a href="flatten.html#rust_toolchain_repository_proxy-name">name</a>, <a href="flatten.html#rust_toolchain_repository_proxy-exec_compatible_with">exec_compatible_with</a>, <a href="flatten.html#rust_toolchain_repository_proxy-repo_mapping">repo_mapping</a>, <a href="flatten.html#rust_toolchain_repository_proxy-target_compatible_with">target_compatible_with</a>,
<a href="flatten.html#rust_toolchain_repository_proxy-target_settings">target_settings</a>, <a href="flatten.html#rust_toolchain_repository_proxy-toolchain">toolchain</a>, <a href="flatten.html#rust_toolchain_repository_proxy-toolchain_type">toolchain_type</a>)
</pre>
<p>Generates a toolchain-bearing repository that declares the toolchains from some other rust_toolchain_repository.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_toolchain_repository_proxy-name"></a>name</td><td style="text-align: left">A unique name for this repository.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository_proxy-exec_compatible_with"></a>exec_compatible_with</td><td style="text-align: left">A list of constraints for the execution platform for this toolchain.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository_proxy-repo_mapping"></a>repo_mapping</td><td style="text-align: left">In <code>WORKSPACE</code> context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>).<br><br>This attribute is <em>not</em> supported in <code>MODULE.bazel</code> context (when invoking a repository rule inside a module extension's implementation function).</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository_proxy-target_compatible_with"></a>target_compatible_with</td><td style="text-align: left">A list of constraints for the target platform for this toolchain.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository_proxy-target_settings"></a>target_settings</td><td style="text-align: left">A list of config_settings that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository_proxy-toolchain"></a>toolchain</td><td style="text-align: left">The name of the toolchain implementation target.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_repository_proxy-toolchain_type"></a>toolchain_type</td><td style="text-align: left">The toolchain type of the toolchain to declare</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div>
<p><a id="rust_toolchain_tools_repository"></a></p>
<h2 id="rust_toolchain_tools_repository"><a class="header" href="#rust_toolchain_tools_repository">rust_toolchain_tools_repository</a></h2>
<pre>
rust_toolchain_tools_repository(<a href="flatten.html#rust_toolchain_tools_repository-name">name</a>, <a href="flatten.html#rust_toolchain_tools_repository-allocator_library">allocator_library</a>, <a href="flatten.html#rust_toolchain_tools_repository-auth">auth</a>, <a href="flatten.html#rust_toolchain_tools_repository-auth_patterns">auth_patterns</a>, <a href="flatten.html#rust_toolchain_tools_repository-dev_components">dev_components</a>,
<a href="flatten.html#rust_toolchain_tools_repository-edition">edition</a>, <a href="flatten.html#rust_toolchain_tools_repository-exec_triple">exec_triple</a>, <a href="flatten.html#rust_toolchain_tools_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="flatten.html#rust_toolchain_tools_repository-extra_rustc_flags">extra_rustc_flags</a>,
<a href="flatten.html#rust_toolchain_tools_repository-global_allocator_library">global_allocator_library</a>, <a href="flatten.html#rust_toolchain_tools_repository-netrc">netrc</a>, <a href="flatten.html#rust_toolchain_tools_repository-opt_level">opt_level</a>, <a href="flatten.html#rust_toolchain_tools_repository-repo_mapping">repo_mapping</a>,
<a href="flatten.html#rust_toolchain_tools_repository-rustfmt_version">rustfmt_version</a>, <a href="flatten.html#rust_toolchain_tools_repository-sha256s">sha256s</a>, <a href="flatten.html#rust_toolchain_tools_repository-target_triple">target_triple</a>, <a href="flatten.html#rust_toolchain_tools_repository-urls">urls</a>, <a href="flatten.html#rust_toolchain_tools_repository-version">version</a>)
</pre>
<p>Composes a single workspace containing the toolchain components for compiling on a given platform to a series of target platforms.</p>
<p>A given instance of this rule should be accompanied by a toolchain_repository_proxy invocation to declare its toolchains to Bazel; the indirection allows separating toolchain selection from toolchain fetching.</p>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-name"></a>name</td><td style="text-align: left">A unique name for this repository.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-allocator_library"></a>allocator_library</td><td style="text-align: left">Target that provides allocator functions when rust_library targets are embedded in a cc_binary.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//ffi/cc/allocator_library"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-auth"></a>auth</td><td style="text-align: left">Auth object compatible with repository_ctx.download to use when downloading files. See <a href="https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download">repository_ctx.download</a> for more details.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-auth_patterns"></a>auth_patterns</td><td style="text-align: left">A list of patterns to match against urls for which the auth object should be used.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-dev_components"></a>dev_components</td><td style="text-align: left">Whether to download the rustc-dev components (defaults to False). Requires version to be "nightly".</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-edition"></a>edition</td><td style="text-align: left">The rust edition to be used by default (2015, 2018, or 2021). If absent, every rule is required to specify its <code>edition</code> attribute.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-exec_triple"></a>exec_triple</td><td style="text-align: left">The Rust-style target that this compiler runs on</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in exec configuration</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-extra_rustc_flags"></a>extra_rustc_flags</td><td style="text-align: left">Extra flags to pass to rustc in non-exec configuration</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-global_allocator_library"></a>global_allocator_library</td><td style="text-align: left">Target that provides allocator functions when a global allocator is used with cc_common.link.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//ffi/cc/global_allocator_library"</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-netrc"></a>netrc</td><td style="text-align: left">.netrc file to use for authentication; mirrors the eponymous attribute from http_archive</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-opt_level"></a>opt_level</td><td style="text-align: left">Rustc optimization levels. For more details see the documentation for <code>rust_toolchain.opt_level</code>.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-repo_mapping"></a>repo_mapping</td><td style="text-align: left">In <code>WORKSPACE</code> context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>).<br><br>This attribute is <em>not</em> supported in <code>MODULE.bazel</code> context (when invoking a repository rule inside a module extension's implementation function).</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-rustfmt_version"></a>rustfmt_version</td><td style="text-align: left">The version of the tool among "nightly", "beta", or an exact version.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-sha256s"></a>sha256s</td><td style="text-align: left">A dict associating tool subdirectories to sha256 hashes. See <a href="flatten.html#rust_register_toolchains">rust_register_toolchains</a> for more details.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-target_triple"></a>target_triple</td><td style="text-align: left">The Rust-style target that this compiler builds for.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-urls"></a>urls</td><td style="text-align: left">A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["https://static.rust-lang.org/dist/{}.tar.xz"]</code></td></tr>
<tr><td style="text-align: left"><a id="rust_toolchain_tools_repository-version"></a>version</td><td style="text-align: left">The version of the tool among "nightly", "beta", or an exact version.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
</tbody></table>
</div><div style="break-before: page; page-break-before: always;"></div><h1 id="external-dependencies"><a class="header" href="#external-dependencies">External Dependencies</a></h1>
<p><a href="crate_universe.html">crate_universe</a> (<a href="crate_universe_bzlmod.html">crate_universe bzlmod</a>) is a tool built into <code>rules_rust</code> that can be used to fetch dependencies.</p>
<div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="crate-universe"><a class="header" href="#crate-universe">Crate Universe</a></h1>
<p>Crate Universe is a set of Bazel rule for generating Rust targets using Cargo.</p>
<p>This doc describes using crate_universe with bzlmod.</p>
<p>If you're using a WORKSPACE file, please see <a href="crate_universe.html">the WORKSPACE equivalent of this doc</a>.</p>
<p>There are some examples of using crate_universe with bzlmod in the <a href="../examples/bzlmod">example folder</a>.</p>
<h1 id="table-of-contents"><a class="header" href="#table-of-contents">Table of Contents</a></h1>
<ol>
<li><a href="crate_universe_bzlmod.html#Setup">Setup</a></li>
<li><a href="crate_universe_bzlmod.html#dependencies">Dependencies</a>
<ul>
<li><a href="crate_universe_bzlmod.html#cargo-workspaces">Cargo Workspace</a></li>
<li><a href="crate_universe_bzlmod.html#direct-dependencies">Direct Packages</a></li>
<li><a href="crate_universe_bzlmod.html#vendored-dependencies">Vendored Dependencies</a></li>
</ul>
</li>
<li><a href="crate_universe_bzlmod.html#crate">Crate reference</a>
<ul>
<li><a href="crate_universe_bzlmod.html#from_cargo">from_cargo</a></li>
<li><a href="crate_universe_bzlmod.html#from_specs">from_specs</a></li>
</ul>
</li>
</ol>
<h2 id="setup-6"><a class="header" href="#setup-6">Setup</a></h2>
<p>To use rules_rust in a project using bzlmod, add the following to your MODULE.bazel file:</p>
<pre><code class="language-starlark">bazel_dep(name = "rules_rust", version = "0.49.3")
</code></pre>
<p>You find the latest version on the <a href="https://github.com/bazelbuild/rules_rust/releases">release page</a>.</p>
<p>After adding <code>rules_rust</code> in your MODULE.bazel, set the following to begin using <code>crate_universe</code>:</p>
<pre><code class="language-starlark">crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
// # ... Dependencies
use_repo(crate, "crates")
</code></pre>
<h2 id="dependencies"><a class="header" href="#dependencies">Dependencies</a></h2>
<p>There are three different ways to declare dependencies in your MODULE.</p>
<ol>
<li>Cargo workspace</li>
<li>Direct Dependencies</li>
<li>Vendored Dependencies</li>
</ol>
<h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">Cargo Workspaces</a></h3>
<p>One of the simpler ways to wire up dependencies would be to first structure your project into a Cargo workspace.
The crates_repository rule can ingest a root Cargo.toml file and generate Bazel dependencies from there.
You find a complete example in the in the <a href="../examples/bzlmod/all_crate_deps">example folder</a>.</p>
<pre><code class="language-starlark">crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
crate.from_cargo(
name = "crates",
cargo_lockfile = "//:Cargo.lock",
manifests = ["//:Cargo.toml"],
)
use_repo(crate, "crates")
</code></pre>
<p>The generated crates_repository contains helper macros which make collecting dependencies for Bazel targets simpler.
Notably, the all_crate_deps and aliases macros (
see <a href="https://bazelbuild.github.io/rules_rust/crate_universe.html#dependencies-api">Dependencies API</a>) commonly allow the
Cargo.toml files to be the single source of truth for dependencies.
Since these macros come from the generated repository, the dependencies and alias definitions
they return will automatically update BUILD targets. In your BUILD files,
you use these macros for a Rust library as shown below:</p>
<pre><code class="language-starlark">load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "lib",
aliases = aliases(),
deps = all_crate_deps(
normal = True,
),
proc_macro_deps = all_crate_deps(
proc_macro = True,
),
)
rust_test(
name = "unit_test",
crate = ":lib",
aliases = aliases(
normal_dev = True,
proc_macro_dev = True,
),
deps = all_crate_deps(
normal_dev = True,
),
proc_macro_deps = all_crate_deps(
proc_macro_dev = True,
),
)
</code></pre>
<p>For a Rust binary that does not depend on any macro, use the following configuration
in your build file:</p>
<pre><code class="language-starlark">rust_binary(
name = "bin",
srcs = ["src/main.rs"],
deps = all_crate_deps(normal = True),
)
</code></pre>
<p>You have to repin before your first build to ensure all Bazel targets for the macros
are generated.</p>
<p>Dependency syncing and updating is done in the repository rule which means it's done during the
analysis phase of builds. As mentioned in the environments variable table above, the <code>CARGO_BAZEL_REPIN</code>
(or <code>REPIN</code>) environment variables can be used to force the rule to update dependencies and potentially
render a new lockfile. Given an instance of this repository rule named <code>crates</code>, the easiest way to
repin dependencies is to run:</p>
<pre><code class="language-shell">CARGO_BAZEL_REPIN=1 bazel sync --only=crates
</code></pre>
<p>This will result in all dependencies being updated for a project. The <code>CARGO_BAZEL_REPIN</code>
environment variable can also be used to customize how dependencies are updated.
For more details about repin, <a href="https://bazelbuild.github.io/rules_rust/crate_universe.html#crates_vendor">please refer to the documentation</a>.</p>
<h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direct Dependencies</a></h3>
<p>In cases where Rust targets have heavy interactions with other Bazel targets (<a href="https://docs.bazel.build/versions/main/be/c-cpp.html">Cc</a>, <a href="https://rules-proto-grpc.com/en/4.5.0/lang/rust.html">Proto</a>,
etc.), maintaining Cargo.toml files may have diminishing returns as things like rust-analyzer
begin to be confused about missing targets or environment variables defined only in Bazel.
In situations like this, it may be desirable to have a “Cargo free” setup. You find an example in the in the <a href="../examples/bzlmod/hello_world_no_cargo">example folder</a>.</p>
<p>crates_repository supports this through the packages attribute,
as shown below.</p>
<pre><code class="language-starlark">crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
crate.spec(package = "serde", features = ["derive"], version = "1.0")
crate.spec(package = "serde_json", version = "1.0")
crate.spec(package = "tokio", default_features=False, features = ["macros", "net", "rt-multi-thread"], version = "1.38")
crate.from_specs()
use_repo(crate, "crates")
</code></pre>
<p>Consuming dependencies may be more ergonomic in this case through the aliases defined in the new repository.
In your BUILD files, you use direct dependencies as shown below:</p>
<pre><code class="language-starlark">rust_binary(
name = "bin",
crate_root = "src/main.rs",
srcs = glob([
"src/*.rs",
]),
deps = [
# External crates
"@crates//:serde",
"@crates//:serde_json",
"@crates//:tokio",
],
visibility = ["//visibility:public"],
)
</code></pre>
<p>Notice, direct dependencies do not need repining.
Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p>
<h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">Vendored Dependencies</a></h3>
<p>In some cases, it is require that all external dependencies are vendored, meaning downloaded
and stored in the workspace. This helps, for example, to conduct licence scans, apply custom patches,
or to ensure full build reproducibility since no download error could possibly occur.
You find a complete example in the in the <a href="../examples/bzlmod/all_deps_vendor">example folder</a>.</p>
<p>For the setup, you need to add the skylib in addition to the rust rules to your MODUE.bazel.</p>
<pre><code class="language-starlark">module(
name = "deps_vendored",
version = "0.0.0"
)
###############################################################################
# B A Z E L C E N T R A L R E G I S T R Y # https://registry.bazel.build/
###############################################################################
# https://github.com/bazelbuild/bazel-skylib/releases/
bazel_dep(name = "bazel_skylib", version = "1.7.1")
# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "0.49.3")
###############################################################################
# T O O L C H A I N S
###############################################################################
# Rust toolchain
RUST_EDITION = "2021"
RUST_VERSION = "1.80.1"
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = RUST_EDITION,
versions = [RUST_VERSION],
)
use_repo(rust, "rust_toolchains")
register_toolchains("@rust_toolchains//:all")
###############################################################################
# R U S T C R A T E S
###############################################################################
crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
</code></pre>
<p>Note, it is important to load the crate_universe rules otherwise you will get an error
as the rule set is needed in the vendored target.</p>
<p>Assuming you have a package called <code>basic</code> in which you want to vendor dependencies,
then you create a folder <code>basic/3rdparty</code>. The folder name can be arbitrary,
but by convention, its either thirdparty or 3rdparty to indicate vendored dependencies.
In the 3rdparty folder, you add a target crates_vendor to declare your dependencies to vendor.
In the example, we vendor a specific version of bzip2.</p>
<pre><code class="language-starlark">load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
crates_vendor(
name = "crates_vendor",
annotations = {
"bzip2-sys": [crate.annotation(
gen_build_script = True,
)],
},
cargo_lockfile = "Cargo.Bazel.lock",
generate_build_scripts = False,
mode = "remote",
packages = {
"bzip2": crate.spec(
version = "=0.3.3",
),
},
repository_name = "basic",
tags = ["manual"],
)
</code></pre>
<p>Next, you have to run <code>Cargo build</code> to generate a Cargo.lock file with all resolved dependencies.
Then, you rename Cargo.lock to Cargo.Bazel.lock and place it inside the <code>basic/3rdparty</code> folder.</p>
<p>At this point, you have the following folder and files:</p>
<pre><code>basic
├── 3rdparty
│ ├── BUILD.bazel
│ ├── Cargo.Bazel.lock
</code></pre>
<p>Now you can run the <code>crates_vendor</code> target:</p>
<p><code>bazel run //basic/3rdparty:crates_vendor</code></p>
<p>This generates a crate folders with all configurations for the vendored dependencies.</p>
<pre><code>basic
├── 3rdparty
│ ├── cratea
│ ├── BUILD.bazel
│ ├── Cargo.Bazel.lock
</code></pre>
<p>Suppose you have an application in <code>basic/src</code> that is defined in <code>basic/BUILD.bazel</code> and
that depends on a vendored dependency. You find a list of all available vendored dependencies
in the BUILD file of the generated folder: <code>basic/3rdparty/crates/BUILD.bazel</code>
You declare a vendored dependency in you target as following:</p>
<pre><code class="language-starlark">load("@rules_rust//rust:defs.bzl", "rust_binary")
rust_binary(
name = "hello_sys",
srcs = ["src/main.rs"],
deps = ["//basic/3rdparty/crates:bzip2"],
visibility = ["//visibility:public"],
)
</code></pre>
<p>Note, the vendored dependency is not yet accessible because you have to define first
how to load the vendored dependencies. For that, you first create a file <code>sys_deps.bzl</code>
and add the following content:</p>
<pre><code class="language-starlark"># rename the default name "crate_repositories" in case you import multiple vendored folders.
load("//basic/3rdparty/crates:defs.bzl", basic_crate_repositories = "crate_repositories")
def sys_deps():
# Load the vendored dependencies
basic_crate_repositories()
</code></pre>
<p>This is straightforward, you import the generated crate_repositories from the crates folder,
rename it to avoid name clashes in case you import from multiple vendored folders, and then
just load the vendored dependencies.</p>
<p>In a WORKSPACE configuration, you would just load and call sys_deps(), but in a MODULE configuration, you cannot do that.
Instead, you create a new file <code>WORKSPACE.bzlmod</code> and add the following content.</p>
<pre><code class="language-starlark">load("//:sys_deps.bzl", "sys_deps")
sys_deps()
</code></pre>
<p>Now, you can build the project as usual.</p>
<p>There are some more examples of using crate_universe with bzlmod in the <a href="https://github.com/bazelbuild/rules_rust/blob/main/examples/bzlmod/">example folder</a>.</p>
<p><a id="crate"></a></p>
<h2 id="crate"><a class="header" href="#crate">crate</a></h2>
<pre>
crate = use_extension("@rules_rust//crate_universe:docs_bzlmod.bzl", "crate")
crate.from_cargo(<a href="crate_universe_bzlmod.html#crate.from_cargo-name">name</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-cargo_config">cargo_config</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-cargo_lockfile">cargo_lockfile</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-generate_binaries">generate_binaries</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-generate_build_scripts">generate_build_scripts</a>,
<a href="crate_universe_bzlmod.html#crate.from_cargo-manifests">manifests</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-splicing_config">splicing_config</a>, <a href="crate_universe_bzlmod.html#crate.from_cargo-supported_platform_triples">supported_platform_triples</a>)
crate.annotation(<a href="crate_universe_bzlmod.html#crate.annotation-deps">deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation-data">data</a>, <a href="crate_universe_bzlmod.html#crate.annotation-additive_build_file">additive_build_file</a>, <a href="crate_universe_bzlmod.html#crate.annotation-additive_build_file_content">additive_build_file_content</a>, <a href="crate_universe_bzlmod.html#crate.annotation-alias_rule">alias_rule</a>,
<a href="crate_universe_bzlmod.html#crate.annotation-build_script_data">build_script_data</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_data_glob">build_script_data_glob</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_deps">build_script_deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_env">build_script_env</a>,
<a href="crate_universe_bzlmod.html#crate.annotation-build_script_proc_macro_deps">build_script_proc_macro_deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_rundir">build_script_rundir</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_rustc_env">build_script_rustc_env</a>,
<a href="crate_universe_bzlmod.html#crate.annotation-build_script_toolchains">build_script_toolchains</a>, <a href="crate_universe_bzlmod.html#crate.annotation-build_script_tools">build_script_tools</a>, <a href="crate_universe_bzlmod.html#crate.annotation-compile_data">compile_data</a>, <a href="crate_universe_bzlmod.html#crate.annotation-compile_data_glob">compile_data_glob</a>, <a href="crate_universe_bzlmod.html#crate.annotation-crate">crate</a>,
<a href="crate_universe_bzlmod.html#crate.annotation-crate_features">crate_features</a>, <a href="crate_universe_bzlmod.html#crate.annotation-data_glob">data_glob</a>, <a href="crate_universe_bzlmod.html#crate.annotation-disable_pipelining">disable_pipelining</a>, <a href="crate_universe_bzlmod.html#crate.annotation-extra_aliased_targets">extra_aliased_targets</a>,
<a href="crate_universe_bzlmod.html#crate.annotation-gen_all_binaries">gen_all_binaries</a>, <a href="crate_universe_bzlmod.html#crate.annotation-gen_binaries">gen_binaries</a>, <a href="crate_universe_bzlmod.html#crate.annotation-gen_build_script">gen_build_script</a>, <a href="crate_universe_bzlmod.html#crate.annotation-override_target_bin">override_target_bin</a>,
<a href="crate_universe_bzlmod.html#crate.annotation-override_target_build_script">override_target_build_script</a>, <a href="crate_universe_bzlmod.html#crate.annotation-override_target_lib">override_target_lib</a>, <a href="crate_universe_bzlmod.html#crate.annotation-override_target_proc_macro">override_target_proc_macro</a>,
<a href="crate_universe_bzlmod.html#crate.annotation-patch_args">patch_args</a>, <a href="crate_universe_bzlmod.html#crate.annotation-patch_tool">patch_tool</a>, <a href="crate_universe_bzlmod.html#crate.annotation-patches">patches</a>, <a href="crate_universe_bzlmod.html#crate.annotation-proc_macro_deps">proc_macro_deps</a>, <a href="crate_universe_bzlmod.html#crate.annotation-repositories">repositories</a>, <a href="crate_universe_bzlmod.html#crate.annotation-rustc_env">rustc_env</a>,
<a href="crate_universe_bzlmod.html#crate.annotation-rustc_env_files">rustc_env_files</a>, <a href="crate_universe_bzlmod.html#crate.annotation-rustc_flags">rustc_flags</a>, <a href="crate_universe_bzlmod.html#crate.annotation-shallow_since">shallow_since</a>, <a href="crate_universe_bzlmod.html#crate.annotation-version">version</a>)
crate.from_specs(<a href="crate_universe_bzlmod.html#crate.from_specs-name">name</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-cargo_config">cargo_config</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-generate_binaries">generate_binaries</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-generate_build_scripts">generate_build_scripts</a>, <a href="crate_universe_bzlmod.html#crate.from_specs-splicing_config">splicing_config</a>,
<a href="crate_universe_bzlmod.html#crate.from_specs-supported_platform_triples">supported_platform_triples</a>)
crate.spec(<a href="crate_universe_bzlmod.html#crate.spec-artifact">artifact</a>, <a href="crate_universe_bzlmod.html#crate.spec-branch">branch</a>, <a href="crate_universe_bzlmod.html#crate.spec-default_features">default_features</a>, <a href="crate_universe_bzlmod.html#crate.spec-features">features</a>, <a href="crate_universe_bzlmod.html#crate.spec-git">git</a>, <a href="crate_universe_bzlmod.html#crate.spec-lib">lib</a>, <a href="crate_universe_bzlmod.html#crate.spec-package">package</a>, <a href="crate_universe_bzlmod.html#crate.spec-rev">rev</a>, <a href="crate_universe_bzlmod.html#crate.spec-tag">tag</a>, <a href="crate_universe_bzlmod.html#crate.spec-version">version</a>)
</pre>
<p><strong>TAG CLASSES</strong></p>
<p><a id="crate.from_cargo"></a></p>
<h3 id="from_cargo"><a class="header" href="#from_cargo">from_cargo</a></h3>
<p>Generates a repo @crates from a Cargo.toml / Cargo.lock pair</p>
<p><strong>Attributes</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crate.from_cargo-name"></a>name</td><td style="text-align: left">The name of the repo to generate</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"crates"</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_cargo-cargo_config"></a>cargo_config</td><td style="text-align: left">A <a href="https://doc.rust-lang.org/cargo/reference/config.html">Cargo configuration</a> file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_cargo-cargo_lockfile"></a>cargo_lockfile</td><td style="text-align: left">The path to an existing <code>Cargo.lock</code> file</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_cargo-generate_binaries"></a>generate_binaries</td><td style="text-align: left">Whether to generate <code>rust_binary</code> targets for all the binary crates in every package. By default only the <code>rust_library</code> targets are generated.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_cargo-generate_build_scripts"></a>generate_build_scripts</td><td style="text-align: left">Whether or not to generate <a href="https://doc.rust-lang.org/cargo/reference/build-scripts.html">cargo build scripts</a> by default.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_cargo-manifests"></a>manifests</td><td style="text-align: left">A list of Cargo manifests (<code>Cargo.toml</code> files).</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_cargo-splicing_config"></a>splicing_config</td><td style="text-align: left">The configuration flags to use for splicing Cargo maniests. Use <code>//crate_universe:defs.bzl\%rsplicing_config</code> to generate the value for this field. If unset, the defaults defined there will be used.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_cargo-supported_platform_triples"></a>supported_platform_triples</td><td style="text-align: left">A set of all platform triples to consider when generating dependencies.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["aarch64-apple-darwin", "aarch64-apple-ios", "aarch64-apple-ios-sim", "aarch64-linux-android", "aarch64-pc-windows-msvc", "aarch64-unknown-fuchsia", "aarch64-unknown-linux-gnu", "aarch64-unknown-nixos-gnu", "aarch64-unknown-nto-qnx710", "arm-unknown-linux-gnueabi", "armv7-linux-androideabi", "armv7-unknown-linux-gnueabi", "i686-apple-darwin", "i686-linux-android", "i686-pc-windows-msvc", "i686-unknown-freebsd", "i686-unknown-linux-gnu", "powerpc-unknown-linux-gnu", "riscv32imc-unknown-none-elf", "riscv64gc-unknown-none-elf", "s390x-unknown-linux-gnu", "thumbv7em-none-eabi", "thumbv8m.main-none-eabi", "wasm32-unknown-unknown", "wasm32-wasi", "wasm32-wasip1", "x86_64-apple-darwin", "x86_64-apple-ios", "x86_64-linux-android", "x86_64-pc-windows-msvc", "x86_64-unknown-freebsd", "x86_64-unknown-fuchsia", "x86_64-unknown-linux-gnu", "x86_64-unknown-nixos-gnu", "x86_64-unknown-none"]</code></td></tr>
</tbody></table>
</div>
<p><a id="crate.annotation"></a></p>
<h3 id="annotation"><a class="header" href="#annotation">annotation</a></h3>
<p><strong>Attributes</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crate.annotation-deps"></a>deps</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-data"></a>data</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-additive_build_file"></a>additive_build_file</td><td style="text-align: left">A file containing extra contents to write to the bottom of generated BUILD files.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-additive_build_file_content"></a>additive_build_file_content</td><td style="text-align: left">Extra contents to write to the bottom of generated BUILD files.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-alias_rule"></a>alias_rule</td><td style="text-align: left">Alias rule to use instead of <code>native.alias()</code>. Overrides <a href="crate_universe_bzlmod.html#render_config">render_config</a>'s 'default_alias_rule'.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_data"></a>build_script_data</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_data_glob"></a>build_script_data_glob</td><td style="text-align: left">A list of glob patterns to add to a crate's <code>cargo_build_script::data</code> attribute</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_deps"></a>build_script_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_env"></a>build_script_env</td><td style="text-align: left">Additional environment variables to set on a crate's <code>cargo_build_script::env</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_proc_macro_deps"></a>build_script_proc_macro_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::proc_macro_deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_rundir"></a>build_script_rundir</td><td style="text-align: left">An override for the build script's rundir attribute.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_rustc_env"></a>build_script_rustc_env</td><td style="text-align: left">Additional environment variables to set on a crate's <code>cargo_build_script::env</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_toolchains"></a>build_script_toolchains</td><td style="text-align: left">A list of labels to set on a crates's <code>cargo_build_script::toolchains</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_tools"></a>build_script_tools</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::tools</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-compile_data"></a>compile_data</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::compile_data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-compile_data_glob"></a>compile_data_glob</td><td style="text-align: left">A list of glob patterns to add to a crate's <code>rust_library::compile_data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-crate"></a>crate</td><td style="text-align: left">The name of the crate the annotation is applied to</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-crate_features"></a>crate_features</td><td style="text-align: left">A list of strings to add to a crate's <code>rust_library::crate_features</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-data_glob"></a>data_glob</td><td style="text-align: left">A list of glob patterns to add to a crate's <code>rust_library::data</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-disable_pipelining"></a>disable_pipelining</td><td style="text-align: left">If True, disables pipelining for library targets for this crate.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-extra_aliased_targets"></a>extra_aliased_targets</td><td style="text-align: left">A list of targets to add to the generated aliases in the root crate_universe repository.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-gen_all_binaries"></a>gen_all_binaries</td><td style="text-align: left">If true, generates <code>rust_binary</code> targets for all of the crates bins</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-gen_binaries"></a>gen_binaries</td><td style="text-align: left">As a list, the subset of the crate's bins that should get <code>rust_binary</code> targets produced.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-gen_build_script"></a>gen_build_script</td><td style="text-align: left">An authorative flag to determine whether or not to produce <code>cargo_build_script</code> targets for the current crate. Supported values are 'on', 'off', and 'auto'.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"auto"</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-override_target_bin"></a>override_target_bin</td><td style="text-align: left">An optional alternate taget to use when something depends on this crate to allow the parent repo to provide its own version of this dependency.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-override_target_build_script"></a>override_target_build_script</td><td style="text-align: left">An optional alternate taget to use when something depends on this crate to allow the parent repo to provide its own version of this dependency.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-override_target_lib"></a>override_target_lib</td><td style="text-align: left">An optional alternate taget to use when something depends on this crate to allow the parent repo to provide its own version of this dependency.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-override_target_proc_macro"></a>override_target_proc_macro</td><td style="text-align: left">An optional alternate taget to use when something depends on this crate to allow the parent repo to provide its own version of this dependency.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-patch_args"></a>patch_args</td><td style="text-align: left">The <code>patch_args</code> attribute of a Bazel repository rule. See <a href="https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_args">http_archive.patch_args</a></td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-patch_tool"></a>patch_tool</td><td style="text-align: left">The <code>patch_tool</code> attribute of a Bazel repository rule. See <a href="https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_tool">http_archive.patch_tool</a></td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-patches"></a>patches</td><td style="text-align: left">The <code>patches</code> attribute of a Bazel repository rule. See <a href="https://docs.bazel.build/versions/main/repo/http.html#http_archive-patches">http_archive.patches</a></td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::proc_macro_deps</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-repositories"></a>repositories</td><td style="text-align: left">A list of repository names specified from <code>crate.from_cargo(name=...)</code> that this annotation is applied to. Defaults to all repositories.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-rustc_env"></a>rustc_env</td><td style="text-align: left">Additional variables to set on a crate's <code>rust_library::rustc_env</code> attribute.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">A list of labels to set on a crate's <code>rust_library::rustc_env_files</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-rustc_flags"></a>rustc_flags</td><td style="text-align: left">A list of strings to set on a crate's <code>rust_library::rustc_flags</code> attribute.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-shallow_since"></a>shallow_since</td><td style="text-align: left">An optional timestamp used for crates originating from a git repository instead of a crate registry. This flag optimizes fetching the source code.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-version"></a>version</td><td style="text-align: left">The versions of the crate the annotation is applied to. Defaults to all versions.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"*"</code></td></tr>
</tbody></table>
</div>
<p><a id="crate.from_specs"></a></p>
<h3 id="from_specs"><a class="header" href="#from_specs">from_specs</a></h3>
<p>Generates a repo @crates from the defined <code>spec</code> tags</p>
<p><strong>Attributes</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crate.from_specs-name"></a>name</td><td style="text-align: left">The name of the repo to generate</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"crates"</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_specs-cargo_config"></a>cargo_config</td><td style="text-align: left">A <a href="https://doc.rust-lang.org/cargo/reference/config.html">Cargo configuration</a> file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_specs-generate_binaries"></a>generate_binaries</td><td style="text-align: left">Whether to generate <code>rust_binary</code> targets for all the binary crates in every package. By default only the <code>rust_library</code> targets are generated.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_specs-generate_build_scripts"></a>generate_build_scripts</td><td style="text-align: left">Whether or not to generate <a href="https://doc.rust-lang.org/cargo/reference/build-scripts.html">cargo build scripts</a> by default.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_specs-splicing_config"></a>splicing_config</td><td style="text-align: left">The configuration flags to use for splicing Cargo maniests. Use <code>//crate_universe:defs.bzl\%rsplicing_config</code> to generate the value for this field. If unset, the defaults defined there will be used.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.from_specs-supported_platform_triples"></a>supported_platform_triples</td><td style="text-align: left">A set of all platform triples to consider when generating dependencies.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["aarch64-apple-darwin", "aarch64-apple-ios", "aarch64-apple-ios-sim", "aarch64-linux-android", "aarch64-pc-windows-msvc", "aarch64-unknown-fuchsia", "aarch64-unknown-linux-gnu", "aarch64-unknown-nixos-gnu", "aarch64-unknown-nto-qnx710", "arm-unknown-linux-gnueabi", "armv7-linux-androideabi", "armv7-unknown-linux-gnueabi", "i686-apple-darwin", "i686-linux-android", "i686-pc-windows-msvc", "i686-unknown-freebsd", "i686-unknown-linux-gnu", "powerpc-unknown-linux-gnu", "riscv32imc-unknown-none-elf", "riscv64gc-unknown-none-elf", "s390x-unknown-linux-gnu", "thumbv7em-none-eabi", "thumbv8m.main-none-eabi", "wasm32-unknown-unknown", "wasm32-wasi", "wasm32-wasip1", "x86_64-apple-darwin", "x86_64-apple-ios", "x86_64-linux-android", "x86_64-pc-windows-msvc", "x86_64-unknown-freebsd", "x86_64-unknown-fuchsia", "x86_64-unknown-linux-gnu", "x86_64-unknown-nixos-gnu", "x86_64-unknown-none"]</code></td></tr>
</tbody></table>
</div>
<p><a id="crate.spec"></a></p>
<h3 id="spec"><a class="header" href="#spec">spec</a></h3>
<p><strong>Attributes</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crate.spec-artifact"></a>artifact</td><td style="text-align: left">Set to 'bin' to pull in a binary crate as an artifact dependency. Requires a nightly Cargo.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-branch"></a>branch</td><td style="text-align: left">The git branch of the remote crate. Tied with the <code>git</code> param. Only one of branch, tag or rev may be specified. Specifying <code>rev</code> is recommended for fully-reproducible builds.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-default_features"></a>default_features</td><td style="text-align: left">Maps to the <code>default-features</code> flag.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-features"></a>features</td><td style="text-align: left">A list of features to use for the crate.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-git"></a>git</td><td style="text-align: left">The Git url to use for the crate. Cannot be used with <code>version</code>.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-lib"></a>lib</td><td style="text-align: left">If using <code>artifact = 'bin'</code>, additionally setting <code>lib = True</code> declares a dependency on both the package's library and binary, as opposed to just the binary.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-package"></a>package</td><td style="text-align: left">The explicit name of the package.</td><td style="text-align: left">String</td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-rev"></a>rev</td><td style="text-align: left">The git revision of the remote crate. Tied with the <code>git</code> param. Only one of branch, tag or rev may be specified.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-tag"></a>tag</td><td style="text-align: left">The git tag of the remote crate. Tied with the <code>git</code> param. Only one of branch, tag or rev may be specified. Specifying <code>rev</code> is recommended for fully-reproducible builds.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-version"></a>version</td><td style="text-align: left">The exact version of the crate. Cannot be used with <code>git</code>.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
</tbody></table>
</div><div style="break-before: page; page-break-before: always;"></div><!-- Generated with Stardoc: http://skydoc.bazel.build -->
<h1 id="crate-universe-1"><a class="header" href="#crate-universe-1">Crate Universe</a></h1>
<p>Crate Universe is a set of Bazel rule for generating Rust targets using Cargo.</p>
<p>This doc describes using crate_universe from a WORKSPACE file.</p>
<p>If you're using bzlmod, please see <a href="crate_universe_bzlmod.html">the bzlmod equivalent of this doc</a>.</p>
<h2 id="setup-7"><a class="header" href="#setup-7">Setup</a></h2>
<p>After loading <code>rules_rust</code> in your workspace, set the following to begin using <code>crate_universe</code>:</p>
<pre><code class="language-python">load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies")
crate_universe_dependencies()
</code></pre>
<p>Note that if the current version of <code>rules_rust</code> is not a release artifact, you may need to set additional
flags such as <a href="crate_universe.html#crate_universe_dependencies-bootstrap"><code>bootstrap = True</code></a> on the <code>crate_universe_dependencies</code>
call above or <a href="crate_universe.html#crates_repository-generator_urls">crates_repository::generator_urls</a> in uses of <code>crates_repository</code>.</p>
<h2 id="rules-1"><a class="header" href="#rules-1">Rules</a></h2>
<ul>
<li><a href="crate_universe.html#crates_repository">crates_repository</a></li>
<li><a href="crate_universe.html#crates_vendor">crates_vendor</a></li>
</ul>
<h2 id="utility-macros"><a class="header" href="#utility-macros">Utility Macros</a></h2>
<ul>
<li><a href="crate_universe.html#crate_universe_dependencies">crate_universe_dependencies</a></li>
<li><a href="crate_universe.html#crateannotation">crate.annotation</a></li>
<li><a href="crate_universe.html#crateselect">crate.select</a></li>
<li><a href="crate_universe.html#cratespec">crate.spec</a></li>
<li><a href="crate_universe.html#crateworkspace_member">crate.workspace_member</a></li>
<li><a href="crate_universe.html#render_config">render_config</a></li>
<li><a href="crate_universe.html#splicing_config">splicing_config</a></li>
</ul>
<h2 id="workflows"><a class="header" href="#workflows">Workflows</a></h2>
<p>The <a href="crate_universe.html#crates_repository"><code>crates_repository</code></a> rule (the primary repository rule of <code>rules_rust</code>'s cargo support) supports a number of different
ways users can express and organize their dependencies. The most common are listed below though there are more to be found in
the <a href="https://github.com/bazelbuild/rules_rust/tree/main/examples/crate_universe">./examples/crate_universe</a> directory.</p>
<h3 id="cargo-workspaces-1"><a class="header" href="#cargo-workspaces-1">Cargo Workspaces</a></h3>
<p>One of the simpler ways to wire up dependencies would be to first structure your project into a <a href="https://doc.rust-lang.org/book/ch14-03-cargo-workspaces.html">Cargo workspace</a>.
The <code>crates_repository</code> rule can ingest a root <code>Cargo.toml</code> file and generate dependencies from there.</p>
<pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crates_repository")
crates_repository(
name = "crate_index",
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:Cargo.Bazel.lock",
manifests = ["//:Cargo.toml"],
)
load("@crate_index//:defs.bzl", "crate_repositories")
crate_repositories()
</code></pre>
<p>The generated <code>crates_repository</code> contains helper macros which make collecting dependencies for Bazel targets simpler.
Notably, the <code>all_crate_deps</code> and <code>aliases</code> macros (see <a href="crate_universe.html#dependencies-api">Dependencies API</a>) commonly allow the
<code>Cargo.toml</code> files to be the single source of truth for dependencies. Since these macros come from the generated
repository, the dependencies and alias definitions they return will automatically update BUILD targets.</p>
<pre><code class="language-python">load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "lib",
aliases = aliases(),
deps = all_crate_deps(
normal = True,
),
proc_macro_deps = all_crate_deps(
proc_macro = True,
),
)
rust_test(
name = "unit_test",
crate = ":lib",
aliases = aliases(
normal_dev = True,
proc_macro_dev = True,
),
deps = all_crate_deps(
normal_dev = True,
),
proc_macro_deps = all_crate_deps(
proc_macro_dev = True,
),
)
</code></pre>
<h3 id="direct-packages"><a class="header" href="#direct-packages">Direct Packages</a></h3>
<p>In cases where Rust targets have heavy interractions with other Bazel targests (<a href="https://docs.bazel.build/versions/main/be/c-cpp.html">Cc</a>, <a href="https://rules-proto-grpc.com/en/latest/lang/rust.html">Proto</a>, etc.),
maintaining <code>Cargo.toml</code> files may have deminishing returns as things like <a href="https://rust-analyzer.github.io/">rust-analyzer</a> begin to be confused
about missing targets or environment variables defined only in Bazel. In workspaces like this, it may be desirable
to have a "Cargo free" setup. <code>crates_repository</code> supports this through the <code>packages</code> attribute.</p>
<pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository", "render_config")
crates_repository(
name = "crate_index",
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:Cargo.Bazel.lock",
packages = {
"async-trait": crate.spec(
version = "0.1.51",
),
"mockall": crate.spec(
version = "0.10.2",
),
"tokio": crate.spec(
version = "1.12.0",
),
},
# Setting the default package name to `""` forces the use of the macros defined in this repository
# to always use the root package when looking for dependencies or aliases. This should be considered
# optional as the repository also exposes alises for easy access to all dependencies.
render_config = render_config(
default_package_name = ""
),
)
load("@crate_index//:defs.bzl", "crate_repositories")
crate_repositories()
</code></pre>
<p>Consuming dependencies may be more ergonomic in this case through the aliases defined in the new repository.</p>
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "lib",
deps = [
"@crate_index//:tokio",
],
proc_macro_deps = [
"@crate_index//:async-trait",
],
)
rust_test(
name = "unit_test",
crate = ":lib",
deps = [
"@crate_index//:mockall",
],
)
</code></pre>
<h3 id="binary-dependencies"><a class="header" href="#binary-dependencies">Binary dependencies</a></h3>
<p>Neither of the above approaches supports depending on binary-only packages.</p>
<p>In order to depend on a Cargo package that contains binaries and no library, you
will need to do one of the following:</p>
<ul>
<li>
<p>Fork the package to add an empty lib.rs, which makes the package visible to
Cargo metadata and compatible with the above approaches;</p>
</li>
<li>
<p>Or handwrite your own build target for the binary, use <code>http_archive</code> to
import its source code, and use <code>crates_repository</code> to make build targets for
its dependencies. This is demonstrated below using the <code>rustfilt</code> crate as an
example.</p>
</li>
</ul>
<pre><code class="language-python"># in WORKSPACE.bazel
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rustfilt",
build_file = "//rustfilt:BUILD.rustfilt.bazel",
sha256 = "c8d748b182c8f95224336d20dcc5609598af612581ce60cfb29da4dc8d0091f2",
strip_prefix = "rustfilt-0.2.1",
type = "tar.gz",
urls = ["https://static.crates.io/crates/rustfilt/rustfilt-0.2.1.crate"],
)
load("@rules_rust//crate_universe:defs.bzl", "crates_repository")
crates_repository(
name = "rustfilt_deps",
cargo_lockfile = "//rustfilt:Cargo.lock",
manifests = ["@rustfilt//:Cargo.toml"],
)
load("@rustfilt_deps//:defs.bzl", rustfilt_deps = "crate_repositories")
rustfilt_deps()
</code></pre>
<pre><code class="language-python"># in rustfilt/BUILD.rustfilt.bazel
load("@rules_rust//rust:defs.bzl", "rust_binary")
rust_binary(
name = "rustfilt",
srcs = glob(["src/**/*.rs"]),
edition = "2018",
deps = [
"@rustfilt_deps//:clap",
"@rustfilt_deps//:lazy_static",
"@rustfilt_deps//:regex",
"@rustfilt_deps//:rustc-demangle",
],
)
</code></pre>
<p>If you use either <code>crates_repository</code> or <code>crates_vendor</code> to depend on a Cargo
package that contains <em>both</em> a library crate <em>and</em> binaries, by default only the
library gets made available to Bazel. To generate Bazel targets for the binary
crates as well, you must opt in to it with an annotation on the package:</p>
<pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crates_repository", "crate")
crates_repository(
name = "crate_index",
annotations = {
"thepackage": [crate.annotation(
gen_binaries = True,
# Or, to expose just a subset of the package's binaries by name:
gen_binaries = ["rustfilt"],
)],
},
# Or, to expose every binary of every package:
generate_binaries = True,
...
)
</code></pre>
<h2 id="dependencies-api"><a class="header" href="#dependencies-api">Dependencies API</a></h2>
<p>After rendering dependencies, convenience macros may also be generated to provide
convenient accessors to larger sections of the dependency graph.</p>
<ul>
<li><a href="crate_universe.html#aliases">aliases</a></li>
<li><a href="crate_universe.html#crate_deps">crate_deps</a></li>
<li><a href="crate_universe.html#all_crate_deps">all_crate_deps</a></li>
<li><a href="crate_universe.html#crate_repositories">crate_repositories</a></li>
</ul>
<h2 id="building-crates-with-complicated-dependencies"><a class="header" href="#building-crates-with-complicated-dependencies">Building crates with complicated dependencies</a></h2>
<p>Some crates have build.rs scripts which are complicated to run. Typically these build C++ (or other languages), or attempt to find pre-installed libraries on the build machine.</p>
<p>There are a few approaches to making sure these run:</p>
<h3 id="some-things-work-without-intervention"><a class="header" href="#some-things-work-without-intervention">Some things work without intervention</a></h3>
<p>Some build scripts will happily run without any support needed.</p>
<p>rules_rust already supplies a configured C++ toolchain as input to build script execution, and sets variables like <code>CC</code>, <code>CXX</code>, <code>LD</code>, <code>LDFLAGS</code>, etc as needed. Many crates which invoke a compiler with the default environment, or forward these env vars, will Just Work (e.g. if using <a href="https://github.com/rust-lang/cc-rs"><code>cc-rs</code></a>).</p>
<p>rules_rust is open to PRs which make build scripts more likely to work by default with intervention assuming they're broadly applicable (e.g. setting extra widely-known env vars is probably fine, wiring up additional toolchains like <code>cmake</code> that aren't present by default for most Bazel users probably isn't).</p>
<h3 id="supplying-extra-tools-to-build"><a class="header" href="#supplying-extra-tools-to-build">Supplying extra tools to build</a></h3>
<p>Some build scripts can be made to work by pulling in some extra files and making them available to the build script.</p>
<p>Commonly this is done by passing the file to the <code>build_script_data</code> annotation for the crate, and using <code>build_script_env</code> to tell the build script where the file is. That env var may often use <code>$(execroot)</code> to get the path to the label, or <code>$${pwd}/</code> as a prefix if the path given is relative to the execroot (as will frequently happen when using a toolchain).A</p>
<p>There is an example of this in the "complicated dependencies" section of https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/WORKSPACE.bazel which builds libz-ng-sys.</p>
<h3 id="building-with-bazel-and-supplying-via-an-override"><a class="header" href="#building-with-bazel-and-supplying-via-an-override">Building with Bazel and supplying via an override</a></h3>
<p>Some build scripts have hooks to allow replacing parts that are complicated to build with output prepared by Bazel.</p>
<p>We can use those hooks by specifying paths (generally using the <code>build_script_data</code> and <code>build_script_env</code> annotations) and pointing them at labels which Bazel will then build. These env vars may often use <code>$(execroot)</code> to get the path to the label, or <code>$${pwd}/</code> as a prefix if the path given is relative to the execroot (as will frequently happen when using a toolchain).</p>
<p>There is an example of this in the "complicated dependencies" section of https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/WORKSPACE.bazel which builds boring-sys.</p>
<hr />
<hr />
<p><a id="crates_vendor"></a></p>
<h2 id="crates_vendor"><a class="header" href="#crates_vendor">crates_vendor</a></h2>
<pre>
crates_vendor(<a href="crate_universe.html#crates_vendor-name">name</a>, <a href="crate_universe.html#crates_vendor-annotations">annotations</a>, <a href="crate_universe.html#crates_vendor-bazel">bazel</a>, <a href="crate_universe.html#crates_vendor-buildifier">buildifier</a>, <a href="crate_universe.html#crates_vendor-cargo_bazel">cargo_bazel</a>, <a href="crate_universe.html#crates_vendor-cargo_config">cargo_config</a>, <a href="crate_universe.html#crates_vendor-cargo_lockfile">cargo_lockfile</a>,
<a href="crate_universe.html#crates_vendor-generate_binaries">generate_binaries</a>, <a href="crate_universe.html#crates_vendor-generate_build_scripts">generate_build_scripts</a>, <a href="crate_universe.html#crates_vendor-generate_target_compatible_with">generate_target_compatible_with</a>, <a href="crate_universe.html#crates_vendor-manifests">manifests</a>,
<a href="crate_universe.html#crates_vendor-mode">mode</a>, <a href="crate_universe.html#crates_vendor-packages">packages</a>, <a href="crate_universe.html#crates_vendor-render_config">render_config</a>, <a href="crate_universe.html#crates_vendor-repository_name">repository_name</a>, <a href="crate_universe.html#crates_vendor-splicing_config">splicing_config</a>,
<a href="crate_universe.html#crates_vendor-supported_platform_triples">supported_platform_triples</a>, <a href="crate_universe.html#crates_vendor-vendor_path">vendor_path</a>)
</pre>
<p>A rule for defining Rust dependencies (crates) and writing targets for them to the current workspace.
This rule is useful for users whose workspaces are expected to be consumed in other workspaces as the
rendered <code>BUILD</code> files reduce the number of workspace dependencies, allowing for easier loads. This rule
handles all the same <a href="crate_universe.html#workflows">workflows</a> <code>crate_universe</code> rules do.</p>
<p>Example:</p>
<p>Given the following workspace structure:</p>
<pre><code class="language-text">[workspace]/
WORKSPACE
BUILD
Cargo.toml
3rdparty/
BUILD
src/
main.rs
</code></pre>
<p>The following is something that'd be found in <code>3rdparty/BUILD</code>:</p>
<pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crates_vendor", "crate")
crates_vendor(
name = "crates_vendor",
annotations = {
"rand": [crate.annotation(
default_features = False,
features = ["small_rng"],
)],
},
cargo_lockfile = "//:Cargo.Bazel.lock",
manifests = ["//:Cargo.toml"],
mode = "remote",
vendor_path = "crates",
tags = ["manual"],
)
</code></pre>
<p>The above creates a target that can be run to write <code>BUILD</code> files into the <code>3rdparty</code>
directory next to where the target is defined. To run it, simply call:</p>
<pre><code class="language-shell">bazel run //3rdparty:crates_vendor
</code></pre>
<p><a id="#crates_vendor_repinning_updating_dependencies"></a></p>
<h3 id="repinning--updating-dependencies"><a class="header" href="#repinning--updating-dependencies">Repinning / Updating Dependencies</a></h3>
<p>Repinning dependencies is controlled by both the <code>CARGO_BAZEL_REPIN</code> environment variable or the <code>--repin</code>
flag to the <code>crates_vendor</code> binary. To update dependencies, simply add the flag ro your <code>bazel run</code> invocation.</p>
<pre><code class="language-shell">bazel run //3rdparty:crates_vendor -- --repin
</code></pre>
<p>Under the hood, <code>--repin</code> will trigger a <a href="https://doc.rust-lang.org/cargo/commands/cargo-update.html">cargo update</a>
call against the generated workspace. The following table describes how to control particular values passed to the
<code>cargo update</code> command.</p>
<div class="table-wrapper"><table><thead><tr><th>Value</th><th>Cargo command</th></tr></thead><tbody>
<tr><td>Any of [<code>true</code>, <code>1</code>, <code>yes</code>, <code>on</code>, <code>workspace</code>]</td><td><code>cargo update --workspace</code></td></tr>
<tr><td>Any of [<code>full</code>, <code>eager</code>, <code>all</code>]</td><td><code>cargo update</code></td></tr>
<tr><td><code>package_name</code></td><td><code>cargo upgrade --package package_name</code></td></tr>
<tr><td><code>package_name@1.2.3</code></td><td><code>cargo upgrade --package package_name --precise 1.2.3</code></td></tr>
</tbody></table>
</div>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crates_vendor-name"></a>name</td><td style="text-align: left">A unique name for this target.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-annotations"></a>annotations</td><td style="text-align: left">Extra settings to apply to crates. See <a href="crate_universe.html#crateannotation">crate.annotation</a>.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; List of strings</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-bazel"></a>bazel</td><td style="text-align: left">The path to a bazel binary used to locate the output_base for the current workspace.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-buildifier"></a>buildifier</td><td style="text-align: left">The path to a <a href="https://github.com/bazelbuild/buildtools/blob/5.0.1/buildifier/README.md">buildifier</a> binary used to format generated BUILD files.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rules_rust//crate_universe/private/vendor:buildifier"</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-cargo_bazel"></a>cargo_bazel</td><td style="text-align: left">The cargo-bazel binary to use for vendoring. If this attribute is not set, then a <code>CARGO_BAZEL_GENERATOR_PATH</code> action env will be used.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@@cargo_bazel_bootstrap//:binary"</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-cargo_config"></a>cargo_config</td><td style="text-align: left">A <a href="https://doc.rust-lang.org/cargo/reference/config.html">Cargo configuration</a> file.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-cargo_lockfile"></a>cargo_lockfile</td><td style="text-align: left">The path to an existing <code>Cargo.lock</code> file</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-generate_binaries"></a>generate_binaries</td><td style="text-align: left">Whether to generate <code>rust_binary</code> targets for all the binary crates in every package. By default only the <code>rust_library</code> targets are generated.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-generate_build_scripts"></a>generate_build_scripts</td><td style="text-align: left">Whether or not to generate <a href="https://doc.rust-lang.org/cargo/reference/build-scripts.html">cargo build scripts</a> by default.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-generate_target_compatible_with"></a>generate_target_compatible_with</td><td style="text-align: left">DEPRECATED: Moved to <code>render_config</code>.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-manifests"></a>manifests</td><td style="text-align: left">A list of Cargo manifests (<code>Cargo.toml</code> files).</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-mode"></a>mode</td><td style="text-align: left">Flags determining how crates should be vendored. <code>local</code> is where crate source and BUILD files are written to the repository. <code>remote</code> is where only BUILD files are written and repository rules used to fetch source code.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"remote"</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-packages"></a>packages</td><td style="text-align: left">A set of crates (packages) specifications to depend on. See <a href="crate_universe.html#crate.spec">crate.spec</a>.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-render_config"></a>render_config</td><td style="text-align: left">The configuration flags to use for rendering. Use <code>//crate_universe:defs.bzl\%render_config</code> to generate the value for this field. If unset, the defaults defined there will be used.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-repository_name"></a>repository_name</td><td style="text-align: left">The name of the repository to generate for <code>remote</code> vendor modes. If unset, the label name will be used</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-splicing_config"></a>splicing_config</td><td style="text-align: left">The configuration flags to use for splicing Cargo maniests. Use <code>//crate_universe:defs.bzl\%rsplicing_config</code> to generate the value for this field. If unset, the defaults defined there will be used.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-supported_platform_triples"></a>supported_platform_triples</td><td style="text-align: left">A set of all platform triples to consider when generating dependencies.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["aarch64-apple-darwin", "aarch64-apple-ios", "aarch64-apple-ios-sim", "aarch64-linux-android", "aarch64-pc-windows-msvc", "aarch64-unknown-fuchsia", "aarch64-unknown-linux-gnu", "aarch64-unknown-nixos-gnu", "aarch64-unknown-nto-qnx710", "arm-unknown-linux-gnueabi", "armv7-linux-androideabi", "armv7-unknown-linux-gnueabi", "i686-apple-darwin", "i686-linux-android", "i686-pc-windows-msvc", "i686-unknown-freebsd", "i686-unknown-linux-gnu", "powerpc-unknown-linux-gnu", "riscv32imc-unknown-none-elf", "riscv64gc-unknown-none-elf", "s390x-unknown-linux-gnu", "thumbv7em-none-eabi", "thumbv8m.main-none-eabi", "wasm32-unknown-unknown", "wasm32-wasi", "wasm32-wasip1", "x86_64-apple-darwin", "x86_64-apple-ios", "x86_64-linux-android", "x86_64-pc-windows-msvc", "x86_64-unknown-freebsd", "x86_64-unknown-fuchsia", "x86_64-unknown-linux-gnu", "x86_64-unknown-nixos-gnu", "x86_64-unknown-none"]</code></td></tr>
<tr><td style="text-align: left"><a id="crates_vendor-vendor_path"></a>vendor_path</td><td style="text-align: left">The path to a directory to write files into. Absolute paths will be treated as relative to the workspace root</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"crates"</code></td></tr>
</tbody></table>
</div>
<p><a id="aliases"></a></p>
<h2 id="aliases"><a class="header" href="#aliases">aliases</a></h2>
<pre>
aliases(<a href="crate_universe.html#aliases-normal">normal</a>, <a href="crate_universe.html#aliases-normal_dev">normal_dev</a>, <a href="crate_universe.html#aliases-proc_macro">proc_macro</a>, <a href="crate_universe.html#aliases-proc_macro_dev">proc_macro_dev</a>, <a href="crate_universe.html#aliases-build">build</a>, <a href="crate_universe.html#aliases-build_proc_macro">build_proc_macro</a>, <a href="crate_universe.html#aliases-package_name">package_name</a>)
</pre>
<p>Produces a map of Crate alias names to their original label</p>
<p>If no dependency kinds are specified, <code>normal</code> and <code>proc_macro</code> are used by default.
Setting any one flag will otherwise determine the contents of the returned dict.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="aliases-normal"></a>normal</td><td style="text-align: left">If True, normal dependencies are included in the output list.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="aliases-normal_dev"></a>normal_dev</td><td style="text-align: left">If True, normal dev dependencies will be included in the output list..</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="aliases-proc_macro"></a>proc_macro</td><td style="text-align: left">If True, proc_macro dependencies are included in the output list.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="aliases-proc_macro_dev"></a>proc_macro_dev</td><td style="text-align: left">If True, dev proc_macro dependencies are included in the output list.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="aliases-build"></a>build</td><td style="text-align: left">If True, build dependencies are included in the output list.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="aliases-build_proc_macro"></a>build_proc_macro</td><td style="text-align: left">If True, build proc_macro dependencies are included in the output list.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="aliases-package_name"></a>package_name</td><td style="text-align: left">The package name of the set of dependencies to look up. Defaults to <code>native.package_name()</code> when unset.</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>dict: The aliases of all associated packages</p>
<p><a id="all_crate_deps"></a></p>
<h2 id="all_crate_deps"><a class="header" href="#all_crate_deps">all_crate_deps</a></h2>
<pre>
all_crate_deps(<a href="crate_universe.html#all_crate_deps-normal">normal</a>, <a href="crate_universe.html#all_crate_deps-normal_dev">normal_dev</a>, <a href="crate_universe.html#all_crate_deps-proc_macro">proc_macro</a>, <a href="crate_universe.html#all_crate_deps-proc_macro_dev">proc_macro_dev</a>, <a href="crate_universe.html#all_crate_deps-build">build</a>, <a href="crate_universe.html#all_crate_deps-build_proc_macro">build_proc_macro</a>,
<a href="crate_universe.html#all_crate_deps-package_name">package_name</a>)
</pre>
<p>Finds the fully qualified label of all requested direct crate dependencies for the package where this macro is called.</p>
<p>If no parameters are set, all normal dependencies are returned. Setting any one flag will
otherwise impact the contents of the returned list.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="all_crate_deps-normal"></a>normal</td><td style="text-align: left">If True, normal dependencies are included in the output list.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="all_crate_deps-normal_dev"></a>normal_dev</td><td style="text-align: left">If True, normal dev dependencies will be included in the output list..</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="all_crate_deps-proc_macro"></a>proc_macro</td><td style="text-align: left">If True, proc_macro dependencies are included in the output list.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="all_crate_deps-proc_macro_dev"></a>proc_macro_dev</td><td style="text-align: left">If True, dev proc_macro dependencies are included in the output list.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="all_crate_deps-build"></a>build</td><td style="text-align: left">If True, build dependencies are included in the output list.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="all_crate_deps-build_proc_macro"></a>build_proc_macro</td><td style="text-align: left">If True, build proc_macro dependencies are included in the output list.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="all_crate_deps-package_name"></a>package_name</td><td style="text-align: left">The package name of the set of dependencies to look up. Defaults to <code>native.package_name()</code> when unset.</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>list: A list of labels to generated rust targets (str)</p>
<p><a id="crate.annotation"></a></p>
<h2 id="crateannotation"><a class="header" href="#crateannotation">crate.annotation</a></h2>
<pre>
crate.annotation(<a href="crate_universe.html#crate.annotation-version">version</a>, <a href="crate_universe.html#crate.annotation-additive_build_file">additive_build_file</a>, <a href="crate_universe.html#crate.annotation-additive_build_file_content">additive_build_file_content</a>, <a href="crate_universe.html#crate.annotation-alias_rule">alias_rule</a>,
<a href="crate_universe.html#crate.annotation-build_script_compile_data">build_script_compile_data</a>, <a href="crate_universe.html#crate.annotation-build_script_data">build_script_data</a>, <a href="crate_universe.html#crate.annotation-build_script_tools">build_script_tools</a>,
<a href="crate_universe.html#crate.annotation-build_script_data_glob">build_script_data_glob</a>, <a href="crate_universe.html#crate.annotation-build_script_deps">build_script_deps</a>, <a href="crate_universe.html#crate.annotation-build_script_env">build_script_env</a>,
<a href="crate_universe.html#crate.annotation-build_script_proc_macro_deps">build_script_proc_macro_deps</a>, <a href="crate_universe.html#crate.annotation-build_script_rundir">build_script_rundir</a>, <a href="crate_universe.html#crate.annotation-build_script_rustc_env">build_script_rustc_env</a>,
<a href="crate_universe.html#crate.annotation-build_script_toolchains">build_script_toolchains</a>, <a href="crate_universe.html#crate.annotation-compile_data">compile_data</a>, <a href="crate_universe.html#crate.annotation-compile_data_glob">compile_data_glob</a>, <a href="crate_universe.html#crate.annotation-crate_features">crate_features</a>, <a href="crate_universe.html#crate.annotation-data">data</a>,
<a href="crate_universe.html#crate.annotation-data_glob">data_glob</a>, <a href="crate_universe.html#crate.annotation-deps">deps</a>, <a href="crate_universe.html#crate.annotation-extra_aliased_targets">extra_aliased_targets</a>, <a href="crate_universe.html#crate.annotation-gen_binaries">gen_binaries</a>, <a href="crate_universe.html#crate.annotation-disable_pipelining">disable_pipelining</a>,
<a href="crate_universe.html#crate.annotation-gen_build_script">gen_build_script</a>, <a href="crate_universe.html#crate.annotation-patch_args">patch_args</a>, <a href="crate_universe.html#crate.annotation-patch_tool">patch_tool</a>, <a href="crate_universe.html#crate.annotation-patches">patches</a>, <a href="crate_universe.html#crate.annotation-proc_macro_deps">proc_macro_deps</a>, <a href="crate_universe.html#crate.annotation-rustc_env">rustc_env</a>,
<a href="crate_universe.html#crate.annotation-rustc_env_files">rustc_env_files</a>, <a href="crate_universe.html#crate.annotation-rustc_flags">rustc_flags</a>, <a href="crate_universe.html#crate.annotation-shallow_since">shallow_since</a>, <a href="crate_universe.html#crate.annotation-override_targets">override_targets</a>)
</pre>
<p>A collection of extra attributes and settings for a particular crate</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crate.annotation-version"></a>version</td><td style="text-align: left">The version or semver-conditions to match with a crate. The wildcard <code>*</code> matches any version, including prerelease versions.</td><td style="text-align: left"><code>"*"</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-additive_build_file"></a>additive_build_file</td><td style="text-align: left">A file containing extra contents to write to the bottom of generated BUILD files.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-additive_build_file_content"></a>additive_build_file_content</td><td style="text-align: left">Extra contents to write to the bottom of generated BUILD files.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-alias_rule"></a>alias_rule</td><td style="text-align: left">Alias rule to use instead of <code>native.alias()</code>. Overrides <a href="crate_universe.html#render_config">render_config</a>'s 'default_alias_rule'.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_compile_data"></a>build_script_compile_data</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::compile_data</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_data"></a>build_script_data</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::data</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_tools"></a>build_script_tools</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::tools</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_data_glob"></a>build_script_data_glob</td><td style="text-align: left">A list of glob patterns to add to a crate's <code>cargo_build_script::data</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_deps"></a>build_script_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::deps</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_env"></a>build_script_env</td><td style="text-align: left">Additional environment variables to set on a crate's <code>cargo_build_script::env</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_proc_macro_deps"></a>build_script_proc_macro_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>cargo_build_script::proc_macro_deps</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_rundir"></a>build_script_rundir</td><td style="text-align: left">An override for the build script's rundir attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_rustc_env"></a>build_script_rustc_env</td><td style="text-align: left">Additional environment variables to set on a crate's <code>cargo_build_script::env</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-build_script_toolchains"></a>build_script_toolchains</td><td style="text-align: left">A list of labels to set on a crates's <code>cargo_build_script::toolchains</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-compile_data"></a>compile_data</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::compile_data</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-compile_data_glob"></a>compile_data_glob</td><td style="text-align: left">A list of glob patterns to add to a crate's <code>rust_library::compile_data</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-crate_features"></a>crate_features</td><td style="text-align: left">A list of strings to add to a crate's <code>rust_library::crate_features</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-data"></a>data</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::data</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-data_glob"></a>data_glob</td><td style="text-align: left">A list of glob patterns to add to a crate's <code>rust_library::data</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-deps"></a>deps</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::deps</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-extra_aliased_targets"></a>extra_aliased_targets</td><td style="text-align: left">A list of targets to add to the generated aliases in the root crate_universe repository.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-gen_binaries"></a>gen_binaries</td><td style="text-align: left">As a list, the subset of the crate's bins that should get <code>rust_binary</code> targets produced. Or <code>True</code> to generate all, <code>False</code> to generate none.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-disable_pipelining"></a>disable_pipelining</td><td style="text-align: left">If True, disables pipelining for library targets for this crate.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-gen_build_script"></a>gen_build_script</td><td style="text-align: left">An authorative flag to determine whether or not to produce <code>cargo_build_script</code> targets for the current crate.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-patch_args"></a>patch_args</td><td style="text-align: left">The <code>patch_args</code> attribute of a Bazel repository rule. See <a href="https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_args">http_archive.patch_args</a></td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-patch_tool"></a>patch_tool</td><td style="text-align: left">The <code>patch_tool</code> attribute of a Bazel repository rule. See <a href="https://docs.bazel.build/versions/main/repo/http.html#http_archive-patch_tool">http_archive.patch_tool</a></td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-patches"></a>patches</td><td style="text-align: left">The <code>patches</code> attribute of a Bazel repository rule. See <a href="https://docs.bazel.build/versions/main/repo/http.html#http_archive-patches">http_archive.patches</a></td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-proc_macro_deps"></a>proc_macro_deps</td><td style="text-align: left">A list of labels to add to a crate's <code>rust_library::proc_macro_deps</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-rustc_env"></a>rustc_env</td><td style="text-align: left">Additional variables to set on a crate's <code>rust_library::rustc_env</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-rustc_env_files"></a>rustc_env_files</td><td style="text-align: left">A list of labels to set on a crate's <code>rust_library::rustc_env_files</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-rustc_flags"></a>rustc_flags</td><td style="text-align: left">A list of strings to set on a crate's <code>rust_library::rustc_flags</code> attribute.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-shallow_since"></a>shallow_since</td><td style="text-align: left">An optional timestamp used for crates originating from a git repository instead of a crate registry. This flag optimizes fetching the source code.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.annotation-override_targets"></a>override_targets</td><td style="text-align: left">A dictionary of alternate targets to use when something depends on this crate to allow the parent repo to provide its own version of this dependency. Keys can be <code>proc-marco</code>, <code>custom-build</code>, <code>lib</code>, <code>bin</code>.</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>string: A json encoded string containing the specified version and separately all other inputs.</p>
<p><a id="crate.select"></a></p>
<h2 id="crateselect"><a class="header" href="#crateselect">crate.select</a></h2>
<pre>
crate.select(<a href="crate_universe.html#crate.select-common">common</a>, <a href="crate_universe.html#crate.select-selects">selects</a>)
</pre>
<p>A Starlark Select for <code>crate.annotation()</code>.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crate.select-common"></a>common</td><td style="text-align: left">A value that applies to all configurations.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="crate.select-selects"></a>selects</td><td style="text-align: left">A dict of <code>target_triple</code> to values.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>struct: A struct representing the Starlark Select.</p>
<p><a id="crate.spec"></a></p>
<h2 id="cratespec"><a class="header" href="#cratespec">crate.spec</a></h2>
<pre>
crate.spec(<a href="crate_universe.html#crate.spec-package">package</a>, <a href="crate_universe.html#crate.spec-version">version</a>, <a href="crate_universe.html#crate.spec-artifact">artifact</a>, <a href="crate_universe.html#crate.spec-lib">lib</a>, <a href="crate_universe.html#crate.spec-default_features">default_features</a>, <a href="crate_universe.html#crate.spec-features">features</a>, <a href="crate_universe.html#crate.spec-git">git</a>, <a href="crate_universe.html#crate.spec-branch">branch</a>, <a href="crate_universe.html#crate.spec-tag">tag</a>, <a href="crate_universe.html#crate.spec-rev">rev</a>)
</pre>
<p>A constructor for a crate dependency.</p>
<p>See <a href="https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html">specifying dependencies</a> in the Cargo book for more details.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crate.spec-package"></a>package</td><td style="text-align: left">The explicit name of the package (used when attempting to alias a crate).</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-version"></a>version</td><td style="text-align: left">The exact version of the crate. Cannot be used with <code>git</code>.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-artifact"></a>artifact</td><td style="text-align: left">Set to "bin" to pull in a binary crate as an artifact dependency. Requires a nightly Cargo.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-lib"></a>lib</td><td style="text-align: left">If using <code>artifact = "bin"</code>, additionally setting <code>lib = True</code> declares a dependency on both the package's library and binary, as opposed to just the binary.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-default_features"></a>default_features</td><td style="text-align: left">Maps to the <code>default-features</code> flag.</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-features"></a>features</td><td style="text-align: left">A list of features to use for the crate</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-git"></a>git</td><td style="text-align: left">The Git url to use for the crate. Cannot be used with <code>version</code>.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-branch"></a>branch</td><td style="text-align: left">The git branch of the remote crate. Tied with the <code>git</code> param. Only one of branch, tag or rev may be specified. Specifying <code>rev</code> is recommended for fully-reproducible builds.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-tag"></a>tag</td><td style="text-align: left">The git tag of the remote crate. Tied with the <code>git</code> param. Only one of branch, tag or rev may be specified. Specifying <code>rev</code> is recommended for fully-reproducible builds.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crate.spec-rev"></a>rev</td><td style="text-align: left">The git revision of the remote crate. Tied with the <code>git</code> param. Only one of branch, tag or rev may be specified.</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>string: A json encoded string of all inputs</p>
<p><a id="crate.workspace_member"></a></p>
<h2 id="crateworkspace_member"><a class="header" href="#crateworkspace_member">crate.workspace_member</a></h2>
<pre>
crate.workspace_member(<a href="crate_universe.html#crate.workspace_member-version">version</a>, <a href="crate_universe.html#crate.workspace_member-sha256">sha256</a>)
</pre>
<p>Define information for extra workspace members</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crate.workspace_member-version"></a>version</td><td style="text-align: left">The semver of the crate to download. Must be an exact version.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="crate.workspace_member-sha256"></a>sha256</td><td style="text-align: left">The sha256 checksum of the <code>.crate</code> file.</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>string: A json encoded string of all inputs</p>
<p><a id="crate_deps"></a></p>
<h2 id="crate_deps"><a class="header" href="#crate_deps">crate_deps</a></h2>
<pre>
crate_deps(<a href="crate_universe.html#crate_deps-deps">deps</a>, <a href="crate_universe.html#crate_deps-package_name">package_name</a>)
</pre>
<p>Finds the fully qualified label of the requested crates for the package where this macro is called.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crate_deps-deps"></a>deps</td><td style="text-align: left">The desired list of crate targets.</td><td style="text-align: left">none</td></tr>
<tr><td style="text-align: left"><a id="crate_deps-package_name"></a>package_name</td><td style="text-align: left">The package name of the set of dependencies to look up. Defaults to <code>native.package_name()</code>.</td><td style="text-align: left"><code>None</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>list: A list of labels to generated rust targets (str)</p>
<p><a id="crate_repositories"></a></p>
<h2 id="crate_repositories"><a class="header" href="#crate_repositories">crate_repositories</a></h2>
<pre>
crate_repositories()
</pre>
<p>A macro for defining repositories for all generated crates.</p>
<p><strong>RETURNS</strong></p>
<p>A list of repos visible to the module through the module extension.</p>
<p><a id="crate_universe_dependencies"></a></p>
<h2 id="crate_universe_dependencies"><a class="header" href="#crate_universe_dependencies">crate_universe_dependencies</a></h2>
<pre>
crate_universe_dependencies(<a href="crate_universe.html#crate_universe_dependencies-rust_version">rust_version</a>, <a href="crate_universe.html#crate_universe_dependencies-bootstrap">bootstrap</a>, <a href="crate_universe.html#crate_universe_dependencies-kwargs">kwargs</a>)
</pre>
<p>Define dependencies of the <code>cargo-bazel</code> Rust target</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crate_universe_dependencies-rust_version"></a>rust_version</td><td style="text-align: left">The version of rust to use when generating dependencies.</td><td style="text-align: left"><code>"1.82.0"</code></td></tr>
<tr><td style="text-align: left"><a id="crate_universe_dependencies-bootstrap"></a>bootstrap</td><td style="text-align: left">If true, a <code>cargo_bootstrap_repository</code> target will be generated.</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="crate_universe_dependencies-kwargs"></a>kwargs</td><td style="text-align: left">Arguments to pass through to cargo_bazel_bootstrap.</td><td style="text-align: left">none</td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>list[struct(repo=str, is_dev_dep=bool)]: A list of the repositories
defined by this macro.</p>
<p><a id="render_config"></a></p>
<h2 id="render_config"><a class="header" href="#render_config">render_config</a></h2>
<pre>
render_config(<a href="crate_universe.html#render_config-build_file_template">build_file_template</a>, <a href="crate_universe.html#render_config-crate_label_template">crate_label_template</a>, <a href="crate_universe.html#render_config-crate_repository_template">crate_repository_template</a>,
<a href="crate_universe.html#render_config-crates_module_template">crates_module_template</a>, <a href="crate_universe.html#render_config-default_alias_rule">default_alias_rule</a>, <a href="crate_universe.html#render_config-default_package_name">default_package_name</a>,
<a href="crate_universe.html#render_config-generate_target_compatible_with">generate_target_compatible_with</a>, <a href="crate_universe.html#render_config-platforms_template">platforms_template</a>, <a href="crate_universe.html#render_config-regen_command">regen_command</a>, <a href="crate_universe.html#render_config-vendor_mode">vendor_mode</a>,
<a href="crate_universe.html#render_config-generate_rules_license_metadata">generate_rules_license_metadata</a>)
</pre>
<p>Various settings used to configure rendered outputs</p>
<p>The template parameters each support a select number of format keys. A description of each key
can be found below where the supported keys for each template can be found in the parameter docs</p>
<div class="table-wrapper"><table><thead><tr><th>key</th><th>definition</th></tr></thead><tbody>
<tr><td><code>name</code></td><td>The name of the crate. Eg <code>tokio</code></td></tr>
<tr><td><code>repository</code></td><td>The rendered repository name for the crate. Directly relates to <code>crate_repository_template</code>.</td></tr>
<tr><td><code>triple</code></td><td>A platform triple. Eg <code>x86_64-unknown-linux-gnu</code></td></tr>
<tr><td><code>version</code></td><td>The crate version. Eg <code>1.2.3</code></td></tr>
<tr><td><code>target</code></td><td>The library or binary target of the crate</td></tr>
<tr><td><code>file</code></td><td>The basename of a file</td></tr>
</tbody></table>
</div>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="render_config-build_file_template"></a>build_file_template</td><td style="text-align: left">The base template to use for BUILD file names. The available format keys are [<code>{name}</code>, {version}`].</td><td style="text-align: left"><code>"//:BUILD.{name}-{version}.bazel"</code></td></tr>
<tr><td style="text-align: left"><a id="render_config-crate_label_template"></a>crate_label_template</td><td style="text-align: left">The base template to use for crate labels. The available format keys are [<code>{repository}</code>, <code>{name}</code>, <code>{version}</code>, <code>{target}</code>].</td><td style="text-align: left"><code>"@{repository}__{name}-{version}//:{target}"</code></td></tr>
<tr><td style="text-align: left"><a id="render_config-crate_repository_template"></a>crate_repository_template</td><td style="text-align: left">The base template to use for Crate label repository names. The available format keys are [<code>{repository}</code>, <code>{name}</code>, <code>{version}</code>].</td><td style="text-align: left"><code>"{repository}__{name}-{version}"</code></td></tr>
<tr><td style="text-align: left"><a id="render_config-crates_module_template"></a>crates_module_template</td><td style="text-align: left">The pattern to use for the <code>defs.bzl</code> and <code>BUILD.bazel</code> file names used for the crates module. The available format keys are [<code>{file}</code>].</td><td style="text-align: left"><code>"//:{file}"</code></td></tr>
<tr><td style="text-align: left"><a id="render_config-default_alias_rule"></a>default_alias_rule</td><td style="text-align: left">Alias rule to use when generating aliases for all crates. Acceptable values are 'alias', 'dbg'/'fastbuild'/'opt' (transitions each crate's <code>compilation_mode</code>) or a string representing a rule in the form '&lt;label to .bzl&gt;:<rule>' that takes a single label parameter 'actual'. See '@crate_index//:alias_rules.bzl' for an example.</td><td style="text-align: left"><code>"alias"</code></td></tr>
<tr><td style="text-align: left"><a id="render_config-default_package_name"></a>default_package_name</td><td style="text-align: left">The default package name to use in the rendered macros. This affects the auto package detection of things like <code>all_crate_deps</code>.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="render_config-generate_target_compatible_with"></a>generate_target_compatible_with</td><td style="text-align: left">Whether to generate <code>target_compatible_with</code> annotations on the generated BUILD files. This catches a <code>target_triple</code>being targeted that isn't declared in <code>supported_platform_triples</code>.</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="render_config-platforms_template"></a>platforms_template</td><td style="text-align: left">The base template to use for platform names. See <a href="https://docs.bazel.build/versions/main/platforms.html">platforms documentation</a>. The available format keys are [<code>{triple}</code>].</td><td style="text-align: left"><code>"@rules_rust//rust/platform:{triple}"</code></td></tr>
<tr><td style="text-align: left"><a id="render_config-regen_command"></a>regen_command</td><td style="text-align: left">An optional command to demonstrate how generated files should be regenerated.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="render_config-vendor_mode"></a>vendor_mode</td><td style="text-align: left">An optional configuration for rendirng content to be rendered into repositories.</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="render_config-generate_rules_license_metadata"></a>generate_rules_license_metadata</td><td style="text-align: left">Whether to generate rules license metedata</td><td style="text-align: left"><code>False</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>string: A json encoded struct to match the Rust <code>config::RenderConfig</code> struct</p>
<p><a id="splicing_config"></a></p>
<h2 id="splicing_config"><a class="header" href="#splicing_config">splicing_config</a></h2>
<pre>
splicing_config(<a href="crate_universe.html#splicing_config-resolver_version">resolver_version</a>)
</pre>
<p>Various settings used to configure Cargo manifest splicing behavior.</p>
<p><strong>PARAMETERS</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Default Value</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="splicing_config-resolver_version"></a>resolver_version</td><td style="text-align: left">The <a href="https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions">resolver version</a> to use in generated Cargo manifests. This flag is <strong>only</strong> used when splicing a manifest from direct package definitions. See <code>crates_repository::packages</code>.</td><td style="text-align: left"><code>"2"</code></td></tr>
</tbody></table>
</div>
<p><strong>RETURNS</strong></p>
<p>str: A json encoded string of the parameters provided</p>
<p><a id="crates_repository"></a></p>
<h2 id="crates_repository"><a class="header" href="#crates_repository">crates_repository</a></h2>
<pre>
crates_repository(<a href="crate_universe.html#crates_repository-name">name</a>, <a href="crate_universe.html#crates_repository-annotations">annotations</a>, <a href="crate_universe.html#crates_repository-cargo_config">cargo_config</a>, <a href="crate_universe.html#crates_repository-cargo_lockfile">cargo_lockfile</a>, <a href="crate_universe.html#crates_repository-generate_binaries">generate_binaries</a>,
<a href="crate_universe.html#crates_repository-generate_build_scripts">generate_build_scripts</a>, <a href="crate_universe.html#crates_repository-generate_target_compatible_with">generate_target_compatible_with</a>, <a href="crate_universe.html#crates_repository-generator">generator</a>,
<a href="crate_universe.html#crates_repository-generator_sha256s">generator_sha256s</a>, <a href="crate_universe.html#crates_repository-generator_urls">generator_urls</a>, <a href="crate_universe.html#crates_repository-isolated">isolated</a>, <a href="crate_universe.html#crates_repository-lockfile">lockfile</a>, <a href="crate_universe.html#crates_repository-manifests">manifests</a>, <a href="crate_universe.html#crates_repository-packages">packages</a>, <a href="crate_universe.html#crates_repository-quiet">quiet</a>,
<a href="crate_universe.html#crates_repository-render_config">render_config</a>, <a href="crate_universe.html#crates_repository-repin_instructions">repin_instructions</a>, <a href="crate_universe.html#crates_repository-repo_mapping">repo_mapping</a>, <a href="crate_universe.html#crates_repository-rust_toolchain_cargo_template">rust_toolchain_cargo_template</a>,
<a href="crate_universe.html#crates_repository-rust_toolchain_rustc_template">rust_toolchain_rustc_template</a>, <a href="crate_universe.html#crates_repository-rust_version">rust_version</a>, <a href="crate_universe.html#crates_repository-splicing_config">splicing_config</a>,
<a href="crate_universe.html#crates_repository-supported_platform_triples">supported_platform_triples</a>)
</pre>
<p>A rule for defining and downloading Rust dependencies (crates). This rule
handles all the same <a href="crate_universe.html#workflows">workflows</a> <code>crate_universe</code> rules do.</p>
<p>Environment Variables:</p>
<div class="table-wrapper"><table><thead><tr><th>variable</th><th>usage</th></tr></thead><tbody>
<tr><td><code>CARGO_BAZEL_GENERATOR_SHA256</code></td><td>The sha256 checksum of the file located at <code>CARGO_BAZEL_GENERATOR_URL</code></td></tr>
<tr><td><code>CARGO_BAZEL_GENERATOR_URL</code></td><td>The URL of a cargo-bazel binary. This variable takes precedence over attributes and can use <code>file://</code> for local paths</td></tr>
<tr><td><code>CARGO_BAZEL_ISOLATED</code></td><td>An authorative flag as to whether or not the <code>CARGO_HOME</code> environment variable should be isolated from the host configuration</td></tr>
<tr><td><code>CARGO_BAZEL_REPIN</code></td><td>An indicator that the dependencies represented by the rule should be regenerated. <code>REPIN</code> may also be used. See <a href="crate_universe.html#repinning--updating-dependencies">Repinning / Updating Dependencies</a> for more details.</td></tr>
<tr><td><code>CARGO_BAZEL_REPIN_ONLY</code></td><td>A comma-delimited allowlist for rules to execute repinning. Can be useful if multiple instances of the repository rule are used in a Bazel workspace, but repinning should be limited to one of them.</td></tr>
</tbody></table>
</div>
<p>Example:</p>
<p>Given the following workspace structure:</p>
<pre><code class="language-text">[workspace]/
WORKSPACE.bazel
BUILD.bazel
Cargo.toml
Cargo.Bazel.lock
src/
main.rs
</code></pre>
<p>The following is something that'd be found in the <code>WORKSPACE</code> file:</p>
<pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crates_repository", "crate")
crates_repository(
name = "crate_index",
annotations = {
"rand": [crate.annotation(
default_features = False,
features = ["small_rng"],
)],
},
cargo_lockfile = "//:Cargo.Bazel.lock",
lockfile = "//:cargo-bazel-lock.json",
manifests = ["//:Cargo.toml"],
# Should match the version represented by the currently registered `rust_toolchain`.
rust_version = "1.60.0",
)
</code></pre>
<p>The above will create an external repository which contains aliases and macros for accessing
Rust targets found in the dependency graph defined by the given manifests.</p>
<p><strong>NOTE</strong>: The <code>cargo_lockfile</code> and <code>lockfile</code> must be manually created. The rule unfortunately does not yet create
it on its own. When initially setting up this rule, an empty file should be created and then
populated by repinning dependencies.</p>
<h3 id="repinning--updating-dependencies-1"><a class="header" href="#repinning--updating-dependencies-1">Repinning / Updating Dependencies</a></h3>
<p>Dependency syncing and updating is done in the repository rule which means it's done during the
analysis phase of builds. As mentioned in the environments variable table above, the <code>CARGO_BAZEL_REPIN</code>
(or <code>REPIN</code>) environment variables can be used to force the rule to update dependencies and potentially
render a new lockfile. Given an instance of this repository rule named <code>crate_index</code>, the easiest way to
repin dependencies is to run:</p>
<pre><code class="language-shell">CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index
</code></pre>
<p>This will result in all dependencies being updated for a project. The <code>CARGO_BAZEL_REPIN</code> environment variable
can also be used to customize how dependencies are updated. The following table shows translations from environment
variable values to the equivilant <a href="https://doc.rust-lang.org/cargo/commands/cargo-update.html">cargo update</a> command
that is called behind the scenes to update dependencies.</p>
<div class="table-wrapper"><table><thead><tr><th>Value</th><th>Cargo command</th></tr></thead><tbody>
<tr><td>Any of [<code>true</code>, <code>1</code>, <code>yes</code>, <code>on</code>, <code>workspace</code>]</td><td><code>cargo update --workspace</code></td></tr>
<tr><td>Any of [<code>full</code>, <code>eager</code>, <code>all</code>]</td><td><code>cargo update</code></td></tr>
<tr><td><code>package_name</code></td><td><code>cargo upgrade --package package_name</code></td></tr>
<tr><td><code>package_name@1.2.3</code></td><td><code>cargo upgrade --package package_name@1.2.3</code></td></tr>
<tr><td><code>package_name@1.2.3=4.5.6</code></td><td><code>cargo upgrade --package package_name@1.2.3 --precise=4.5.6</code></td></tr>
</tbody></table>
</div>
<p>If the <code>crates_repository</code> is used multiple times in the same Bazel workspace (e.g. for multiple independent
Rust workspaces), it may additionally be useful to use the <code>CARGO_BAZEL_REPIN_ONLY</code> environment variable, which
limits execution of the repinning to one or multiple instances of the <code>crates_repository</code> rule via a comma-delimited
allowlist:</p>
<pre><code class="language-shell">CARGO_BAZEL_REPIN=1 CARGO_BAZEL_REPIN_ONLY=crate_index bazel sync --only=crate_index
</code></pre>
<p><strong>ATTRIBUTES</strong></p>
<div class="table-wrapper"><table><thead><tr><th style="text-align: left">Name</th><th style="text-align: left">Description</th><th style="text-align: left">Type</th><th style="text-align: left">Mandatory</th><th style="text-align: left">Default</th></tr></thead><tbody>
<tr><td style="text-align: left"><a id="crates_repository-name"></a>name</td><td style="text-align: left">A unique name for this repository.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels#target-names">Name</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-annotations"></a>annotations</td><td style="text-align: left">Extra settings to apply to crates. See <a href="crate_universe.html#crateannotation">crate.annotation</a>.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; List of strings</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-cargo_config"></a>cargo_config</td><td style="text-align: left">A <a href="https://doc.rust-lang.org/cargo/reference/config.html">Cargo configuration</a> file</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-cargo_lockfile"></a>cargo_lockfile</td><td style="text-align: left">The path used to store the <code>crates_repository</code> specific <a href="https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html">Cargo.lock</a> file. In the case that your <code>crates_repository</code> corresponds directly with an existing <code>Cargo.toml</code> file which has a paired <code>Cargo.lock</code> file, that <code>Cargo.lock</code> file should be used here, which will keep the versions used by cargo and bazel in sync.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">required</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-generate_binaries"></a>generate_binaries</td><td style="text-align: left">Whether to generate <code>rust_binary</code> targets for all the binary crates in every package. By default only the <code>rust_library</code> targets are generated.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>False</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-generate_build_scripts"></a>generate_build_scripts</td><td style="text-align: left">Whether or not to generate <a href="https://doc.rust-lang.org/cargo/reference/build-scripts.html">cargo build scripts</a> by default.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-generate_target_compatible_with"></a>generate_target_compatible_with</td><td style="text-align: left">DEPRECATED: Moved to <code>render_config</code>.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-generator"></a>generator</td><td style="text-align: left">The absolute label of a generator. Eg. <code>@cargo_bazel_bootstrap//:cargo-bazel</code>. This is typically used when bootstrapping</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-generator_sha256s"></a>generator_sha256s</td><td style="text-align: left">Dictionary of <code>host_triple</code> -&gt; <code>sha256</code> for a <code>cargo-bazel</code> binary.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-generator_urls"></a>generator_urls</td><td style="text-align: left">URL template from which to download the <code>cargo-bazel</code> binary. <code>{host_triple}</code> and will be filled in according to the host platform.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-isolated"></a>isolated</td><td style="text-align: left">If true, <code>CARGO_HOME</code> will be overwritten to a directory within the generated repository in order to prevent other uses of Cargo from impacting having any effect on the generated targets produced by this rule. For users who either have multiple <code>crate_repository</code> definitions in a WORKSPACE or rapidly re-pin dependencies, setting this to false may improve build times. This variable is also controled by <code>CARGO_BAZEL_ISOLATED</code> environment variable.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-lockfile"></a>lockfile</td><td style="text-align: left">The path to a file to use for reproducible renderings. If set, this file must exist within the workspace (but can be empty) before this rule will work.</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">Label</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>None</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-manifests"></a>manifests</td><td style="text-align: left">A list of Cargo manifests (<code>Cargo.toml</code> files).</td><td style="text-align: left"><a href="https://bazel.build/concepts/labels">List of labels</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>[]</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-packages"></a>packages</td><td style="text-align: left">A set of crates (packages) specifications to depend on. See <a href="crate_universe.html#crate.spec">crate.spec</a>.</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"><code>{}</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-quiet"></a>quiet</td><td style="text-align: left">If stdout and stderr should not be printed to the terminal.</td><td style="text-align: left">Boolean</td><td style="text-align: left">optional</td><td style="text-align: left"><code>True</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-render_config"></a>render_config</td><td style="text-align: left">The configuration flags to use for rendering. Use <code>//crate_universe:defs.bzl\%render_config</code> to generate the value for this field. If unset, the defaults defined there will be used.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-repin_instructions"></a>repin_instructions</td><td style="text-align: left">Instructions to re-pin the repository if required. Many people have wrapper scripts for keeping dependencies up to date, and would like to point users to that instead of the default.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-repo_mapping"></a>repo_mapping</td><td style="text-align: left">In <code>WORKSPACE</code> context only: a dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.<br><br>For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>).<br><br>This attribute is <em>not</em> supported in <code>MODULE.bazel</code> context (when invoking a repository rule inside a module extension's implementation function).</td><td style="text-align: left"><a href="https://bazel.build/rules/lib/dict">Dictionary: String -&gt; String</a></td><td style="text-align: left">optional</td><td style="text-align: left"></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-rust_toolchain_cargo_template"></a>rust_toolchain_cargo_template</td><td style="text-align: left">The template to use for finding the host <code>cargo</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{cfg}</code> (eg. 'exec'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-rust_toolchain_rustc_template"></a>rust_toolchain_rustc_template</td><td style="text-align: left">The template to use for finding the host <code>rustc</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{cfg}</code> (eg. 'exec'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'cargo.exe') will be replaced in the string if present.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-rust_version"></a>rust_version</td><td style="text-align: left">The version of Rust the currently registered toolchain is using. Eg. <code>1.56.0</code>, or <code>nightly/2021-09-08</code></td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>"1.82.0"</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-splicing_config"></a>splicing_config</td><td style="text-align: left">The configuration flags to use for splicing Cargo maniests. Use <code>//crate_universe:defs.bzl\%rsplicing_config</code> to generate the value for this field. If unset, the defaults defined there will be used.</td><td style="text-align: left">String</td><td style="text-align: left">optional</td><td style="text-align: left"><code>""</code></td></tr>
<tr><td style="text-align: left"><a id="crates_repository-supported_platform_triples"></a>supported_platform_triples</td><td style="text-align: left">A set of all platform triples to consider when generating dependencies.</td><td style="text-align: left">List of strings</td><td style="text-align: left">optional</td><td style="text-align: left"><code>["aarch64-apple-darwin", "aarch64-apple-ios", "aarch64-apple-ios-sim", "aarch64-linux-android", "aarch64-pc-windows-msvc", "aarch64-unknown-fuchsia", "aarch64-unknown-linux-gnu", "aarch64-unknown-nixos-gnu", "aarch64-unknown-nto-qnx710", "arm-unknown-linux-gnueabi", "armv7-linux-androideabi", "armv7-unknown-linux-gnueabi", "i686-apple-darwin", "i686-linux-android", "i686-pc-windows-msvc", "i686-unknown-freebsd", "i686-unknown-linux-gnu", "powerpc-unknown-linux-gnu", "riscv32imc-unknown-none-elf", "riscv64gc-unknown-none-elf", "s390x-unknown-linux-gnu", "thumbv7em-none-eabi", "thumbv8m.main-none-eabi", "wasm32-unknown-unknown", "wasm32-wasi", "wasm32-wasip1", "x86_64-apple-darwin", "x86_64-apple-ios", "x86_64-linux-android", "x86_64-pc-windows-msvc", "x86_64-unknown-freebsd", "x86_64-unknown-fuchsia", "x86_64-unknown-linux-gnu", "x86_64-unknown-nixos-gnu", "x86_64-unknown-none"]</code></td></tr>
</tbody></table>
</div>
<p><strong>ENVIRONMENT VARIABLES</strong></p>
<p>This repository rule depends on the following environment variables:</p>
<ul>
<li><code>CARGO_BAZEL_GENERATOR_URL</code></li>
<li><code>CARGO_BAZEL_GENERATOR_SHA256</code></li>
<li><code>CARGO_BAZEL_REPIN</code></li>
<li><code>REPIN</code></li>
<li><code>CARGO_BAZEL_REPIN_ONLY</code></li>
<li><code>CARGO_BAZEL_ISOLATED</code></li>
<li><code>CARGO_BAZEL_DEBUG</code></li>
</ul>
<div style="break-before: page; page-break-before: always;"></div><h1 id="upstream-tooling"><a class="header" href="#upstream-tooling">Upstream Tooling</a></h1>
<p>rules_rust manages versions of things like rustc. If you want to manually run upstream tooling configured at the versions, plugins and such that rules_rust has configured, rules_rust exposes these as targets in <code>@rules_rust//tools/upstream_wrapper</code>:</p>
<pre><code class="language-console">% bazel query @rules_rust//tools/upstream_wrapper
@rules_rust//tools/upstream_wrapper:cargo
@rules_rust//tools/upstream_wrapper:cargo_clippy
@rules_rust//tools/upstream_wrapper:rustc
@rules_rust//tools/upstream_wrapper:rustfmt
</code></pre>
<p>You can run them via <code>bazel run</code>, e.g. <code>bazel run @rules_rust//tools/upstream_wrapper:cargo -- check</code>.</p>
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
</nav>
</div>
<script>
window.playground_copyable = true;
</script>
<script src="elasticlunr.min.js"></script>
<script src="mark.min.js"></script>
<script src="searcher.js"></script>
<script src="clipboard.min.js"></script>
<script src="highlight.js"></script>
<script src="book.js"></script>
<!-- Custom JS scripts -->
<script>
window.addEventListener('load', function() {
window.setTimeout(window.print, 100);
});
</script>
</div>
</body>
</html>